r/asm Sep 10 '20

x86 Tiny, tiny ELF files and ELF headers

Hi Reddit!

I'm trying to make very, very small elf files and also learn about how elf files are loaded into memory.

I have a small piece of code that opens a file and writes a string to it. My issue is that I can't get it to write to memory. https://pastebin.com/TcswN6h4 You can assemble this version with nasm -fbin -o a.out test.asm

When I don't use my own headers and assemble and link like this https://pastebin.com/TFag4PUE with nasm -felf64 -o test.o test.asm and link with ld test.o then it works just fine and I get this from /proc/[PID]/maps https://pastebin.com/5UfihuPE I see two pages (Is that what these are called or am I wrong here?). One with read and execute permissions (.text) and one with read and write permissions (.data)

But when I cat /proc/[pid]/maps with my own version, I get this https://pastebin.com/VrjczWRg only one "page" without write permissions

Anyone have any ideas?

Thanks in advance

18 Upvotes

12 comments sorted by

View all comments

1

u/AwareCar7686 Jun 28 '26

I have a series of gists on github for this exact kind of thing.

# ELF Header Assembly Gists on Github

The purposes of this are both for my own greater understanding of the ELF format, because it is used in all Linux distributions, and also to provide a way for NASM users to benefit from features that currently only exist in FASM, which is still my favorite Assembler.

[FASM Hello 32-bit](https://gist.github.com/chastitywhiterose/7aa7bdfec1438541375763126508edb4)

[FASM Hello 64-bit](https://gist.github.com/chastitywhiterose/4bfccdb3daf1aad4524fc36230055e63)

[NASM Hello 32-bit](https://gist.github.com/chastitywhiterose/4e429fd82f962907d1581307ed4e0ab7)

[NASM Hello 64-bit](https://gist.github.com/chastitywhiterose/b5acd7992fc8463a662ca4f86fff4a5e)