Компиляция программ из Assembler (NASM unix 64bit intel)

Есть программа:

   section .data
    msg db "Hello world!",10

section .text
    global start

start:
    mov rax, 1
    mov rdi, 1
    mov rsi, msg
    mov rdx, 13
    syscall

    mov rax, 60
    mov rdi, 0
    syscall

создаю объект:

nasm -f macho64 hello.asm

пытаюсь создать исполняемый файл:

ld hello.o -o hello

код ошибки:

Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64

меняю start на _main, предупреждение:

ld: dynamic main executables must link with libSystem.dylib for architecture x86_64

исполняю:

[2]    8119 segmentation fault  ./a.out

пишу main на с:

void    hello_asm(void);

int     main(void)
{
    hello_asm();
    return (0);
}

меняю _main на _hello_asm, компилирую, предупреждение:

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

исполняю:

[2]    8082 segmentation fault  ./a.out

как в итоге нужно правильно все это делать?


Ответы (0 шт):