Make GCC initialize global variable using instructions instead of assembly directive such as .long or .quad

Arvind Sankar nivedita@alum.mit.edu
Mon Jan 20 22:54:00 GMT 2020


On Mon, Jan 20, 2020 at 05:33:07PM -0500, Arvind Sankar wrote:
> 
> If you're not going to be using a libc, your options would be to either
> avoid constructs that result in run-time relocations being needed (such
> as initializing global variables to the address of some
> function/variable), or add at least some minimal relocation processing
> in your startup code -- it might be possible to just extract the
> static-pie bits you need from musl without having to bring in the whole
> library, as these are pretty small, looks like less than 100 lines of
> actual code + a few include files to get definitions.

If you go the route of pulling the code out of musl, note that it only
handles {R_386,R_X86_64}_RELATIVE relocations. For normal code with
recent gcc/binutils, that should be enough, but you might want to check
that you don't have anything else appearing in your program.



More information about the Gcc-help mailing list