Section start and stop markers in Linker Fragments
Posted: Mon Nov 11, 2019 10:19 pm
Hey all,
My project uses some linker magic for a specific class of variables in the code in order to group them all together and iterate over them for initialization. The developer before me implemented this by inserting start and stop markers as linker symbols into the project linker script (previously esp32.common.ld in v3.2, now esp32.project.ld.in in v4.0-beta2) provided as part of ESP-IDF.
It looks something like this. In this example, the section name is "SpecialVars" and there is a macro in my code that adds
--------
This works fine, but I'd rather move to using a local linker fragment so I can use a clean copy of ESP-IDF.
I've tried using the following linker fragment "linker.lf" and added it to LDFRAGMENTS in idf_component_register within the component's CMakeLists.txt:
--------
But this leaves two problems:
One, there doesn't seem to be a way to define/provide symbols (start/stop markers) like above - if I add anything like that to the fragment, the build system fails to parse it.
Two, the first example where the I modified the ESP-IDF linker script (esp32.project.ld.in) compiles fine, but the second (using a linker fragment) just bootloops with the message. I should note that I get this same message if I don't modify any of the linker files at all.
P.S. the error message confuses me. Shouldn't SpecialVars be put into dram and not drom per my mapping? Does this mean my linker fragment isn't even being read?
My project uses some linker magic for a specific class of variables in the code in order to group them all together and iterate over them for initialization. The developer before me implemented this by inserting start and stop markers as linker symbols into the project linker script (previously esp32.common.ld in v3.2, now esp32.project.ld.in in v4.0-beta2) provided as part of ESP-IDF.
It looks something like this. In this example, the section name is "SpecialVars" and there is a macro in my code that adds
Code: Select all
__attribute__((section("SpecialVars")))
Code: Select all
SECTIONS
{
[...]
.dram0.data :
{
[...]
. = ALIGN(8);
PROVIDE(__start_SpecialVars = .);
*(SpecialVars)
PROVIDE(__stop_SpecialVars = .);
[...]
} > dram0_0_seg
[...]
}
This works fine, but I'd rather move to using a local linker fragment so I can use a clean copy of ESP-IDF.
I've tried using the following linker fragment "linker.lf" and added it to LDFRAGMENTS in idf_component_register within the component's CMakeLists.txt:
Code: Select all
[sections:SpecialVars]
entries:
.SpecialVars+
[scheme:SpecialVars]
entries:
SpecialVars -> dram0_data
[mapping:SpecialVars]
object: main.o
entries:
* (SpecialVars)
But this leaves two problems:
One, there doesn't seem to be a way to define/provide symbols (start/stop markers) like above - if I add anything like that to the fragment, the build system fails to parse it.
Two, the first example where the I modified the ESP-IDF linker script (esp32.project.ld.in) compiles fine, but the second (using a linker fragment) just bootloops with the message
Code: Select all
boot: Image contains multiple DROM segments. Only the last one will be mapped.
P.S. the error message confuses me. Shouldn't SpecialVars be put into dram and not drom per my mapping? Does this mean my linker fragment isn't even being read?