How to link function at specific address

  • arpa

    How can I get the linker to locate a specific function to a specific address?

    • Maarten Brock
      Maarten Brock

      1. You could write it in assembler using an ABSolute area and a .org address.
      2. You could put the function in a separate source file and compile it with a named code segment (--codeseg MYCODE or #pragma codeseg MYCODE) and tell the linker where to put that segment with -Wl,bMYCODE=0xaaaa.
      3. You could use a trampoline/jumptable written in assembler and put that at the specific address.

      But the real question is: WHY do you want to put a function at a specific address? Do you want to share it between different programs? If so, have you thought about the variables (RAM) it uses?