Re: [PATCH] compiler.h: Specify correct attribute for .rodata..c_jump_table

From: Josh Poimboeuf
Date: Wed Feb 12 2025 - 21:39:46 EST


On Thu, Feb 13, 2025 at 10:20:40AM +0800, Tiezhu Yang wrote:
> On 02/13/2025 01:50 AM, Josh Poimboeuf wrote:
> > > @@ -133,7 +133,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
> > > #define annotate_unreachable() __annotate_unreachable(__COUNTER__)
> > >
> > > /* Annotate a C jump table to allow objtool to follow the code flow */
> > > -#define __annotate_jump_table __section(".rodata..c_jump_table")
> > > +#define __annotate_jump_table __section(".rodata..c_jump_table,\"a\",@progbits #")
> >
> > This caused a regression, this hack apparently doesn't work with Clang:
> >
> > $ readelf -WS kernel/bpf/core.o | grep c_jump_table
> > [43] .rodata..c_jump_table,"a",@progbits # PROGBITS 0000000000000000 00d610 000800 00 A 0 0 16
> >
> > Notice the section name is literally:
> >
> > .rodata..c_jump_table,"a",@progbits #
>
> Yes, I noticed this section name which contains the original name
> ".rodata..c_jump_table" and the specified attribute compiled with
> Clang, it should not contain the specified attribute.
>
> That is strange but seems no effect due to only compare the first
> few letters of the section name in objtool.

It actually does have an effect -- objtool doesn't recognize the BPF C
jump table (see the use of C_JUMP_TABLE_SECTION in
tools/objtool/arch/x86/special.c), resulting in a bogus warning and
missing ORC.

I do have a workaround to use strstarts() instead of strcmp(), I'll be
posting that soon.

> I will keep digging with the GNU and LLVM compiler developers.

Thanks!

--
Josh