DT_RELR design
H.J. Lu
hjl.tools@gmail.com
Thu Jan 6 23:27:47 GMT 2022
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.
More information about the Binutils
mailing list