Position independent code on iMX.RT

cancel
Showing results for 
Search instead for 
Did you mean: 

Position independent code on iMX.RT

786 Views
noahwang
Contributor III

I'm using the iMX.RT1052 and I want to generate position independent code (PIC) since I want to be able to execute from any ROM location (this is so I can store and run multiple versions of firmware from the flash). However, I've been having trouble generating PIC on 'MCUXpresso v10.2.0 [Build 759] [2018-05-15]'  using 'arm-none-eabi-gcc version 7.2.1 20170904' that came with the IDE. I have all options for compiling/linking PIC defined: 

   - '-fPIC'
   - '-mno-pic-data-is-text-relative'
   - '-msingle-pic-base'
   - '-mpic-register=r9'

However when I look at the assembly generated by this, all function calls are relative branches (bl 0x60XXXXXX, etc) which is obviously dependent on position in ROM. I know that these options are doing something because now all my global variables in RAM are accessed via the global offset table (GOT) but this is not my goal. Having only the RAM be position independent is pointless as the same RAM banks are being used regardless of which ROM address the code is running from.

Does anyone have any experience with generating PIC code for the iMX.RT or is this simply an impossibility at the current time?

0 Kudos
1 Reply

631 Views
noahwang
Contributor III

It turned out to be my mistake, I got confused because the disassembly in MCUXpresso showed an absolute branch but checking the actual binary I saw that it was a relative one. I guess eclipse converts it to an an absolute address for ease of reading, probably so you don't have to manually convert an offset.