How to access variable define in linker script in c?

前端 未结 2 784
忘掉有多难
忘掉有多难 2021-01-13 01:54

In the linker script, I defined PROVIDE(__KERNEL_BEGIN__ = .);.

The address can be accessed from:

extern uint32_t __KERNEL_BEGIN__[];
         


        
2条回答
  •  被撕碎了的回忆
    2021-01-13 02:34

    You need to take the address of the extern variable. It is not completely intuitive but is explained in the manual.

    In theory, the extern can be any primitive data type. For reasons which I am unaware, the convention is to use a char:

    extern char __KERNEL_BEGIN__;
    

    Then to get the address exported from the linker script, take the address of __KERNEL_BEGIN__:

    printf("Address: %08x\n", &__KERNEL_BEGIN__);
    

    You can read about this in the manual for ld.

提交回复
热议问题