Relocating code on cortex m3 but keeping data constant
Ian Lance Taylor
iant@google.com
Sun Feb 27 19:27:00 GMT 2011
Dan Baldor <danbaldor@gmail.com> writes:
> I am working on a project using a arm cortex-m3 processor that needs
> relocatable code. The relocation is such that the .text and .data
> sections will have a different offset when loaded than what they were
> compiled with (the .text section can be loaded to different sections
> of internal flash while the .data section will always reside in the
> same location of sram). If I keep the .got with .text section I can
> get the global variables to have the correct addresses but my static
> local variables have the wrong address (they are offset from where
> they should be the amount that the .text segment shifted). I think the
> static locals are referenced from the start of the .GOT section which
> is why I am having problems. I am compiling all my c code with –fpic
> and linking with –fpic and –pie. Is there any way to either force the
> static locals (and maybe global variables) to absolute addresses or to
> relocate the .GOT section dynamically? I tried doing by placing the
> GOT section with the data but when I do so code does not locate the
> GOT section correctly. I thought that perhaps I should be using
> |-msingle-pic-base and -mpic-register=|/reg /but so far all attempts
> to use this did not work at all.
If the runtime address is fixed, this is normally done using a linker
script using the AT() modifier; see
http://sourceware.org/binutils/docs-2.21/ld/Output-Section-LMA.html .
If the runtime address varies, then I don't know that there is a way to
handle this. Using -fpic/-pie implies the existence of a dynamic
linker.
Ian
More information about the Gcc-help
mailing list