Re: [PATCH] objtool: Use idiomatic section name for relocatable rodata under PIE

From: Josh Poimboeuf
Date: Tue Feb 18 2025 - 15:18:09 EST


On Tue, Feb 18, 2025 at 08:36:42PM +0100, Ard Biesheuvel wrote:
> > > > If so, it feels like this needs to be its own patch, described as a fix.
> > > >
> > >
> > > Fair enough. But better to drop the previous patch from the objtool tree then.
> >
> > I think we can do that... Peter?
> >
> > And just to be clear, you'll have two fixes, right?
> >
> > 1) Make loongarch .data.rel.ro.* actually read-only
> > 2) Fix objtool C jump table annotations for clang
> >
>
> One fix is to emit .data.rel.ro input sections into .rodata, and fix
> objtool accordingly so it also looks for jump tables there.

Hm, I don't think so... I think at least one of us is confused :-)

Objtool reads object files (including vmlinux.o) before the final
vmlinux link. So a linker script change isn't visible to objtool.

And switch statment jump tables are always compiled in .rodata.*.
Right?

> The other is to emit the BPF jump table into .data.rel.ro.c_jump_table
> so that the linker does not complain about conflicting permissions.
>
> Does that sound about right?

I could be completely confused, but my understanding is we need the
following two fixes:

1) Map .data.rel.ro.* into .rodata for vmlinux to so that it actually
becomes read-only at runtime. This has nothing to do with objtool
AFAIK.

2) Fix the __annotate_jump_table macro for Clang, which takes:

__section(".rodata..c_jump_table,\"a\",@progbits #")

quite literally. So we need a new section name that works for GCC,
Clang, and GCC -fPIE. And it should be mapped in vmlinux .rodata.

--
Josh