2163169_en-US

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

2163169_en-US

2163169_en-US

如何将.a静态库文件链接到固定地址

MPC5746R

S32 Design Studio for Power Architecture Version 2017.R1


我使用了一个.a静态库文件,现在我想把.a库文件内的函数链接到固定地址,如何实现?

以下方式失败了。


MEMORY
{

 m2_text : org = 0x01280000+0x10, len = 768K-0x30

}

SECTIONS
{

.lib_section : 
{
    libK12LM_SCR.a:*(.text*)
    libK12LM_SCR.a:*(.text.*) 
    libK12LM_SCR.a:*(.rodata) 
    libK12LM_SCR.a:*(.rodata.*) 
} > m2_text

}

Re: 如何将.a静态库文件链接到固定地址

Hello,

General recommended steps to link functions to fixed addresses:

1. Use a Custom Linker File (.ld):

Modify the default linker script to define specific memory sections and place functions at fixed addresses.

.my_fixed_section 0x10000000 :
{
KEEP(*(.my_fixed_func))
} > m_text

2. Tag Functions in Code:

Use GCC attributes to place functions in custom sections:

void __attribute__((section(".my_fixed_func"))) my_function(void) {
// Your code
}

3. Ensure the .a Library is Built with Section Attributes:

If you don’t control the source of the .a file, you may need to wrap or recompile the library with section attributes.

Alternatively, use objcopy to extract and reassign sections manually.

4. Update the Linker Command in Project Settings:

Go to Project Properties > C/C++ Build > Settings > Tool Settings > Cross Linker.

Add flags like:

-T your_custom_linker.ld

5. Verify with Map File:

After build, inspect the .map file to confirm that functions are placed at the intended addresses.

Best regards,

Peter


Tags (1)
No ratings
Version history
Last update:
‎11-21-2025 05:58 PM
Updated by: