Forum: ARM programming with GCC/GNU tools Position Independent Executable for Cortex M3

von Dan (Guest)

Rate this post
0 useful
not useful
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" 
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.


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.