From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Sathvika Vasireddy <sv@linux.ibm.com>,
jpoimboe@kernel.org, peterz@infradead.org, npiggin@gmail.com,
maddy@linux.ibm.com
Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
llvm@lists.linux.dev
Subject: Re: [RFC PATCH] objtool: Skip unannotated intra-function call warning for bl+mflr pattern
Date: Mon, 24 Feb 2025 08:15:04 +0100 [thread overview]
Message-ID: <3223ec0e-c445-4bbf-ae72-276688e40908@csgroup.eu> (raw)
In-Reply-To: <20250219162014.10334-1-sv@linux.ibm.com>
Le 19/02/2025 à 17:20, Sathvika Vasireddy a écrit :
> Architectures like PowerPC use a pattern where the compiler generates a
> branch-and-link (bl) instruction that targets the very next instruction,
> followed by loading the link register (mflr) later. This pattern appears
> in the code like:
>
> bl .+4
> li r5,0
> mflr r30
What compiler do you use ? Is it a very old version of GCC ?
That sequence is not correct and should never be used by modern
compilers. It should be bcl 20,31,+4 instead.
All such hand writen sequences have been removed from kernel assembly,
see commit c974809a26a1 ("powerpc/vdso: Avoid link stack corruption in
__get_datapage()") for details
>
> Objtool currently warns about this as an "unannotated intra-function
> call" because find_call_destination() fails to find any symbol at the
> target offset. Add a check to skip the warning when a branch targets
> the immediate next instruction in the same function.
I think this should be done in arch_decode_instruction(), just set
insn->type to INSN_OTHER when you see bl .+4
Something like:
diff --git a/tools/objtool/arch/powerpc/decode.c
b/tools/objtool/arch/powerpc/decode.c
index 53b55690f320..ca264c97ee8d 100644
--- a/tools/objtool/arch/powerpc/decode.c
+++ b/tools/objtool/arch/powerpc/decode.c
@@ -55,7 +55,9 @@ int arch_decode_instruction(struct objtool_file *file,
const struct section *sec
switch (opcode) {
case 18: /* b[l][a] */
- if ((ins & 3) == 1) /* bl */
+ if (ins == 0x48000005) /* bl .+4 */
+ typ = INSN_OTHER;
+ else if ((ins & 3) == 1) /* bl */
typ = INSN_CALL;
imm = ins & 0x3fffffc;
>
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202502180818.XnFdv8I8-lkp@intel.com/
> Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
> ---
> tools/objtool/check.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index 753dbc4f8198..3f7cf2c917b5 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -1613,6 +1613,7 @@ static struct symbol *find_call_destination(struct section *sec, unsigned long o
> */
> static int add_call_destinations(struct objtool_file *file)
> {
> + struct instruction *next_insn;
> struct instruction *insn;
> unsigned long dest_off;
> struct symbol *dest;
> @@ -1625,6 +1626,11 @@ static int add_call_destinations(struct objtool_file *file)
> reloc = insn_reloc(file, insn);
> if (!reloc) {
> dest_off = arch_jump_destination(insn);
> +
> + next_insn = next_insn_same_func(file, insn);
> + if (next_insn && dest_off == next_insn->offset)
> + continue;
> +
> dest = find_call_destination(insn->sec, dest_off);
>
> add_call_dest(file, insn, dest, false);
> --
> 2.39.3
>
next prev parent reply other threads:[~2025-02-24 8:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-19 16:20 Sathvika Vasireddy
2025-02-20 19:59 ` Josh Poimboeuf
2025-02-21 8:50 ` Sathvika Vasireddy
2025-02-24 10:36 ` Christophe Leroy
2025-02-24 12:35 ` Peter Zijlstra
2025-02-24 16:25 ` Peter Zijlstra
2025-02-24 17:54 ` Christophe Leroy
2025-02-24 7:15 ` Christophe Leroy [this message]
2025-02-24 10:33 ` Christophe Leroy
2025-02-24 13:19 ` Christophe Leroy
2025-02-24 17:09 ` Nathan Chancellor
2025-02-25 7:35 ` Christophe Leroy
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=3223ec0e-c445-4bbf-ae72-276688e40908@csgroup.eu \
--to=christophe.leroy@csgroup.eu \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=llvm@lists.linux.dev \
--cc=maddy@linux.ibm.com \
--cc=npiggin@gmail.com \
--cc=peterz@infradead.org \
--cc=sv@linux.ibm.com \
/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®