How to access variable define in linker script in c?

前端 未结 2 782
忘掉有多难
忘掉有多难 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:27

    This is more in reference to your follow-up question beneath Ryan's post, however it may help answer your original question as well.

    "Variables" defined in linker scripts aren't treated the same as those defined in C; they're more symbols than anything. When accessing these symbols defined in your linker scripts, you must use the & operator.

    For example, if we had the following section in our linker script:

    .data :
    {
        _sdata = .;
        *(.data*);
        _edata = .;
    } > ram AT >rom
    

    We could get a pointer to the start of the .data section like so:

    uint8_t *data_ptr = &_sdata;
    

    For further reading, try the binutils docs, or this excellent primer on linker scripts

    Cheers

提交回复
热议问题