Octacone wrote:Interesting, why did the compiler choose those two .text sections and not some other random ones?
When a template is instantiated, the compiler will generate a new section with the name indicating what exactly it contains. You can push the name through c++filt to see the cleartext version of it. If multiple CPP files instantiate the same template, their object files will contain the same template text sections. They are marked to only be linked once, so the linker throws all but one instance of the code away.
This allows you to compile and link C++ like you'd do with C. And believe me, it is a blessing. At work I have to deal with a compiler that uses a prelinker. In that system, the compiler will not instantiate templates at all, but rather, the linker is run again and again. The prelinker identifies undefined references to template instances and recompiles certain source files after telling the compiler to instantiate a certain template in there. It takes ages to complete and is extremely fragile in case the source file is no longer available at the time of the final link. Which can happen with libraries, for example.
Octacone wrote:On QEMU my constants are located at 0xC010F2B1 (and contain real data) and on real hardware they're at 0x350046 (and contain garbage data)! Like how! That is impossible they should be +3GB higher (at least).
OK, is your linear mapping not long enough?
Octacone wrote:There is really not much space when it comes to debugging on real hardware. The only thing I can do is dump registers and memory (if mapped) and that's about it.
That's about all you'll ever need. Once you've found the corrupt memory, you can use the debug registers to find out who wrote to it.
nullplan wrote:What do I gain by using the WP bit?
If bad code writes into read-only sections, you get an exception immediately instead of memory corruption that crashes down the line somewhere.