Commit: Treat .relro_padding as a special section
Jan Beulich
jbeulich@suse.com
Wed Jul 24 13:54:58 GMT 2024
On 24.07.2024 15:47, Nick Clifton wrote:
> Hi Guys,
>
> I am applying the patch below to fix an issue with running objcopy on
> binaries created by lld. Lld can generate a synthetic section called
> ".relro_padding" whose purpose should be obvious. It has a type of
> SHT_NOBITS and an entsize of 0.
>
> Unfortunately when the BFD library encounters this section - eg
> because objcopy is being used - it matches the section's name to the
> pattern for ".rel" special sections which means that it gets treated
> as a SHT_REL section and, if the target architecture supports REL
> relocations, the entsize is changed to 8. Not only is this change
> wrong, but it also causes problems later on if it turns out that the
> section's size is not a multiple of 8. For example, strip will refuse
> to process it.
>
> To see this in action try copying the i686 version of libclang.so:
>
> $ objcopy libclang.so.18.1 jim
> $ readelf -WS libclang.so.18.1 jim | grep relro
> [24] .relro_padding NOBITS 02521d2c 251fd2c 0002d4 00 WA 0 0 1
> [24] .relro_padding NOBITS 02521d2c 251fd2c 0002d4 08 WA 2 0 1
>
> Note the changes to the entsize (00 to 08) and link (0 to 2).
>
> All of which is a long explanation for a simple patch which adds the
> .relro_padding section as a special section in its own right, so that
> it can be copied without any changes.
Surely a useful workaround for the moment, but mind me asking why
_bfd_elf_get_special_section() goes solely by name, and not (at least)
also by type? If I'm not mistaken ELF permits people to create sections
of any names they like, without them obtaining special meaning as long
as type is e.g. SHT_PROGBITS. (Yes, I know of psABI-s which undermine
this basic idea by using SHT_PROGBITS for special sections of theirs.)
Jan
More information about the Binutils
mailing list