I'm learning assembly and I'm trying to run a quite simple program.
section .text
    global start
    global _main
start:
    call _main
    ret
_main:
    push 42
    ret
I'm using NASM on OSX 64-bits. Here is what I tried :
$ nasm -f macho64 simple.asm -o simple.o
$ ld simple.o -o a.out
$ ./a.out
dyld: no writable segment
[1]    38021 trace trap  ./a.out
$
$ ld -lc -ldylib1.o -e start simple.o -o a.out
$ ./a.out
[1]    38134 segmentation fault  ./a.out
$
$ ld -macosx_version_min 10.8 -lSystem simple.o -o a.out
[1]    38134 segmentation fault  ./a.out
$
Following this post, I added section .data into the code.
$ nasm -f macho64 simple.asm && ld simple.o && ./a.out
[1]    39119 killed     ./a.out
1) How can I get my program not to be killed ?
2) Why do my program get those signals (SIGTRAP, SIGSEGV and SIGKILL) ?
3) Where could I have found those answers without asking ? Explanations I've found until now do require prior knowledge about assembly.
Edit
I understood my mistake with push 42, thank you. My program runs when loaded with ld -macosx_version_min 10.8 -lSystem simple.o. But :
- I still have the SIGTRAP when loaded with - ld simple.o
- I still have the segfault when loaded with - ld -lc -ldylib1.o -e start simple.o
- I still have a SIGKILL when I add - section .dataand load with- ld simple.o
- I have a bus error when I add - section .dataand load with- ld -macosx_version_min 10.8 -lSystem simple.o
I wonder why I get those signals (in order to understand how it works). I'd also like to know why I have to specify macosx_version_min and how I could have found it without having a friend telling it to me.
 
     
     
    