遵循本教程后我遇到了一个问题 - https://www.youtube.com/watch?v=RvvRO_gWYIg
几个可能的问题:
- 看起来处理器架构和操作系统可能与我正在研究的有很大不同。在视频中,它似乎是一个 i386 linux 机器,我正在使用 x64 OSX 机器。
- 当注释掉 helloWorldStr 引用时,它又开始工作了。
- 使用 32 位指令在 64 位机器上组装
下面发布的是损坏的代码,任何帮助将不胜感激!
# Hello World Program:
.data
HelloWorldStr:
.ascii "Hello World"
.text
.globl start
start:
# Load all the arguments for write():
# write(output, string, string_size)
movl $4, %eax # Load write()
movl $1, %ebx # Arg Output of write() :: STDOUT
movl $HelloWorldStr, %ecx # Referencing the Memory Loc. of the String
movl $11, %edx # Byte length of the String "Hello World"
int $0x80
# Call Exit:
movl $1, %eax
movl $0, %ebx
int $0x80
此外,这里出现了一些错误:
Undefined symbols for architecture x86_64:
"_main", referenced from:
start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
所以我将 _start 更改为 _main 然后传递到下一个错误:
gcc HelloWorldProgram.s -m32
ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in _main from /var/folders/8t/7639_vls58lgd1nnwx4dpbh40000gn/T//cc3wDW8K.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie