I feel like asking a very stupid question but was not able to find anything useful so far...
So I have like the most trivial assembler programm imaginable which goes like this
SECTION .TEXT
GLOBAL _start
_start:
mov rax, 60
mov rdi, 0
syscall
I use nasm to generate an object file like
nasm -f elf64 -o test.o test.asm
Link with ld like
ld -o test test.o
Running the resulting executable results in a segfault
./test
Segmentation fault (core dumped)
As I have been able to find some assembler examples online that have exactly the same assembler program and which do apparently execute successfully I guess there must be something wrong with either my call to nasm or to ld. Any help or suggestion would be appreciated.
Results of readelf do not look suspicious to me but I'm not too familiar with that
readelf -a test
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x401000
Start of program headers: 64 (bytes into file)
Start of section headers: 4352 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 1
Size of section headers: 64 (bytes)
Number of section headers: 5
Section header string table index: 4
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .TEXT PROGBITS 0000000000401000 00001000
000000000000000c 0000000000000000 A 0 0 1
[ 2] .symtab SYMTAB 0000000000000000 00001010
00000000000000a8 0000000000000018 3 3 8
[ 3] .strtab STRTAB 0000000000000000 000010b8
0000000000000022 0000000000000000 0 0 1
[ 4] .shstrtab STRTAB 0000000000000000 000010da
0000000000000021 0000000000000000 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
D (mbind), l (large), p (processor specific)
There are no section groups in this file.
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000
0x000000000000100c 0x000000000000100c R 0x1000
Section to Segment mapping:
Segment Sections...
00 .TEXT
There is no dynamic section in this file.
There are no relocations in this file.
No processor specific unwind information to decode
Symbol table '.symtab' contains 7 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 FILE LOCAL DEFAULT ABS test.asm
2: 000000000040100c 0 NOTYPE LOCAL DEFAULT 1 _end
3: 0000000000401000 0 NOTYPE GLOBAL DEFAULT 1 _start
4: 000000000040200c 0 NOTYPE GLOBAL DEFAULT 1 __bss_start
5: 000000000040200c 0 NOTYPE GLOBAL DEFAULT 1 _edata
6: 0000000000402010 0 NOTYPE GLOBAL DEFAULT 1 _end
No version information found in this file.
Same goes for objdump
objdump -D test.o
test.o: file format elf64-x86-64
Disassembly of section .TEXT:
0000000000000000 <_start>:
0: b8 3c 00 00 00 mov $0x3c,%eax
5: bf 00 00 00 00 mov $0x0,%edi
a: 0f 05 syscall