by cryne · 1y ago · 0 comments
nasm -f elf64 tiny.s && ld -s tiny.o
; tiny.asm
BITS 64
GLOBAL _start
SECTION .text
_start:
mov eax, 1
mov ebx, 42
int 0x80
and this lands me at 4320 bytes!
Why is there such a stark difference?Your linker must align the .text section to the page size (often 4096 bytes). If you open the binary with a hex editor you'll see lots of null padding.
[0] https://tmpout.sh/3/22.html
[1] https://github.com/binarygolf/BGGP/pull/3/files, assembly at https://gist.github.com/LegionMammal978/347c939def56dcba449c...
I think it's some sort of optimization (retrieving one page of memory should be easier than two, right?). With GNU ld I can do
ld -s -Ttext=0x4000b0 tiny.o
and shave off 3920 bytes on my system.