How to change function linking order in S32DS?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to change function linking order in S32DS?

2,270 Views
zhijunyao
Contributor I

I'am working with MPC5744P, and I'd like to understand how to change the function linking order with S32DS. Creating a new project, after building, S32DS assign function address by default, from low to high address, main()->dummy()->SetIVPR->InitINTC->enableIrg->xcptn_xmpl, as bellow.

 .text.main     0x01002bc8       0x28 ./src/main.o
                0x01002bc8                main
 .text.dummy    0x01002bf0        0xc ./src/intc_SW_mode_isr_vectors_MPC5744P.o
                0x01002bf0                dummy
 .text.SetIVPR  0x01002bfc       0x1a ./src/MPC57xx__Interrupt_Init.o
                0x01002bfc                SetIVPR
 .text.InitINTC
                0x01002c16       0x3c ./src/MPC57xx__Interrupt_Init.o
                0x01002c16                InitINTC
 .text.enableIrq
                0x01002c52       0x24 ./src/MPC57xx__Interrupt_Init.o
                0x01002c52                enableIrq
 .text.xcptn_xmpl
                0x01002c76       0x34 ./src/MPC57xx__Interrupt_Init.o
                0x01002c76                xcptn_xmpl

 

Now, I need to change linking order, moving main() to the bottom, dummy()->SetIVPR->InitINTC->enableIrg->xcptn_xmpl->main(). How can I set this in S32DS to control linking order?

Labels (2)
2 Replies

1,394 Views
stanish
NXP Employee
NXP Employee

Hi,

another approach and is to control the link order of specific functions directly in the linker file. See the snippet below:

    .text :

    {

      *(.init)

      *(.text.startup)

      *(.text)

      *(.text.dummy)     

      *(.text.SetIVPR)

      *(.text.InitINTC)

      *(.text.enableIrq)

      *(.text.xcptn_xmpl)

      *(.text.main)

      *(.text.*)     

      . = ALIGN(16);

    } > m_text

This solution will work when ‘-ffunction-sections’ compiler option is used (set by default in a new project).

This option causes each function is associated with its own section.

This solution does not in fact change linker order. It will change only functions relative location in memory but this might the the main reason for changing the linking order.

Stan

1,394 Views
stanish
NXP Employee
NXP Employee

Hello,

Currently it's not possible to change the link order in IDE (as opposed to e.g. CodeWarrior).

There is a related feature request already logged in our database so this feature might be implemented in a future release.

The only workaround I can think of is to disable makefile generation and adjust the link order manually. See below the workaround instructions:

1) Build the project first - makefiles and .args files are created automatically in the output directory:

pastedImage_2.png

2) In the project properties turn off Makefile automatic generation:

pastedImage_1.png

3) Change the link order directly in .args file (e.g Startup.o has been moved at the end of the object files):

"./src/main.o"
"./src/intc_sw_handlers.o"
"./src/intc_SW_mode_isr_vectors_MPC5744P.o"
"./src/flashrchw.o"
"./src/Vector.o"
"./src/MPC57xx__Interrupt_Init.o"
"./Project_Settings/Startup_Code/startup.o" 
-T
"C:/S32DS_Workspaces/S32DS_PA_1.1_clean/MPC5744P_Interrupt_debug/Project_Settings/Linker_Files/57xx_flash.ld"
-T
"C:/S32DS_Workspaces/S32DS_PA_1.1_clean/MPC5744P_Interrupt_debug/Project_Settings/Linker_Files/libs.ld"
-Wl,-Map,"MPC5744P_Interrupt_debug.map"
-Xlinker
--gc-sections
-mcpu=e200z4
-specs=ewl_c9x.specs
-mhard-float
--sysroot="C:/Freescale/S32_Power_v1.1/S32DS/e200_ewl2"

Note:

If you need to add a source file into your project you should turn on the makefile generation again and rebuild to update your makefile/.args files.

Hope it helps.

Stan