Page 1 of 1

Section start and stop markers in Linker Fragments

Posted: Mon Nov 11, 2019 10:19 pm
by JadElClemens
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

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.
. 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?

Re: Section start and stop markers in Linker Fragments

Posted: Thu Apr 01, 2021 5:04 am
by wm-kaertech
did you ever found a solution for this? I'm facing the same issue

Re: Section start and stop markers in Linker Fragments

Posted: Sun Apr 11, 2021 9:11 am
by franzhoepfinger

Re: Section start and stop markers in Linker Fragments

Posted: Mon Apr 12, 2021 12:09 am
by ESP_Angus
Yes, this feature is new in ESP-IDF v4.4 but is designed for this purpose.