This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
x86-64 linker ignores relocation overflow
On Thu, Sep 28, 2006 at 05:40:41PM -0700, H. J. Lu wrote:
> On Thu, Sep 28, 2006 at 03:33:05PM +0100, Keir Fraser wrote:
> >
> > > Compile and link the attached C program as follows. I used gcc-4.1.1 and
> > > binutils-2.17, but gcc >= 4.0.0 and binutils >= 2.16 probably suffice.
> > >
> > > # gcc -fpic -o test.o -c test.c
> > > # ld -Ttext 100000000 -o test test.o
> > >
> > > Disassembly of the result trivially shows that the address of weak symbol 'x'
> > > is 0x100000000.
> >
> > By the way, experimentation with the address of the text section shows that
> > the weak symbol's address is resolved to the nearest 4GB-aligned address
> > (nearest to what I'm not sure -- RIP? Section start?). It may get rounded up
> > or down, whichever is nearest.
>
> You are asking for impossible:
>
> [hjl@gnu-13 weak-4]$ objdump -dr foo.o
>
> foo.o: file format elf64-x86-64
>
> Disassembly of section .text:
>
> 0000000000000000 <_start>:
> 0: 55 push %rbp
> 1: 48 89 e5 mov %rsp,%rbp
> 4: 48 8d 05 00 00 00 00 lea 0(%rip),%rax # b
> <_start+0xb>
> 7: R_X86_64_PC32 x+0xfffffffffffffffc
> b: c9 leaveq
> c: c3 retq
>
> R_X86_64_PC32 only supports signed 32bit offset. 0x100000000 is more
> than 32bit. The linker should issue an error, at least a warning. You
> can take your pick and I will fix the linker. If no one objects, I
> will make it an error.
Alan, linker doesn't issue an error due to this patch:
http://sourceware.org/ml/binutils/2004-06/msg00199.html
I don't quite understand how it is supposed to work.
H.J.