* DT_RELR design
@ 2022-01-06 23:11 Alan Modra
2022-01-06 23:27 ` H.J. Lu
2022-01-07 2:01 ` Fangrui Song
0 siblings, 2 replies; 4+ messages in thread
From: Alan Modra @ 2022-01-06 23:11 UTC (permalink / raw)
To: H.J. Lu; +Cc: binutils
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.
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: DT_RELR design
2022-01-06 23:11 DT_RELR design Alan Modra
@ 2022-01-06 23:27 ` H.J. Lu
2022-01-06 23:32 ` H.J. Lu
2022-01-07 2:01 ` Fangrui Song
1 sibling, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2022-01-06 23:27 UTC (permalink / raw)
To: Alan Modra; +Cc: Binutils
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: DT_RELR design
2022-01-06 23:27 ` H.J. Lu
@ 2022-01-06 23:32 ` H.J. Lu
0 siblings, 0 replies; 4+ messages in thread
From: H.J. Lu @ 2022-01-06 23:32 UTC (permalink / raw)
To: Alan Modra; +Cc: Binutils
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: DT_RELR design
2022-01-06 23:11 DT_RELR design Alan Modra
2022-01-06 23:27 ` H.J. Lu
@ 2022-01-07 2:01 ` Fangrui Song
1 sibling, 0 replies; 4+ messages in thread
From: Fangrui Song @ 2022-01-07 2:01 UTC (permalink / raw)
To: Alan Modra; +Cc: H.J. Lu, binutils, Cary Coutant
On 2022-01-07, Alan Modra via Binutils 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.
Odd addresses use R_*_RELATIVE.
Even addresses use .relr.dyn.
In my gold patch
https://sourceware.org/pipermail/binutils/2021-November/118567.html
gold/testsuite/relr_aarch64.sh actually tests this.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-01-07 2:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-06 23:11 DT_RELR design Alan Modra
2022-01-06 23:27 ` H.J. Lu
2022-01-06 23:32 ` H.J. Lu
2022-01-07 2:01 ` Fangrui Song
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).