alternate title: "Hopefully the last day I spend all day trying to compile my code properly"
(context: I'm working on writing an OS, and am experiencing a mysterious recurring bug. After many days, I have found the reason!)
Today I went through the following:
- Decide to try to write some code
- Upgrade Rust, since my version is 8 days old
- Oh no, the new Rust breaks my oldish version of rust-core
- Upgrade rust-core
- Oh no, the new rust-core requires me to compile in a different way
- Spend a bunch of time messing with
clangand friends to get everything to compile again
- Everything compiles. Yay!
- Try to run code
- Encounter mystery bug again, where my array mysteriously contains 0s instead of its actual contents
- Make sad faces
- Go talk to Allison. Allison is the best.
- Allison asks: "What linker debugging strategies do you have?"
- Change the linker script randomly (actual thing that has worked)
- Change variable attributes from 'private' to 'public' at random (actual other thing that has worked)
- Look at the linker map or symbol table (not helpful, so far)
- Attach gdb to qemu and inspect the contents of memory (!!!)
gdb is great. It let me
- search my memory for "QWERTY" (not there! why not?)
- look at the memory at a given address (lots of zeros! huh!)
- Do a core dump, and compare it to the original file. Lots of zeros! Why is half my program gone?
SURPRISE MY CODE IS NOT WORKING BECAUSE SOMETHING IS ERASING IT.
Can we talk about this?
- I have code
- I can compile my code
- Half of my binary gets overwritten with 0s at runtime. Why. What did I do to deserve this?
- No wonder the order I put the binary in matters.
It is a wonder that this code even runs, man. Man.
Edit: I found why my binary has lots of 0s in it at runtime. It is
because I was only loading 12k of it in
loader.asm. Hopefully this
will serve as a lesson to someone.