Re: objtool crashes with some clang produced .o files

From: Peter Zijlstra
Date: Fri Dec 11 2020 - 04:33:51 EST


On Thu, Dec 10, 2020 at 03:35:45PM -0800, Nick Desaulniers wrote:

> > $ echo "__SCK__tp_func_cdev_update() { __SCT__tp_func_cdev_update(); }" > file.c

> > $ clang-12 -S file.c -O2 -fno-asynchronous-unwind-tables -o-
> > .text
> > .file "file.c"
> > .globl __SCK__tp_func_cdev_update # -- Begin function
> > __SCK__tp_func_cdev_update
> > .p2align 4, 0x90
> > .type __SCK__tp_func_cdev_update,@function
> > __SCK__tp_func_cdev_update: # @__SCK__tp_func_cdev_update
> > # %bb.0:
> > xorl %eax, %eax
> > jmp __SCT__tp_func_cdev_update # TAILCALL
> > .Lfunc_end0:
> > .size __SCK__tp_func_cdev_update, .Lfunc_end0-__SCK__tp_func_cdev_update
> > # -- End function
> > .ident "Ubuntu clang version
> > 12.0.0-++20201129052612+ce134da4b18-1~exp1~20201129163253.238"
> > .section ".note.GNU-stack","",@progbits
> > .addrsig

> (gdb) b tools/objtool/check.c:475
> (gdb) r orc generate file.o
> Breakpoint 1, create_static_call_sections (file=0x41f478 <file>) at check.c:475
> 475 reloc->sym = insn->sec->sym;
> (gdb) p insn->sec->sym
> $4 = (struct symbol *) 0x0
> (gdb) p insn->sec->name
> $5 = 0xc22d26 ".text"
>
> So some instruction in .text that contained a relocation for, we could
> not determine a symbol for?

Ooh, cute that's weird. So it's trying to write a relocation to the
site that does (IOW fill static_call_site::addr):

CALL/JMP __SCT*

and that's failing, because the instruction's section doesn't have a
symbol.

Both my GCC and clang-11 get me:

(gdb) p insn->sec->sym
$1 = (struct symbol *) 0x555555d83a70
(gdb) p insn->sec->sym->name
$2 = 0x555555d82f46 ".text"

Looking at elf.c, it seems we're missing an STT_SECTION symbol for
.text.

And indeed, when I add -fno-asynchronous-unwind-tables to clang-11, that
goes missing from the readelf .symtab listing. Help ?!