NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: mmk213 on July 24, 2017, 02:13:10 PM
-
hi, here is an empty 64bit program in openbsd
section .note.openbsd.ident
align 0x02
dd 0x08, 0x04, 0x01
db 'OpenBSD', 0x00
dd 0x00
align 0x02
section .text
global _start
_start:
xor eax, eax
inc al
syscall
i compile it with
nasm -f elf64 simple.asm -o simple.o
ld -o simple simple.o -m elf_x86_64_obsd -nopie
and i get an executable which is 1390 bytes in size (kind of huge).. when i strip it it gets to 904 bytes..
now, my question is this:
when i add a simple data section with
section .data
cr: db 0x05
and recompile it, my executable is now 5001 bytes!!
can someone explain me why does adding a one byte data section increase my executable by more than 4000 bytes in openbsd?
-
Sounds like a "page" - 4096 bytes. From what you're seeing, it looks like openbsd must allocate a full page for a section if it exists at all. There might be a way to tell ld not to do that. I don't think there's anything Nasm can do about it. You might be able to make section .text writeable, but you probably don't want to.
Best,
Frank