mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "tip-bot2 for Tiezhu Yang" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>,
	Huacai Chen <chenhuacai@loongson.cn>,
	Josh Poimboeuf <jpoimboe@kernel.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: objtool/core] objtool: Handle various symbol types of rodata
Date: Fri, 14 Mar 2025 20:04:03 -0000	[thread overview]
Message-ID: <174198264378.14745.7475966821311554479.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20250211115016.26913-2-yangtiezhu@loongson.cn>

The following commit has been merged into the objtool/core branch of tip:

Commit-ID:     ab6ce22b789622ca732e91cbb3a5cb5ba370cbd0
Gitweb:        https://git.kernel.org/tip/ab6ce22b789622ca732e91cbb3a5cb5ba370cbd0
Author:        Tiezhu Yang <yangtiezhu@loongson.cn>
AuthorDate:    Tue, 11 Feb 2025 19:50:10 +08:00
Committer:     Josh Poimboeuf <jpoimboe@kernel.org>
CommitterDate: Wed, 12 Mar 2025 15:43:38 -07:00

objtool: Handle various symbol types of rodata

In the relocation section ".rela.rodata" of each .o file compiled with
LoongArch toolchain, there are various symbol types such as STT_NOTYPE,
STT_OBJECT, STT_FUNC in addition to the usual STT_SECTION, it needs to
use reloc symbol offset instead of reloc addend to find the destination
instruction in find_jump_table() and add_jump_table().

For the most part, an absolute relocation type is used for rodata. In the
case of STT_SECTION, reloc->sym->offset is always zero, and for the other
symbol types, reloc_addend(reloc) is always zero, thus it can use a simple
statement "reloc->sym->offset + reloc_addend(reloc)" to obtain the symbol
offset for various symbol types.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Link: https://lore.kernel.org/r/20250211115016.26913-2-yangtiezhu@loongson.cn
Acked-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
 tools/objtool/check.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index ce973d9..cfab4a1 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -1954,6 +1954,7 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn,
 	unsigned int prev_offset = 0;
 	struct reloc *reloc = table;
 	struct alternative *alt;
+	unsigned long sym_offset;
 
 	/*
 	 * Each @reloc is a switch table relocation which points to the target
@@ -1971,9 +1972,10 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn,
 		if (prev_offset && reloc_offset(reloc) != prev_offset + 8)
 			break;
 
+		sym_offset = reloc->sym->offset + reloc_addend(reloc);
+
 		/* Detect function pointers from contiguous objects: */
-		if (reloc->sym->sec == pfunc->sec &&
-		    reloc_addend(reloc) == pfunc->offset)
+		if (reloc->sym->sec == pfunc->sec && sym_offset == pfunc->offset)
 			break;
 
 		/*
@@ -1981,10 +1983,10 @@ static int add_jump_table(struct objtool_file *file, struct instruction *insn,
 		 * which point to the end of the function.  Ignore them.
 		 */
 		if (reloc->sym->sec == pfunc->sec &&
-		    reloc_addend(reloc) == pfunc->offset + pfunc->len)
+		    sym_offset == pfunc->offset + pfunc->len)
 			goto next;
 
-		dest_insn = find_insn(file, reloc->sym->sec, reloc_addend(reloc));
+		dest_insn = find_insn(file, reloc->sym->sec, sym_offset);
 		if (!dest_insn)
 			break;
 
@@ -2023,6 +2025,7 @@ static void find_jump_table(struct objtool_file *file, struct symbol *func,
 	struct reloc *table_reloc;
 	struct instruction *dest_insn, *orig_insn = insn;
 	unsigned long table_size;
+	unsigned long sym_offset;
 
 	/*
 	 * Backward search using the @first_jump_src links, these help avoid
@@ -2046,7 +2049,10 @@ static void find_jump_table(struct objtool_file *file, struct symbol *func,
 		table_reloc = arch_find_switch_table(file, insn, &table_size);
 		if (!table_reloc)
 			continue;
-		dest_insn = find_insn(file, table_reloc->sym->sec, reloc_addend(table_reloc));
+
+		sym_offset = table_reloc->sym->offset + reloc_addend(table_reloc);
+
+		dest_insn = find_insn(file, table_reloc->sym->sec, sym_offset);
 		if (!dest_insn || !insn_func(dest_insn) || insn_func(dest_insn)->pfunc != func)
 			continue;
 

  reply	other threads:[~2025-03-14 20:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-11 11:50 [PATCH v7 0/7] Add jump table support for objtool on LoongArch Tiezhu Yang
2025-02-11 11:50 ` [PATCH v7 1/7] objtool: Handle various symbol types of rodata Tiezhu Yang
2025-03-14 20:04   ` tip-bot2 for Tiezhu Yang [this message]
2025-02-11 11:50 ` [PATCH v7 2/7] objtool: Handle different entry size " Tiezhu Yang
2025-03-14 20:04   ` [tip: objtool/core] " tip-bot2 for Tiezhu Yang
2025-02-11 11:50 ` [PATCH v7 3/7] objtool: Handle PC relative relocation type Tiezhu Yang
2025-03-14 20:04   ` [tip: objtool/core] " tip-bot2 for Tiezhu Yang
2025-02-11 11:50 ` [PATCH v7 4/7] objtool/LoongArch: Add support for switch table Tiezhu Yang
2025-03-14 20:04   ` [tip: objtool/core] " tip-bot2 for Tiezhu Yang
2025-02-11 11:50 ` [PATCH v7 5/7] objtool/LoongArch: Add support for goto table Tiezhu Yang
2025-03-14 20:04   ` [tip: objtool/core] " tip-bot2 for Tiezhu Yang
2025-02-11 11:50 ` [PATCH v7 6/7] LoongArch: Enable jump table for objtool Tiezhu Yang
2025-02-11 11:50 ` [PATCH v7 7/7] LoongArch: Convert unreachable() to BUG() Tiezhu Yang
2025-03-08  5:47 ` [PATCH v7 0/7] Add jump table support for objtool on LoongArch Huacai Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=174198264378.14745.7475966821311554479.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=chenhuacai@loongson.cn \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=x86@kernel.org \
    --cc=yangtiezhu@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®