[PATCH 05/10] ld: Initial DT_RELR support

H.J. Lu hjl.tools@gmail.com
Sat Jan 8 13:19:55 GMT 2022


On Sat, Jan 8, 2022 at 12:30 AM Fangrui Song <i@maskray.me> wrote:
>
> On 2022-01-07, H.J. Lu via Binutils wrote:
> >Add a -z pack-relative-relocs option to enable DT_RELR and create a
> >relr.dyn section for DT_RELR.
> >
> >-z pack-relative-relocs implies -z combreloc and --relax.  --no-relax
> >and -z nocombreloc imply -z nopack-relative-relocs.
> >
> >-z pack-relative-relocs is chosen over the similar option in lld,
> >--pack-dyn-relocs=relr, to implement a glibc binary lockout mechanism
> >with a special glibc version symbol, to avoid random crashes of DT_RELR
> >binaries with the existing glibc binaries.
>
> I think -z pack-relative-relocs is orthogonal to -z combreloc.
> -z combreloc affects how .rela.dyn is sorted and whether RELACOUNT is
> generated. It has nothing to do with .relr.dyn, which is a different section.

With -z nocombreloc, ld can generate:

$ readelf -r tmpdir/pr25754-3ba

Relocation section '.rela.data.rel.ro' at offset 0x540 contains 1 entry:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000003de8  000000000008 R_X86_64_RELATIVE                    3de8

Relocation section '.rela.got' at offset 0x558 contains 5 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000003fd0  000100000006 R_X86_64_GLOB_DAT 0000000000000000
__libc_start_main@GLIBC_2.34 + 0
000000003fd8  000200000006 R_X86_64_GLOB_DAT 0000000000000000
_ITM_deregisterTM[...] + 0
000000003fe8  000400000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0
000000003ff0  000500000006 R_X86_64_GLOB_DAT 0000000000000000
_ITM_registerTMCl[...] + 0
000000003ff8  000600000006 R_X86_64_GLOB_DAT 0000000000000000
__cxa_finalize@GLIBC_2.2.5 + 0

Relocation section '.rela.fini_array' at offset 0x5d0 contains 1 entry:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000003de0  000000000008 R_X86_64_RELATIVE                    10f0

Relocation section '.rela.init_array' at offset 0x5e8 contains 1 entry:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000003dd8  000000000008 R_X86_64_RELATIVE                    1130

Relocation section '.rela.plt' at offset 0x600 contains 1 entry:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000004018  000300000007 R_X86_64_JUMP_SLO 0000000000000000
puts@GLIBC_2.2.5 + 0

3 R_X86_64_RELATIVEs are 3 different .rela sections.
If they are put in a single section, they are combined.

-- 
H.J.


More information about the Libc-alpha mailing list