Initial DT_RELR support in bfd linker

Fangrui Song i@maskray.me
Wed Jan 5 04:44:12 GMT 2022


On 2022-01-02, H.J. Lu wrote:
>Hi,
>
>I created users/hjl/DT_RELR/master branch:
>
>https://gitlab.com/x86-binutils/binutils-gdb/-/commits/users/hjl/DT_RELR/master
>
>for initial DT_RELR support in bfd linker.   I added
>a -z pack-relative-dyn-relocs option which also adds
>GLIBC_ABI_VERSION_GEN2 dependency when
> -z pack-relative-dyn-relocs option is used to link
>against glibc.

Thanks for working on this!

Non-glibc systems (musl, FreeBSD, NetBSD, etc) will definitely want a
version of -z pack-relative-dyn-relocs which does not require GLIBC_ABI_VERSION_GEN2 in .gnu.version_r.

I managed to test this with
https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/maskray/relr
by commenting out elf_link_add_packed_relative_dyn_reloc_dependency:

--- i/bfd/elflink.c
+++ w/bfd/elflink.c
@@ -2219,2 +2219,3 @@ _bfd_elf_export_symbol (struct elf_link_hash_entry *h, void *data)
  
+__attribute__((unused))
  static bool
@@ -7045,3 +7046,3 @@ bfd_elf_size_dynamic_sections (bfd *output_bfd,
         {
-         elf_link_add_packed_relative_dyn_reloc_dependency (&sinfo);
+         //elf_link_add_packed_relative_dyn_reloc_dependency (&sinfo);
           if (sinfo.failed)


A -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=-fpie -DCMAKE_EXE_LINKER_FLAGS=-pie -DLLVM_ENABLE_PROJECTS=clang
Clang build crashes with -z pack-relative-dyn-relocs.
In llvm-readelf -r output, .rela.dyn has 277 R_X86_64_RELATIVE
relocations while .relr.dyn has 535577. This may be suspicious.
ld.lld --pack-dyn-relocs=relr places all relative relocations in .relr.dyn.

I am sure you know how to reproduce by yourself:)


More information about the Libc-alpha mailing list