This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Position Independent Code - Linker Error

Hello there

I'm trying to compile and link position independent code using the --apcs=/ropi compile option (C/C++: Read-Only Position Independent). Since I'm using --scatter I can't make use of the linker option "Make RO Sections Position Independent. Instead I mark the RO execution region in my scatter file with the PI option (as mentioned in this post: www.keil.com/.../).

It compiles just fine, but I get the L6248E Linker Error mainly because of the startup file. I understand that the assembler can't generate position independent code. I tried to write the startup code in C so that the compiler takes care of the position independency, unfortunately without success.

It seems like the DCD directive is causing the linker error. Does anyone have a suggestion or solution to my problem? Any help is appreciated.

Im using a STM32F100 Controller with Keil uVision 4.5 Standard Version (Armcc, ArmLink V4.1.0.894)

Here is my scatter file:

LR_IROM1 0x08000000 0x00010000  {    ; load region size_region
  ER_IROM1 0x08000000 PI 0x00010000  {  ; load address = execution address
   *.o (RESET, +First)
   *(InRoot$$Sections)
   .ANY (+RO)
  }
  RW_IRAM1 0x20000000 0x00002000  {  ; RW data
   .ANY (+RW +ZI)
  }
}

and my Startup File (vector table):

; Vector Table Mapped to Address 0 at Reset
                AREA    RESET, DATA, READONLY
                EXPORT  __Vectors
                EXPORT  __Vectors_End
                EXPORT  __Vectors_Size

__Vectors       DCD     __initial_sp                    ; Top of Stack
                DCD     Reset_Handler                   ; Reset Handler
                DCD     NMI_Handler                     ; NMI Handler
                DCD     HardFault_Handler               ; Hard Fault Handler
                DCD     MemManage_Handler               ; MPU Fault Handler
                DCD     BusFault_Handler                ; Bus Fault Handler
                DCD     UsageFault_Handler              ; Usage Fault Handler
                DCD     0                               ; Reserved
                DCD     0                               ; Reserved
                DCD     0                               ; Reserved
                DCD     0                               ; Reserved
                DCD     SVC_Handler                     ; SVCall Handler
                DCD     DebugMon_Handler                ; Debug Monitor Handler
                DCD     0                               ; Reserved
                DCD     PendSV_Handler                  ; PendSV Handler
                DCD     SysTick_Handler                 ; SysTick Handler
...
__Vectors_End

__Vectors_Size  EQU  __Vectors_End - __Vectors

                AREA    |.text|, CODE, READONLY

; Reset handler
Reset_Handler    PROC
                 EXPORT  Reset_Handler             [WEAK]
     IMPORT  __main
     IMPORT  SystemInit
                  LDR     R0, =SystemInit
                 BLX     R0
                 LDR     R0, =__main
                 BX      R0
                 ENDP

; Dummy Exception Handlers (infinite loops which can be modified)

NMI_Handler     PROC
                EXPORT  NMI_Handler                      [WEAK]
                B       .
                ENDP
HardFault_Handler\ 
                PROC
                EXPORT  HardFault_Handler                [WEAK]
                B       .
                ENDP
...

Thank you

Roland