nasm:"global _start:"可以吗?
nasm: Is "global _start:" allowed?
我的代码如下所示:
section .text
global _start:
_start:
...
如果我编译它:
nasm -f elf test.asm
我没有收到任何错误,链接后程序对我有用。
现在的问题是我的导师无法编译我的程序,必须删除 global _start:
行中的“:”才能使其运行。
- 怎么会没有报错还能编译呢?
- 是“:”吗?allowed/legal 程序应该可以运行吗?
我试图找出为什么 NASM 可能不会拒绝:
GLOBAL, like EXTERN, allows object formats to define private
extensions by means of a colon. The elf object format, for example,
lets you specify whether global data items are functions or data:
global hashlookup:function, hashtable:data
Like EXTERN, the primitive
form of GLOBAL differs from the user-level form only in that it can
take only one argument at a time.
-- http://www.nasm.us/doc/nasmdoc6.html
所以这只是解析器的一个怪癖。可以组装,但我没有检查它组装成什么。
不要这样做。这显然是错误的,你不应该指望它会起作用。它只能靠运气工作。与往常一样,在这些情况下,如果不这样做没有任何好处,请坚持使用正常语法。即使您不混淆 compiler/assembler,您也会混淆其他人类读者。
我的代码如下所示:
section .text
global _start:
_start:
...
如果我编译它:
nasm -f elf test.asm
我没有收到任何错误,链接后程序对我有用。
现在的问题是我的导师无法编译我的程序,必须删除 global _start:
行中的“:”才能使其运行。
- 怎么会没有报错还能编译呢?
- 是“:”吗?allowed/legal 程序应该可以运行吗?
我试图找出为什么 NASM 可能不会拒绝:
GLOBAL, like EXTERN, allows object formats to define private extensions by means of a colon. The elf object format, for example, lets you specify whether global data items are functions or data:
global hashlookup:function, hashtable:data
Like EXTERN, the primitive form of GLOBAL differs from the user-level form only in that it can take only one argument at a time.
-- http://www.nasm.us/doc/nasmdoc6.html
所以这只是解析器的一个怪癖。可以组装,但我没有检查它组装成什么。
不要这样做。这显然是错误的,你不应该指望它会起作用。它只能靠运气工作。与往常一样,在这些情况下,如果不这样做没有任何好处,请坚持使用正常语法。即使您不混淆 compiler/assembler,您也会混淆其他人类读者。