Position Independent Executable for Cortex M3

Guest #2059990
I am working on building my application so it can be executed directly 
from flash (on a Stellaris/TI Cortex M3) anywhere within the flash.  Has 
anyone done this?  So far this is what I am trying:
Modified the YAGARTO scripts as follows:
For gcc-build:  Added: CFLAGS_FOR_TARGET="-fpie" 
CXXFLAGS_FOR_TARGET="-fpie"
For newlib-build: Added: CFLAGS="-fpie"

My bootloader (which is at a fixed location) modifies the vector table 
of the application so that all its vectors are pointing to where the 
code actually resides.  I also modified the startup code so that data 
section is updated from the correct location of flash.

The problem I am still having is that when my code executes it seems 
that all my data is now been changed to be relative the PC.  I want my 
code to position independent but I would like to keep the data at the 
same locations in the internal sram.   So far I am not linking with -pie 
option as when I do my code does not execute at all.  I suspect that I 
may need to link with -pie as it seems to add a .dynamic section (in my 
data section) to my map file which might be necessary.  I am not sure if 
I need to make modifications to the .dynamic section to have it point to 
the correct locations in flash in the startup code.

Reply

A question of your own? This thread is over 15 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.