NASM 到 GAS:调用 equ'd 符号
我有一些 NASM 文件,其中包含一行:
%INCLUDE "bmdev.asm"
bmdev.asm
文件具有 equ 指令,例如:
b_print_newline equ 0x0000000000100040
包含 bmdev.asm
的文件然后能够调用这些项目。即
call b_print_newline
有没有办法将其转换为 GAS?当我尝试进行直接翻译时,即
.set b_print_newline , 0x100040
call b_print_string
它似乎没有反汇编为正确的内容:
callq *0x100040
NASM 调用反汇编为:
callq 0xfffffffffff00040
这里的目标是为 BareMetal OS 通过 GAS 而不是 NASM。
有效的二进制文件的完整反汇编:
$ 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
无效的二进制文件的完整反汇编:
$ 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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让 AS 生成相对调用是如此困难,这似乎有点奇怪,也许更聪明的人可以加入。
无论如何,这样做:
会导致(正如您所注意到的)AS 生成间接跳转。
您可以使用
.
自行伪造它。 (dot) 伪变量:或者您可以使用链接器(根据需要使用命令行或脚本)来定义具有正确名称的符号,在这种情况下,代码将根据您的意愿进行编译。
可能有一种方法可以让它在不使用链接器定义符号的情况下工作,但我还没有找到一种方法。
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:
results in (as you noticed) AS generating an indirect jump.
You can fake it on your own using the
.
(dot) pseudo-variable: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.
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.
我在 binutils 邮件列表中提出了这个问题。这似乎是一个错误。 建议我提交错误报告和我已经这样做了。
修复已签入 binutils 树。
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.