mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] tools/objtool: tolerate STT_NOTYPE symbols at end of section
@ 2022-12-20 10:13 Nicholas Piggin
  2022-12-20 14:21 ` Christophe Leroy
  2023-01-09 17:01 ` [tip: core/urgent] objtool: Tolerate " tip-bot2 for Nicholas Piggin
  0 siblings, 2 replies; 3+ messages in thread
From: Nicholas Piggin @ 2022-12-20 10:13 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Nicholas Piggin, Peter Zijlstra, linux-kernel, linuxppc-dev

Hand-written asm often contains non-function symbols in executable
sections. _end symbols for finding the size of instruction blocks
for runtime processing is one such usage.

optprobe_template_end is one example that causes the warning:

  objtool: optprobe_template_end(): can't find starting instruction

This is because the symbol happens to be at the end of the file (and
therefore end of a section in the object file).

So ignore end-of-section STT_NOTYPE symbols instead of bailing out
because an instruction can't be found. While we're here, add a more
descriptive warning for STT_FUNC symbols found at the end of a
section.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 tools/objtool/check.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 4350be739f4f..4b7c8b33069e 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -427,6 +427,15 @@ static int decode_instructions(struct objtool_file *file)
 			if (func->type != STT_NOTYPE && func->type != STT_FUNC)
 				continue;
 
+			if (func->offset == sec->sh.sh_size) {
+				/* Heuristic: likely an "end" symbol */
+				if (func->type == STT_NOTYPE)
+					continue;
+				WARN("%s(): STT_FUNC at end of section",
+				     func->name);
+				return -1;
+			}
+
 			if (func->return_thunk || func->alias != func)
 				continue;
 
-- 
2.37.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tools/objtool: tolerate STT_NOTYPE symbols at end of section
  2022-12-20 10:13 [PATCH] tools/objtool: tolerate STT_NOTYPE symbols at end of section Nicholas Piggin
@ 2022-12-20 14:21 ` Christophe Leroy
  2023-01-09 17:01 ` [tip: core/urgent] objtool: Tolerate " tip-bot2 for Nicholas Piggin
  1 sibling, 0 replies; 3+ messages in thread
From: Christophe Leroy @ 2022-12-20 14:21 UTC (permalink / raw)
  To: Nicholas Piggin, Josh Poimboeuf
  Cc: Peter Zijlstra, linuxppc-dev, linux-kernel



Le 20/12/2022 à 11:13, Nicholas Piggin a écrit :
> Hand-written asm often contains non-function symbols in executable
> sections. _end symbols for finding the size of instruction blocks
> for runtime processing is one such usage.
> 
> optprobe_template_end is one example that causes the warning:
> 
>    objtool: optprobe_template_end(): can't find starting instruction
> 
> This is because the symbol happens to be at the end of the file (and
> therefore end of a section in the object file).
> 
> So ignore end-of-section STT_NOTYPE symbols instead of bailing out
> because an instruction can't be found. While we're here, add a more
> descriptive warning for STT_FUNC symbols found at the end of a
> section.

There's a patch to solve this already as far as I understand. They seem 
different.

See 
https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20221208072813.25799-1-sv@linux.ibm.com/

> 
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
>   tools/objtool/check.c | 9 +++++++++
>   1 file changed, 9 insertions(+)
> 
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index 4350be739f4f..4b7c8b33069e 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -427,6 +427,15 @@ static int decode_instructions(struct objtool_file *file)
>   			if (func->type != STT_NOTYPE && func->type != STT_FUNC)
>   				continue;
>   
> +			if (func->offset == sec->sh.sh_size) {
> +				/* Heuristic: likely an "end" symbol */
> +				if (func->type == STT_NOTYPE)
> +					continue;
> +				WARN("%s(): STT_FUNC at end of section",
> +				     func->name);
> +				return -1;
> +			}
> +
>   			if (func->return_thunk || func->alias != func)
>   				continue;
>   

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip: core/urgent] objtool: Tolerate STT_NOTYPE symbols at end of section
  2022-12-20 10:13 [PATCH] tools/objtool: tolerate STT_NOTYPE symbols at end of section Nicholas Piggin
  2022-12-20 14:21 ` Christophe Leroy
@ 2023-01-09 17:01 ` tip-bot2 for Nicholas Piggin
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Nicholas Piggin @ 2023-01-09 17:01 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Naveen N. Rao, Sathvika Vasireddy, Nicholas Piggin, Ingo Molnar,
	x86, linux-kernel

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

Commit-ID:     cad90e5381d840cf2296aaac9b3eff71a30b7c5b
Gitweb:        https://git.kernel.org/tip/cad90e5381d840cf2296aaac9b3eff71a30b7c5b
Author:        Nicholas Piggin <npiggin@gmail.com>
AuthorDate:    Tue, 20 Dec 2022 20:13:23 +10:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Mon, 09 Jan 2023 17:53:46 +01:00

objtool: Tolerate STT_NOTYPE symbols at end of section

Hand-written asm often contains non-function symbols in executable
sections. _end symbols for finding the size of instruction blocks
for runtime processing is one such usage.

optprobe_template_end is one example that causes the warning:

  objtool: optprobe_template_end(): can't find starting instruction

This is because the symbol happens to be at the end of the file (and
therefore end of a section in the object file).

So ignore end-of-section STT_NOTYPE symbols instead of bailing out
because an instruction can't be found. While we're here, add a more
descriptive warning for STT_FUNC symbols found at the end of a
section.

[ This also solves a PowerPC regression reported by Sathvika Vasireddy. ]

Reported-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Reported-by: Sathvika Vasireddy <sv@linux.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Sathvika Vasireddy <sv@linux.ibm.com>
Link: https://lore.kernel.org/r/20221220101323.3119939-1-npiggin@gmail.com
---
 tools/objtool/check.c |  9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 4350be7..4b7c8b3 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -427,6 +427,15 @@ static int decode_instructions(struct objtool_file *file)
 			if (func->type != STT_NOTYPE && func->type != STT_FUNC)
 				continue;
 
+			if (func->offset == sec->sh.sh_size) {
+				/* Heuristic: likely an "end" symbol */
+				if (func->type == STT_NOTYPE)
+					continue;
+				WARN("%s(): STT_FUNC at end of section",
+				     func->name);
+				return -1;
+			}
+
 			if (func->return_thunk || func->alias != func)
 				continue;
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-09 17:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-20 10:13 [PATCH] tools/objtool: tolerate STT_NOTYPE symbols at end of section Nicholas Piggin
2022-12-20 14:21 ` Christophe Leroy
2023-01-09 17:01 ` [tip: core/urgent] objtool: Tolerate " tip-bot2 for Nicholas Piggin

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®