NASM to GAS: Calling equ'd symbols
Pergunta
I have some NASM files which have a line:
%INCLUDE "bmdev.asm"
The bmdev.asm
file has equ directives such as:
b_print_newline equ 0x0000000000100040
The files which include bmdev.asm
then are able to call those items. I.e.
call b_print_newline
Is there a way to convert this to GAS? When I try to do the direct translation, i.e.
.set b_print_newline , 0x100040
call b_print_string
it doesn't appear to disassemble to the right thing:
callq *0x100040
The NASM call disassembles to:
callq 0xfffffffffff00040
The goal here is to generate binaries for BareMetal OS via GAS instead of NASM.
The full disassembly of the binary which works:
$ objdump -D -b binary -m i386:x86-64 test-nl.app
test-nl.app: file format binary
Disassembly of section .data:
0000000000000000 <.data>:
0: e8 3b 00 f0 ff callq 0xfffffffffff00040
5: c3 retq
The full disassembly of the binary which doesn't work:
$ objdump -D -b binary -m i386:x86-64 test-nl-a.app
test-nl-a.app: file format binary
Disassembly of section .data:
0000000000000000 <.data>:
0: ff 14 25 40 00 10 00 callq *0x100040
7: c3 retq
I've posted a (hopefully) clearer version of this question. Closing this one.
Solução 2
I brought this issue up on the binutils mailing list. It appears to be a bug. It was suggested that I file a bug report and I've done so.
A fix has been checked in to the binutils tree.
Outras dicas
It seems kind of odd that it should be so difficult to get AS to generate a relative call, perhaps someone smarter can jump in.
Anyway, doing:
.set b_print_newline, 0x100040
call b_print_newline
results in (as you noticed) AS generating an indirect jump.
You can fake it on your own using the .
(dot) pseudo-variable:
call b_print_newline - .
Or you can use the linker (command line or script as you wish) to define symbols with the correct names, in which case the code gets compiled as you wish.
$ cat test.S
.section .text
.globl _start
_start:
call b_print_newline
ret
$ as --64 -o test.o test.S
$ ld --defsym b_print_newline=0x100040 -Ttext 200000 --oformat binary -o test.bin test.o
$ objdump -D -b binary -m i386:x86-64 test.bin
test.bin: file format binary
Disassembly of section .data:
0000000000000000 <.data>:
0: e8 3b 00 f0 ff callq 0xfffffffffff00040
5: c3 retq
There is probably a way to make it work without using the linker to define symbols, but I haven't been able to find a way.