我有这个:
$ make build
read.o: In function `_start':
read.asm:(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o:(.text+0x0): first defined here
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
Makefile:3: recipe for target 'build' failed
make: *** [build] Error 1
从此asm:
global main
section .text
main: mov rax, 1 ; system call for write
mov rdi, 1 ; file handle 1 is stdout
mov rsi, message ; address of string to output
mov rdx, 13 ; number of bytes
syscall ; invoke operating system to do the write
mov rax, 60 ; system call for exit
xor rdi, rdi ; exit code 0
syscall ; invoke operating system to exit
section .data
message: db "Hello, World", 10 ; note the newline at the end
我正在用它运行它:
$ nasm -felf64 read.asm -o read.o && gcc read.o -o store && ./store
如何将单词main
更改为main
或_start
以外的名称,例如begin
或myentrypoint
?我想自定义它。甚至可以定制吗?
请注意,main
不是入口点。入口点是_start
提供的crt0.o
,最终调用main
。您无法更改。但是,您可以提供自己的启动代码,以调用main
以外的其他功能。
注意,可以通过-e
的ld
选项将入口点本身设置为所需的任何符号。有关详细信息,请参见手册。但是请注意,如果您更改此设置,则C运行时代码将不再正常工作。仅与您自己的运行时代码一起使用。
将main
更改为其他选项的一种方法是将main
设置为其他符号的别名,例如与
.set main, mymain
在某些汇编文件中。我相信这应该可以。