相关疑难解决方法(0)

为什么这个movq指令适用于linux而不是osx?

以下汇编代码as在OSX 10.9.4上运行时出错,但在Linux(Debian 7.6)上成功运行.特别是,movq指令似乎不喜欢label参数.

$ cat test.S
.globl _main
_main:
    movq $_main, %rax
    ret
Run Code Online (Sandbox Code Playgroud)

这是错误:

$ as -o test.o test.S 
test.S:3:32-bit absolute addressing is not supported for x86-64
test.S:3:cannot do signed 4 byte relocation
Run Code Online (Sandbox Code Playgroud)

将$_main第3行更改为文字$10就好了.

代码必须以非常小的方式进行修改才能在Linux上运行 - 只需从标签中删除下划线即可.

$ cat test.S
.globl main
main:
    movq $main, %rax
    ret
Run Code Online (Sandbox Code Playgroud)

很容易独立验证代码在Linux上是否可行:

$ as -o test.o test.S
$ gcc -o test.out test.o
$ ./test.out
Run Code Online (Sandbox Code Playgroud)

请忽略代码并没有真正做很多事情,我故意尽可能地将其修剪下来以证明错误.

我已经看了很多使用LEA(加载有效地址),但在我做出改变之前,我想了解其中的区别 - 为什么它适用于Linux而不是OSX?

linux macos x86-64

11
推荐指数
1
解决办法
1688
查看次数

标签 统计

linux ×1

macos ×1

x86-64 ×1