I have a hello world program:
.global _start
.text
_start:
# write (1, msj, 13)
mov $1, %rax # system call 1 is write
mov $1, %rdi # file handler 1 is stdout
mov $message, %rsi # address of string to output
mov $13, %rdx # number of bytes
syscall
# exit(0)
mov $60, %rax # system call 60 is exit
xor %rdi, %rdi # we want to return code 0
syscall
message:
.ascii "Hello, world\n"
I can assemble this into an object file with:
as hello.s -o hello.o
This object file is not executable. When I try to execute it, I get:
bash: ./hello.o: cannot execute binary file: Exec format error
I need to invoke the linker to make this viable:
ld hello.o -o hello
At this point, the hello program works. However, the use of the linker here is confusing to me.... I'm not linking in any external libraries! I seem to just be linking the object file to nothing.
What is the linker doing for such a "self-contained" program?