Linker script: insert absolute address of the function to the generated code

后端 未结 2 572
遥遥无期
遥遥无期 2021-01-13 06:15

I have a question related to gcc\'s linker.

I\'m working with embedded stuff (PIC32), but PIC32\'s compiler and linker are based on gcc, so, main things should be co

相关标签:
2条回答
  • 2021-01-13 06:52

    The way I found around this was to use function pointers, i.e.

    void (*formatted_write)( int a, char * b, struct mystruct c );
    

    then, in the code somewhere at boot set the address of this function, i.e.

    formatted_write = 0xa0000;
    

    you can then call your function using the normal convention.

    Additionally, you can use the -Wl,--just-symbols=symbols.txt flag when compiling. You can set the address of your symbols as follows:

    formatted_write = 0xa0000;
    
    0 讨论(0)
  • 2021-01-13 06:56

    For the case that someone has the same problem (like me some hours ago), there is a still better solution:

    Let "bootloader.out" be the bootloader-binary. Then we can generate with

    nm -g bootloader.out | grep '^[0-9,a-e]\{8\} T' | awk '{printf "PROVIDE(%s = 0x%s);\n",$3,$1}' > bootloader.inc
    

    a file that we can include in the linker script of the application with

    INCLUDE bootloader.inc
    

    The linker knows now the addresses of all bootloader-functions and we can link against it without to have the actual function code in the application. All what we need there is a declaration for every bootloader-function which we want to execute.

    0 讨论(0)
提交回复
热议问题