Sources Bugzilla – Bug 13046
Direct call doesn't work in 64bit
Last modified: 2011-08-01 19:38:38 UTC
Here's a small NASM program: [BITS 64] [ORG 0x0000000000200000] b_print_newline equ 0x0000000000100040 start: call b_print_newline ret Assemble it: $ nasm -f bin pr-nl-a.asm -o pr-nl-a.app Disassemble it: $ objdump -D -b binary -m i386:x86-64 pr-nl-a.app pr-nl-a.app: file format binary Disassembly of section .data: 0000000000000000 <.data>: 0: e8 3b 00 f0 ff callq 0xfffffffffff00040 5: c3 retq Here's a GAS version: .set b_print_newline , 0x0000000000100040 .text .global _start _start: call b_print_newline ret Assemble and link it: $ as -o pr-nl-b.o pr-nl-b.s $ ld -Ttext 200000 --oformat binary -o pr-nl-b.app pr-nl-b.o Disassemble it: $ objdump -D -b binary -m i386:x86-64 pr-nl-b.app pr-nl-b.app: file format binary Disassembly of section .data: 0000000000000000 <.data>: 0: ff 14 25 40 00 10 00 callq *0x100040 7: c3 retq As you can see, the disassembled code differs slightly. The code for `call` in NASM: 0: e8 3b 00 f0 ff callq 0xfffffffffff00040 vs GAS: 0: ff 14 25 40 00 10 00 callq *0x100040 Also, here's the program in FASM: b_print_newline equ 0x0000000000100040 use64 org 0x0000000000200000 start: call b_print_newline ret It does the right thing: $ objdump -D -b binary -m i386:x86-64 pr-nl-c.app pr-nl-c.app: file format binary Disassembly of section .data: 0000000000000000 <.data>: 0: e8 3b 00 f0 ff callq 0xfffffffffff00040 5: c3 retq I brought this issue up on the binutils list. It was suggested that I open a bug for this: http://sourceware.org/ml/binutils/2011-07/msg00277.html
(In reply to comment #0) > > Here's a GAS version: > > .set b_print_newline , 0x0000000000100040 > > .text > > .global _start > > _start: > > call b_print_newline > > ret > > Assemble and link it: > > $ as -o pr-nl-b.o pr-nl-b.s > $ ld -Ttext 200000 --oformat binary -o pr-nl-b.app pr-nl-b.o > > Disassemble it: > > $ objdump -D -b binary -m i386:x86-64 pr-nl-b.app > pr-nl-b.app: file format binary > > > Disassembly of section .data: > > 0000000000000000 <.data>: > 0: ff 14 25 40 00 10 00 callq *0x100040 > 7: c3 retq > You have "call b_print_newline" where b_print_newline is 0x100040 and you get "callq *0x100040". What is wrong with that? Please tell me why you think binutis is wrong. Please don't mention NASM here since I can say NASM is wrong.
> You have "call b_print_newline" where b_print_newline is 0x100040 > and you get "callq *0x100040". What is wrong with that? Please > tell me why you think binutis is wrong. Please don't mention NASM > here since I can say NASM is wrong. I brought the issue up on the mailing list because I wanted to know how to write the NASM version of the program in GAS. I was then told (by you) to report a bug: http://sourceware.org/ml/binutils/2011-07/msg00277.html Perhaps it's not a bug. I just would like to know how to port the NASM/FASM example to GAS.
(In reply to comment #2) > > You have "call b_print_newline" where b_print_newline is 0x100040 > > and you get "callq *0x100040". What is wrong with that? Please > > tell me why you think binutis is wrong. Please don't mention NASM > > here since I can say NASM is wrong. > > I brought the issue up on the mailing list because I wanted to know how to > write the NASM version of the program in GAS. I was then told (by you) to > report a bug: > > http://sourceware.org/ml/binutils/2011-07/msg00277.html > > Perhaps it's not a bug. I just would like to know how to port the NASM/FASM > example to GAS. Please tell me exactly what you want to do and I may tell you how to do it with gas. Please leave NASM out of it.
$ cat > equcall.s <<\EOF .text .set b_print_newline, 0x100040 .global _start _start: call b_print_newline ret EOF $ gas/as-new --64 -o equcall.o equcall.s equcall.s: Assembler messages: equcall.s:5: Warning: indirect call without `*' $ binutils/objdump -dr equcall.o equcall.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 <_start>: 0: ff 14 25 40 00 10 00 callq *0x100040 7: c3 retq $ gas/as-new --32 -o equcall.o /src/tmp/equcall.s $ binutils/objdump -dr equcall.o equcall.o: file format elf32-i386 Disassembly of section .text: 00000000 <_start>: 0: e8 3c 00 10 00 call 100041 <b_print_newline+0x1> 1: R_386_PC32 *ABS* 5: c3 ret $ cat > equcall.s <<\EOF .text .global _start _start: call b_print_newline ret .set b_print_newline, 0x100040 EOF $ gas/as-new --64 -o equcall.o equcall.s $ binutils/objdump -dr equcall.o equcall.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 <_start>: 0: e8 00 00 00 00 callq 5 <_start+0x5> 1: R_X86_64_PC32 *ABS*+0x10003c 5: c3 retq Definitely some inconsistency here.
[hjl@gnu-6 pr13046]$ cat x.s .text .global _start _start: call 0x100040 .intel_syntax noprefix call 0x100040 [hjl@gnu-6 pr13046]$ as --64 -o x.o x.s x.s: Assembler messages: x.s:4: Warning: indirect call without `*' [hjl@gnu-6 pr13046]$ objdump -dwr x.o x.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 <_start>: 0: ff 14 25 40 00 10 00 callq *0x100040 7: ff 14 25 40 00 10 00 callq *0x100040 [hjl@gnu-6 pr13046]$
CVSROOT: /cvs/src Module name: src Changes by: hjl@sourceware.org 2011-08-01 19:25:51 Modified files: gas/testsuite : ChangeLog gas/testsuite/gas/i386: x86-64-branch.d x86-64-branch.s gas/testsuite/gas/i386/ilp32: x86-64-branch.d opcodes : ChangeLog i386-opc.tbl i386-tbl.h Log message: Add Disp32S to 64bit call. gas/testsuite/ 2011-08-01 H.J. Lu <hongjiu.lu@intel.com> PR gas/13046 * gas/i386/x86-64-branch.s: Add tests for direct branch. * gas/i386/x86-64-branch.d: Updated. * gas/i386/ilp32/x86-64-branch.d: Likewise. opcodes/ 2011-08-01 H.J. Lu <hongjiu.lu@intel.com> PR gas/13046 * i386-opc.tbl: Add Disp32S to 64bit call. * i386-tbl.h: Regenerated. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1934&r2=1.1935 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/i386/x86-64-branch.d.diff?cvsroot=src&r1=1.3&r2=1.4 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/i386/x86-64-branch.s.diff?cvsroot=src&r1=1.2&r2=1.3 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/testsuite/gas/i386/ilp32/x86-64-branch.d.diff?cvsroot=src&r1=1.1&r2=1.2 http://sourceware.org/cgi-bin/cvsweb.cgi/src/opcodes/ChangeLog.diff?cvsroot=src&r1=1.1745&r2=1.1746 http://sourceware.org/cgi-bin/cvsweb.cgi/src/opcodes/i386-opc.tbl.diff?cvsroot=src&r1=1.97&r2=1.98 http://sourceware.org/cgi-bin/cvsweb.cgi/src/opcodes/i386-tbl.h.diff?cvsroot=src&r1=1.102&r2=1.103
Fixed.