Section start and stop markers in Linker Fragments

JadElClemens
Posts: 10
Joined: Mon Oct 28, 2019 9:04 pm

Section start and stop markers in Linker Fragments

Postby JadElClemens » 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

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?

wm-kaertech
Posts: 1
Joined: Thu Apr 01, 2021 5:03 am

Re: Section start and stop markers in Linker Fragments

Postby wm-kaertech » Thu Apr 01, 2021 5:04 am

did you ever found a solution for this? I'm facing the same issue

franzhoepfinger
Posts: 21
Joined: Wed Mar 04, 2020 7:14 pm

Re: Section start and stop markers in Linker Fragments

Postby franzhoepfinger » Sun Apr 11, 2021 9:11 am


ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Section start and stop markers in Linker Fragments

Postby ESP_Angus » Mon Apr 12, 2021 12:09 am

Yes, this feature is new in ESP-IDF v4.4 but is designed for this purpose.

Who is online

Users browsing this forum: No registered users and 92 guests