Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to exclude a function/symbol from a particular section in linker script?

I have used EXCLUDE_FILE to explicitly omit placing certain sections of certain object files in the master object file that I want to generate. I was wondering if there is a way to omit out just a particular symbol rather than an entire section.

Example:

Say I have a library a.lib which consists of 1.o, 2.o and 3.o with .text and .data sections. .text section of 1.o contains func1, func2 and func3.

using EXCLUDE_FILE, I can only omit out the entire .text or .data section from 1.o. I want to be able to omit out only func1 and place func2 and func3. Is this possible?

like image 415
whyme Avatar asked Oct 27 '25 07:10

whyme


1 Answers

If you use GCC, you can put your function into a seperate section. And move or omit the section with a linker script.

int f3(void) __attribute__((section(".excl")));

int f3(void) {

    ...
}

These tell GCC to compile f3 into .excl section. Then with you linker script you can place it somewhere else.

SECTIONS
{
    .text : 
    {
        *(.text)
    }
    ....
    .excl : 
    {
        *(.excl)
    }
}
like image 104
Tutul Avatar answered Oct 29 '25 06:10

Tutul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!