Author Topic: question about "section .data" in openbsd  (Read 9055 times)

Offline mmk213

  • Jr. Member
  • *
  • Posts: 8
question about "section .data" in openbsd
« on: July 24, 2017, 02:13:10 PM »
hi, here is an empty 64bit program in openbsd
Code: [Select]
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
Code: [Select]
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
Code: [Select]
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?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: question about "section .data" in openbsd
« Reply #1 on: July 25, 2017, 06:22:19 AM »
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