Chris
Chris

Reputation: 2896

Specify absolute address for symbol placement

I have a static library that I compiled, and when I create executables I want a certain function I created in the library to always be placed at a fixed absolute address.

Specifically, my static library is a set of x86 assembly routines, and I want one of the routines (called _start_exec) to always be located at a fixed virtual address when the ELF binary is loaded. I have tried looking at --defsym, although I don't think that was what I wanted. I don't want to mess with the starting point of the executable, I just want for a certain sequence of instructions to always be located at a fixed virtual address in all executables I link.

Upvotes: 1

Views: 329

Answers (2)

Michael F
Michael F

Reputation: 40830

You can script ld to do what you want with ABSOLUTE(expr) and ADDR(section). From the ld documentation:

    SECTIONS { ...
      .output1 :
        { 
        start_of_output_1 = ABSOLUTE(.);
        ...
        }
      .output :
        {
        symbol_1 = ADDR(.output1);
        symbol_2 = start_of_output_1;
        }
    ... }

You can modify the script above to suit your exact need.

Upvotes: 1

As I said in comments, you probably need to make an ld script. See the binutils documentation on linker scripts

Upvotes: 1

Related Questions