From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51B6339B964 for ; Tue, 12 May 2026 22:11:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778623878; cv=none; b=YXYnI5Pg/cl4uF/GucPExuaXFxALDvAp/5IjKN0CkgfQGqYuQ9hROm/KxW+tA+qR2BuAqYRrAgJQP/9P1118w3GaTM9/8+/sGMHkHS+INNzBzO9SHGsPtPD5vbhJT/hAWnE+knNvgnLWf2vZgBorhOmAXD01LwQUaiNYR1ajiMg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778623878; c=relaxed/simple; bh=36Tw+gz85KTY3fBDCPnS7KKF24RCjtB1UcjdLUyYiPg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=LMOArPJROdls/igm16RDi+oZMGi0YRhAJK6HEHvfaellFfpaHPwljnbGTNwgKQjWZSywC8Zp2dec2SND3I4767KbCcTSEuKSIHfeNuG/TZ8auKXu66MuQnGjPmF82snneeb51aqZHOu9eH+aaoLex3L8rzzeOPzFNTzGp1GI3XQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=DO13w20q; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DO13w20q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778623876; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jl30t3jXKDaBR32ke15XxtGmE5d14QvFnALDQQLw2mE=; b=DO13w20qSc1L1Ri4a9ES0qhsihqnKOov5j9I44HXxGPUPBbfO5ITLjOvSoMVJeUXAssBtm U361q+RplbB2QOeeCs+fw0Nh4GfXqrcZ7lUmoEEwve75r2JATtuzjUAanucKSCfKKJcG+t gLC++ASV3rhZEeg+huXNVOqdl6KSJ3M= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-214-MPHo4m1ZNQ6ugcJ4F_Cm0w-1; Tue, 12 May 2026 18:11:12 -0400 X-MC-Unique: MPHo4m1ZNQ6ugcJ4F_Cm0w-1 X-Mimecast-MFC-AGG-ID: MPHo4m1ZNQ6ugcJ4F_Cm0w_1778623871 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E19C61955F01; Tue, 12 May 2026 22:11:10 +0000 (UTC) Received: from jolawren-thinkpadp1gen7.ibmlowe.csb (unknown [10.22.89.145]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D67941800347; Tue, 12 May 2026 22:11:09 +0000 (UTC) From: Joe Lawrence To: live-patching@vger.kernel.org Cc: Josh Poimboeuf , Song Liu , Miroslav Benes , Petr Mladek Subject: [RFC 2/4] objtool/klp: allow special section entry size overrides Date: Tue, 12 May 2026 18:11:00 -0400 Message-ID: <20260512221102.2720763-3-joe.lawrence@redhat.com> In-Reply-To: <20260512221102.2720763-1-joe.lawrence@redhat.com> References: <20260512221102.2720763-1-joe.lawrence@redhat.com> Precedence: bulk X-Mailing-List: live-patching@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Special section entry sizes (ALT_ENTRY_SIZE, JUMP_ENTRY_SIZE, EX_ENTRY_SIZE) are built into objtool from arch-specific headers. When processing cached unit test objects that were built from a different kernel version, these compiled-in sizes may not match the objects' actual entry sizes, causing create_fake_symbols() to incorrectly parse special sections. Allow the user to override the compiled-in defaults via environment variables of the same name. When unset, behavior is unchanged. This will enable a klp-diff unit test runner to pass the correct entry sizes from test metadata. Assisted-by: Cursor:claude-4.6-opus Signed-off-by: Joe Lawrence --- tools/objtool/klp-diff.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c index bd8d64f2f3f6..ebe4a2a087ca 100644 --- a/tools/objtool/klp-diff.c +++ b/tools/objtool/klp-diff.c @@ -1749,6 +1749,22 @@ static int clone_sym_relocs(struct elfs *e, struct symbol *patched_sym) } +static unsigned int entry_size_from_env(const char *name, unsigned int def) +{ + const char *str = getenv(name); + char *end; + unsigned long val; + + if (!str) + return def; + + val = strtoul(str, &end, 10); + if (*end || !val) + return def; + + return val; +} + static int create_fake_symbol(struct elf *elf, struct section *sec, unsigned long offset, size_t size) { @@ -1871,6 +1887,21 @@ static int create_fake_symbols(struct elf *elf) } entry_size = sec->sh.sh_entsize; + + /* + * Some special sections have multiple relocs per entry, + * so the reloc-based heuristic below doesn't work. Use + * the arch-defined entry sizes for known special sections. + */ + if (!entry_size) { + if (!strcmp(sec->name, ".altinstructions")) + entry_size = entry_size_from_env("ALT_ENTRY_SIZE", ALT_ENTRY_SIZE); + else if (!strcmp(sec->name, "__jump_table")) + entry_size = entry_size_from_env("JUMP_ENTRY_SIZE", JUMP_ENTRY_SIZE); + else if (!strcmp(sec->name, "__ex_table")) + entry_size = entry_size_from_env("EX_ENTRY_SIZE", EX_ENTRY_SIZE); + } + if (!entry_size) { entry_size = arch_reloc_size(sec->rsec->relocs); if (sec_size(sec) != entry_size * sec_num_entries(sec->rsec)) { -- 2.53.0