Choosing ELF sections in C
Posted: Sat May 02, 2009 2:27 pm
I was wondering if it is possible to select in which ELF section a piece of code or global data will be stored in C. I know you can do it quite easily in assembly. My intent is to put all of the code that has to do with initializing my kernel in a separate ELF section, then free it once the system is booted, because more than half of the code is for initialization (my kernel is very small), and I want to be conservative about memory. I can get a couple of pages back based on the object size, and it's only about half written already.
It seems like this wouldn't be conventionally possible, because of the fact that not everyone uses ELF binaries, but is there some sort of linker hack that would let this work?
Alternatively, because all of the init code is compiled into one object, then linked with objects from other parts of the kernel, which I'm *assuming* means they are contiguously grouped, perhaps there is some way of detecting the upper and lower limits of that object in the section?
Thanks!
BTW, this is using GNU CC/Binutils and a higher half kernel design.
It seems like this wouldn't be conventionally possible, because of the fact that not everyone uses ELF binaries, but is there some sort of linker hack that would let this work?
Alternatively, because all of the init code is compiled into one object, then linked with objects from other parts of the kernel, which I'm *assuming* means they are contiguously grouped, perhaps there is some way of detecting the upper and lower limits of that object in the section?
Thanks!
BTW, this is using GNU CC/Binutils and a higher half kernel design.