Basic Hello World as seen many times before on x86_64 Linux:
global my_start_symbol
section .text
my_start_symbol:
mov rax, 1
mov rdi, 1
mov rsi, msg
mov rdx, msg_len
syscall
mov rax, 60
xor rdi, rdi
syscall
section .rodata:
msg: db "Hello, world!", 10
msg_len: equ $ - msg
My working ld
linker script:
ENTRY(my_start_symbol)
SECTIONS
{
. = 0x10000;
.text : { *(.text*) }
.rodata : { *(.rodata*) }
}
Invoked with:
nasm -f elf64 assembly.asm -o assembly.o
ld -T linker.ld assembly.o -o assembly
I get various segmentation faults when I experiment with the following changes:
- If I remove the
. = 0x10000
inside of my linker script or make it anything less than0x10000
I get a segfault. I thought this may be due to page size, howevergetconf PAGE_SIZE
returns 4K, so I don't know why 8K is necessary. - If I change the
.text
section in my assembly file to say.my_section_name
and update the linker to say.my_section_name : { *(.my_section_name*) }
I get a segfault. I thought the section names like.text
,.data
etc. were by convention, and that you could make them anything you wanted. If I'm wrong, why would.text : { *(.my_section_name*) }
give a segfault also?