I tested two successfully exiting minimal programs, first uses libc
, second does not use libc
.
First:
segment .text
global main
main:
xor eax, eax
ret
Build and check size:
yasm -f elf64 main.s; clang -o main main.o; stat ./main
...
Size: 8552
...
Second:
segment .text
global _start
_start:
mov eax, 60
xor edi, edi
syscall
Build and check size:
yasm -f elf64 main.s; ld -o main main.o; stat ./main
...
Size: 704
---
Obviously program using main is larger in size. Why linkers does not strip main routine from binaries to optimise for size? I mean linkers that get object files after compilation of C program.