Search code examples
cgccdebug-symbolscoocox

How to share functions symbols and addresses between projects in C?


I have two distinct projects which are running on the same target. I want my second project to use few functions written in the first project at specific addresses.

To do that I thought I could use the symbol table from the first project in the second but it doesn't work. (I use arm-none-eabi toolchain and -nm on .elf file to generate symbols table).

I know that is possible but how can I do that ?


Solution

  • Well, the brute-force approach will very likely work:

    int (*far_function)(int a, int b, int c) = (int(*)(int, int, int)) 0xfeedf00d;
    
    far_function(1, 2, 3);
    

    In other words, just make a function pointer and initialize it using the known address.

    If the address isn't well-known (which it won't be if the other application is re-built and you haven't taken steps to "lock" the target function to a particular address), I would instead add meta-data at some fixed address, that contains the pointer. The other application would embed this data, thereby "exporting" the location of the interesting function.