gcc linker description file force symbol to be at specific address

后端 未结 2 576
一个人的身影
一个人的身影 2021-01-04 20:57

I have a very specific question about the gcc linker description file. I have an embedded project and have to make sure, that the main symbol or the address of the main symb

2条回答
  •  星月不相逢
    2021-01-04 21:27

    If you already have a linker control file (I assume you are using a gcc toolchain), then you just need to put your object file containing your main() function into the very first section (and leave it out of the Makefile).

    Here is an example:

    MEMORY
    {
       rom (RX) : ORIGIN = START_ADDRESS, LENGTH = 0x0010000
    }
    SECTIONS
    {
        .text :
        {
            main.o (.text) /* this is the program entry point */
            *(.text)
        }
        .data :
        {
            . = ALIGN(4);
            *(.data)
        }
     }
    

    (this is simplified a bit, but I think you get the point). The .text section begins at START_ADDRESS and as long as you make sure your main.o is located there (and main() is the first function in it), you are set.

提交回复
热议问题