Relocating code on cortex m3 but keeping data constant

Dan Baldor danbaldor@gmail.com
Fri Feb 25 01:56:00 GMT 2011


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.

Any help you can provide would be greatly appreciated.



More information about the Gcc-help mailing list