分段故障调用printf NASM

时间:2014-10-30 22:16:51

标签: macos gcc segmentation-fault printf nasm

我正在使用Yosemite的Macbook Pro。无法使printf正常工作。这是我的代码:

extern _printf
global _main

section .data

msg:    db      "Hello World"

section .text

_main:
    push        msg
    call        _printf
    add         esp, 4
    ret

使用:

nasm -f macho test.s && gcc -arch i386 -e _main test.o && ./a.out

输出:

ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in _main from test.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
Segmentation fault: 11

我真的很感激任何帮助。

1 个答案:

答案 0 :(得分:1)

这完全回答了我的问题! How to print argv[0] in NASM?