This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PR16794, gold ignores R_386_GOTOFF addend
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Alan Modra <amodra at gmail dot com>
- Cc: Binutils <binutils at sourceware dot org>, Cary Coutant <ccoutant at gmail dot com>
- Date: Thu, 26 Sep 2019 09:09:26 -0700
- Subject: Re: PR16794, gold ignores R_386_GOTOFF addend
- References: <20190926052338.GH19242@bubble.grove.modra.org>
On Wed, Sep 25, 2019 at 10:23 PM Alan Modra <amodra@gmail.com> wrote:
>
> An R_386_GOTOFF relocation has an addend, typically used when a
> symbol can be replaced by its section symbol plus an offset.
> psymval->value(object,0) is quite wrong then, fix it. The same goes
> for R_X86_64_GOTOFF64.
>
> Note that R_X86_64_GOTOFF64 isn't easy to generate from gcc, and may
> in fact be impossible nowadays. Also, x86 gas won't reduce symbols to
> section symbols on R_386_GOTOFF and R_X86_64_GOTOFF64. I suspect that
> isn't necessary, but I'm leaving that to HJ to investigate. (Keeping
> the original symbol is necessary for most GOT relocs in order to
> generate the proper GOT entry because the ABI says to put the symbol
> in the GOT entry, not symbol plus addend. The addend becomes a
> useless offset from the GOT entry. But anyway, these two relocs don't
> generate a GOT entry.)
>
I got
[hjl@gnu-cfl-1 tmp]$ cat y.s
.text
.globl foo
.type foo, @function
foo:
leal 2+bar@GOTOFF(%eax), %eax
.size foo, .-foo
.data
.align 4
.type bar, @object
.size bar, 10
bar:
.string "\001"
.zero 8
[hjl@gnu-cfl-1 tmp]$ gcc -c -m32 y.s
[hjl@gnu-cfl-1 tmp]$ readelf -r y.o
Relocation section '.rel.text' at offset 0x110 contains 1 entry:
Offset Info Type Sym.Value Sym. Name
00000002 00000209 R_386_GOTOFF 00000000 .data
[hjl@gnu-cfl-1 tmp]$
GOTOFF relocation against the local symbol is reduced to
section.
--
H.J.