Lets say I have,
#define SW_VERSION_ADDRESS 0x08005FE0
#define SW_REVISION "123"
const u32 sw_version_address = SW_VERSION_ADDRESS;
const char gv_SW_revision[18] __attribute__((section(".sw_version"))) = SW_REVISION;
and in my linker file
.sw_version sw_version_address :
{
*(.sw_version)
}
I think the problem is that I am not passing the sw_version_address from the c file to my linker correctly.
I have tried to replce the variable sw_version_address in my linker file with hardcoded address and then it works. However I dont want to hardcode it in the linker file.
Any suggestions?
Anton is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
7
You can’t use a variable as the value in your linker script.
There is no workaround.
To archive it you need to dynamically generate your .h
file and definitions for the linker script.
You can also as @Eugene Sh suggested preprocess the file with C definitions into the linker script:
“def.h”:
#define SW_VERSION_ADDRESS 0x08005FE0
“script.ld.in”:
#include "def.h"
.sw_version SW_VERSION_ADDRESS :
{
*(.sw_version)
}
And add the build step:
cpp -P script.ld.in -o script.ld