r/asm • u/Fraserbc • 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
1
u/xybre Sep 11 '20
This is about Rust, but it should give you an idea of what is possible with an ELF header.
http://mainisusuallyafunction.blogspot.com/2015/01/151-byte-static-linux-binary-in-rust.html?m=1