Skip to content

Commit be8b31d

Browse files
committed
Use new section for dynamic arrays
Use a custom linker section to hold dynamic arrays such as the usermod list. This provides an extensible solution for wider use in the future (such as FX or Bus drivers), as well as IDF v5 compatibility.
1 parent ae37f42 commit be8b31d

File tree

7 files changed

+28
-4
lines changed

7 files changed

+28
-4
lines changed

pio-scripts/dynarray.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Add a section to the linker script to store our dynamic arrays
2+
# This is implemented as a pio post-script to ensure that our extra linker
3+
# script fragments are processed last, after the base platform scripts have
4+
# been loaded and all sections defined.
5+
Import("env")
6+
7+
if env.get("PIOPLATFORM") == "espressif8266":
8+
# Use a shim on this platform so we can share the same output blocks
9+
# names as used by later platforms (ESP32)
10+
env.Append(LINKFLAGS=["-Ttools/esp8266_rodata.ld"])
11+
12+
env.Append(LINKFLAGS=["-Ttools/dynarray.ld"])

pio-scripts/validate_modules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def check_map_file_objects(map_file: list[str], dirs: Iterable[str]) -> set[str]
4141
def count_usermod_objects(map_file: list[str]) -> int:
4242
""" Returns the number of usermod objects in the usermod list """
4343
# Count the number of entries in the usermods table section
44-
return len([x for x in map_file if ".dtors.tbl.usermods.1" in x])
44+
return len([x for x in map_file if ".dynarray.usermods.1" in x])
4545

4646

4747
def validate_map_file(source, target, env):

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ extra_scripts =
133133
pre:pio-scripts/set_metadata.py
134134
post:pio-scripts/output_bins.py
135135
post:pio-scripts/strip-floats.py
136+
post:pio-scripts/dynarray.py
136137
pre:pio-scripts/user_config_copy.py
137138
pre:pio-scripts/load_usermods.py
138139
pre:pio-scripts/build_ui.py

tools/dynarray.ld

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* Linker script fragment to add dynamic array section to binary */
2+
SECTIONS
3+
{
4+
.dynarray :
5+
{
6+
. = ALIGN(4);
7+
KEEP(*(SORT_BY_INIT_PRIORITY(.dynarray.*)))
8+
} > default_rodata_seg
9+
}

tools/esp8266_rodata.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* Linker script fragment to shim ESP8266 section name to newer ESP32 standards */
2+
REGION_ALIAS("default_rodata_seg", iram1_0_seg)

wled00/fcn_declare.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ namespace UsermodManager {
365365
};
366366

367367
// Register usermods by building a static list via a linker section
368-
#define REGISTER_USERMOD(x) Usermod* const um_##x __attribute__((__section__(".dtors.tbl.usermods.1"), used)) = &x
368+
#define REGISTER_USERMOD(x) Usermod* const um_##x __attribute__((__section__(".dynarray.usermods.1"), used)) = &x
369369

370370
//usermod.cpp
371371
void userSetup();

wled00/um_manager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
// We stick them in the '.dtors' segment because it's always included by the linker scripts
1111
// even though it never gets called. Who calls exit() in an embedded program anyways?
1212
// If someone ever does, though, it'll explode as these aren't function pointers.
13-
static Usermod * const _usermod_table_begin[0] __attribute__((__section__(".dtors.tbl.usermods.0"), unused)) = {};
14-
static Usermod * const _usermod_table_end[0] __attribute__((__section__(".dtors.tbl.usermods.99"), unused)) = {};
13+
static Usermod * const _usermod_table_begin[0] __attribute__((__section__(".dynarray.usermods.0"), unused)) = {};
14+
static Usermod * const _usermod_table_end[0] __attribute__((__section__(".dynarray.usermods.99"), unused)) = {};
1515

1616
static size_t getCount() {
1717
return &_usermod_table_end[0] - &_usermod_table_begin[0];

0 commit comments

Comments
 (0)