--- Additional Comments From vincent dot riviere at freesbee dot fr
2006-07-22 15:00 ---
Here are detailed tests.
# target i686-pc-cygwin
# gas 2.16.91 20050610 on host Windows XP SP2 ##
$ as bug.s -o bug.o
$ objdump -d bug.o
bug.o: file format pe-i386
Disassembly of section .text:
<.text>:
0: eb 01 jmp3 <.weak.mylabel.>
2: 90 nop
0003 <.weak.mylabel.>:
3: 90 nop
4: 90 nop
...
$ objdump -r bug.o
bug.o: file format pe-i386
$ ld bug.o -o bug
ld: warning: cannot find entry symbol _mainCRTStartup; defaulting to 00401000
$ objdump -d bug
bug: file format pei-i386
Disassembly of section .text:
00401000 <__RUNTIME_PSEUDO_RELOC_LIST_END__>:
401000: eb 01 jmp401003 <.weak.mylabel.>
401002: 90 nop
00401003 <.weak.mylabel.>:
401003: 90 nop
401004: 90 nop
...
$ objdump -r bug
bug: file format pei-i386
Everything is perfect here.
There is a short relative jump and no relocation.
# target i386-pc-linux #
# gas 2.17 on host Debian Sarge (stable) ###
$ as bug.s -o bug.o
$ objdump -d bug.o
bug.o: file format elf32-i386
Disassembly of section .text:
:
0: e9 fc ff ff ff jmp1
5: 90 nop
0006 :
6: 90 nop
$ objdump -r bug.o
bug.o: file format elf32-i386
RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
0001 R_386_PC32mylabel
$ ld bug.o -o bug
ld: warning: cannot find entry symbol _start; defaulting to 08048074
$ objdump -d bug
bug: file format elf32-i386
Disassembly of section .text:
08048074 :
8048074: e9 01 00 00 00 jmp804807a
8048079: 90 nop
0804807a :
804807a: 90 nop
$ objdump -r bug
bug: file format elf32-i386
In this case, gas generates a long relative jump AND a 32-bit relocation.
I didn't see that detail on my first post.
In the object file, the value of the jump looks quite strange. It is -4, in
fact the address to relocate relative to the instruction just after the jump.
Maybe this behavior is required by the elf object format ?
Anyway, the relocation entry is here and right.
After linking, the relative jump has the correct value and the executable has
no more relocation.
Even though it would be more optimal with a short jump and without a
relocation, the result is perfectly correct.
# target m68k-unknown-linux
# gas 2.17 on host Debian Sarge (stable) ###
$ as bug.s -o bug.o
$ objdump -d bug.o
bug.o: file format elf32-m68k
Disassembly of section .text:
:
0: 4ef9 jmp 0
6: 4e71nop
0008 :
8: 4e71nop
$ objdump -r bug.o
bug.o: file format elf32-m68k
RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
0002 R_68K_32 mylabel
$ ld bug.o -o bug
ld: warning: cannot find entry symbol _start; defaulting to 8074
$ objdump -d bug
bug: file format elf32-m68k
Disassembly of section .text:
8074 :
8074: 4ef9 8000 007c jmp 807c
807a: 4e71nop
807c :
807c: 4e71nop
$ objdump -r bug
bug: file format elf32-m68k
Here, gas generates an absolute long jump and a 32-bit relocation.
The value of the jump and the relocation are correct.
The linked executable contains the right jump value.
There is no relocation in the final executable, I suppose that it's normal for
that target.
# target m68k-unknown-netbsd ###
# gas 2.17 on host Debian Sarge (stable) ###
$ as bug.s -o bug.o
$ objdump -d bug.o
bug.o: file format a.out-m68k-netbsd
Disassembly of section .text:
:
0: 4efa 000a jmp %pc@(c )
4: 4e71nop
0006 :
6: 4e71nop
$ obj.netbsd/binutils/objdump -r bug.o
bug.o: file format a.out-m68k-netbsd
RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
0002 DISP16.text
$ ld bug.o -o bug
$ objdump -d bug
bug: file format a.out-m68k-netbsd
Disassembly of section .text:
2020 :
2020: 4efa 000a jmp %pc@(202c <__etext+0x4>)
2024: 4e71nop
2026 :
2026: 4e71nop
2028 <__etext>:
...
$ objdump -r bug
bug: file format a.out-m68k-netbsd
This