DT_RELR design

H.J. Lu hjl.tools@gmail.com
Thu Jan 6 23:32:43 GMT 2022


On Thu, Jan 6, 2022 at 3:27 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Thu, Jan 6, 2022 at 3:11 PM Alan Modra <amodra@gmail.com> wrote:
> >
> > gcc -shared -fPIC on the following
> > struct pack { char c; void *p; } __attribute__ ((__packed__));
> > static char x;
> > struct pack ref = { 'A', &x };
> >
> > results in
> > 0000000000004021  0000000000000008 R_X86_64_RELATIVE
> >
> > That odd address can't be encoded by the current DT_RELR design.
> > That's likely to cause you some trouble on x86.
> >
>
> It has no problem:
>
> [hjl@gnu-tgl-2 build-x86_64-linux]$ cat x.c
> struct pack { char c; void *p; } __attribute__ ((__packed__));
> static char x;
> struct pack ref = { 'A', &x };
> [hjl@gnu-tgl-2 build-x86_64-linux]$ gcc -c -fPIC x.c -O2
> [hjl@gnu-tgl-2 build-x86_64-linux]$ ./ld/ld-new -z
> pack-relative-dyn-relocs x.o -shared -o libx.so
> [hjl@gnu-tgl-2 build-x86_64-linux]$ readelf -r libx.so
>
> Relocation section '.rela.dyn' at offset 0x240 contains 1 entry:
>   Offset          Info           Type           Sym. Value    Sym. Name + Addend
> 000000003001  000000000008 R_X86_64_RELATIVE                    3009
> [hjl@gnu-tgl-2 build-x86_64-linux]$
>
>           if (!elf_x86_relative_reloc_record_add
>                 (info,
>                  ((unaligned_section || unaligned_offset)
>                   ? &htab->unaligned_relative_reloc
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  This won't be placed in
> .relr.dyn section
>                   : &htab->relative_reloc),
>                  irel, input_section, sec, h, isym, offset))
>             goto error_return;
>
> My patch has tests to cover this case.
>
> --
> H.J.

FYI, my current DT_RELR code is at

https://gitlab.com/x86-binutils/binutils-gdb/-/commits/users/hjl/DT_RELR/master

It can build glibc with DT_RELR enabled successfully
on x86-64 and i686.

-- 
H.J.


More information about the Binutils mailing list