Re: [RFC PATCH] objtool: Skip unannotated intra-function call warning for bl+mflr pattern

From
Sathvika Vasireddy <hidden>
Date
2025-02-21 08:51:14
Also in
lkml, llvm
Reply to
Josh Poimboeuf, 2025-02-20
Hi Josh, Thanks for the review.

On 2/21/25 1:29 AM, Josh Poimboeuf wrote:
On Wed, Feb 19, 2025 at 09:50:14PM +0530, Sathvika Vasireddy wrote:
quoted
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
If I understand correctly, this is basically a fake call which is used
to get the value of the program counter?
Yes, that's correct.

Also, just out of curiosity, how does x86 do it? Does it not use a branch to next instruction approach?
quoted
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.

Reported-by: kernel test robot <redacted>
Closes: https://lore.kernel.org/oe-kbuild-all/202502180818.XnFdv8I8-lkp@intel.com/ (local)
Signed-off-by: Sathvika Vasireddy <redacted>
This should have a Fixes tag as well.
Thanks for catching that. I'll add the Fixes tag.
quoted
  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;
+
This won't work on x86, where an intra-function call is converted to a
stack-modifying JUMP.  So this should probably be checked in an
arch-specific function.
Thanks for letting me know, I'll introduce arch_skip_call_warning() to handle architecture specific cases in the next patch I send.

Regards,
Sathvika
Thread (12 messages) 12 messages, 5 authors, last reply 2025-02-25
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help