Eric Pouech eric.pouech@wanadoo.fr writes:
don't you mean extern char _end[] instead ? there's nothing currently which ensures that pe_header is at the start of the code (it relies on the fact it's the first on gcc/ld link option, and that ld allocates slots for compilation units in the order they are expressed) => this may become a porting issue I'm not sure either that _end is completly portable?
using this technique (with _start, _etext, _edata, _bss_start, _end) we could also compute the "real" size of code, data, and bss which should be of some interest (even if data would be a bit more difficult, since we need to take care of the rsrc part)
If you really want to get everything right you have to write a linker script. This also allows making the PE header the first thing in the image. It's not very portable but it's easy to have a linker script for each platform. I played a bit with that back when we were trying to make the Visual C++ debugger work on builtin dlls, I may be able to find this code somewhere if someone is interested.