Skip to content

Commit 47a2981

Browse files
committed
build: Add support for checking an llext build at compile time
This commit adds compile-time checking of the sketch to verify that all symbols not directly resolved in the sketch are defined in the Zephyr core. This reuses the 'linked' logic, but defines the llext-specific symbols only. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
1 parent 0daaefe commit 47a2981

File tree

9 files changed

+35
-20
lines changed

9 files changed

+35
-20
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ llext-edk/
66
cflags.txt
77
cxxflags.txt
88
includes.txt
9-
provides.ld
9+
syms-llext.ld
10+
syms-linked.ld

boards.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ portentac33.menu.mode.linked=linked
450450
portentac33.menu.mode.linked.build.extra_ldflags=-lc -lm -lgcc -L{build.variant.path} -Wl,--wrap=random -Wl,--wrap=calloc -Wl,--wrap=free -Wl,--wrap=malloc -Wl,--wrap=realloc
451451
portentac33.menu.mode.linked.build.llext_link_flags=
452452
portentac33.menu.mode.linked.build.suffix=_linked
453-
portentac33.menu.mode.linked.build.ldscript={runtime.platform.path}/variants/_linked/linker_script.ld
453+
portentac33.menu.mode.linked.build.link_mode=linked
454454
portentac33.menu.mode.linked.upload.extension=bin-zsk.bin
455455
portentac33.menu.mode.linked.postbuild_mode=-prelinked
456456

extra/build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ done
9191

9292
# Generate the provides.ld file for linked builds
9393
echo "Generating exported symbol scripts"
94+
extra/gen_provides.py "${BUILD_DIR}/zephyr/zephyr.elf" -L > ${VARIANT_DIR}/syms-llext.ld
9495
extra/gen_provides.py "${BUILD_DIR}/zephyr/zephyr.elf" -LF \
9596
"+kheap_llext_heap" \
9697
"+kheap__system_heap" \
@@ -100,6 +101,6 @@ extra/gen_provides.py "${BUILD_DIR}/zephyr/zephyr.elf" -LF \
100101
"free=__wrap_free" \
101102
"realloc=__wrap_realloc" \
102103
"calloc=__wrap_calloc" \
103-
"random=__wrap_random" > ${VARIANT_DIR}/provides.ld
104+
"random=__wrap_random" > ${VARIANT_DIR}/syms-linked.ld
104105

105106
cmake -P extra/gen_arduino_files.cmake $variant

extra/package_core.inc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ README.md
1313
doc/
1414
cores/
1515
libraries/
16-
variants/_llext/
17-
variants/_linked/
16+
variants/_ldscripts/

platform.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,17 @@ compiler.zephyr.extra_ldflags=-lstdc++ -lsupc++
4949
# this can be overriden in boards.txt
5050
build.extra_flags=
5151
build.extra_ldflags=
52+
build.link_mode=llext
5253
compiler.zephyr=
5354

54-
build.ldscript={runtime.platform.path}/variants/_llext/linker_script.ld
55+
build.ldscript.path={runtime.platform.path}/variants/_ldscripts
56+
build.link_command="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} {build.extra_flags} {build.extra_ldflags} {compiler.zephyr.common_ldflags} --specs=picolibc.specs --specs=nosys.specs {compiler.ldflags} {object_files} -Wl,--start-group "{build.path}/{archive_file}" {compiler.zephyr} {compiler.zephyr.extra_ldflags} {compiler.libraries.ldflags} -Wl,--end-group
57+
build.link_command.check-llext={build.link_command}
58+
build.link_args.check-llext="-T{build.variant.path}/syms-llext.ld" "-T{build.ldscript.path}/memory-check.ld" "-T{build.ldscript.path}/build-linked.ld" -o /dev/null
59+
build.link_args.build-llext="-T{build.ldscript.path}/build-llext.ld"
60+
build.link_args.build-linked="-T{build.variant.path}/syms-linked.ld" "-T{build.ldscript.path}/memory-linked.ld" "-T{build.ldscript.path}/build-linked.ld"
61+
build.link_args.build-common="-Wl,-Map,{build.path}/{build.project_name}.map" -o "{build.path}/{build.project_name}_debug.elf"
62+
5563
build.llext_link_flags=-r -e main
5664
build.extra_extra_ldflags=
5765
build.suffix=
@@ -99,7 +107,9 @@ recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DARDUIN
99107
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
100108

101109
## Combine gc-sections, archives, and objects
102-
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} {build.extra_flags} {build.extra_ldflags} {compiler.zephyr.common_ldflags} "-T{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" --specs=picolibc.specs --specs=nosys.specs {compiler.ldflags} -o "{build.path}/{build.project_name}_debug.elf" {object_files} -Wl,--start-group "{build.path}/{archive_file}" {compiler.zephyr} {compiler.zephyr.extra_ldflags} {compiler.libraries.ldflags} -Wl,--end-group
110+
recipe.c.combine.1.pattern={build.link_command.check-{build.link_mode}} {build.link_args.check-{build.link_mode}}
111+
recipe.c.combine.2.pattern={build.link_command} {build.link_args.build-{build.link_mode}} {build.link_args.build-common}
112+
recipe.c.combine.pattern={recipe.c.combine.2.pattern}
103113
recipe.hooks.linking.postlink.1.pattern="{compiler.path}{build.crossprefix}strip" --strip-debug "{build.path}/{build.project_name}_debug.elf" -o "{build.path}/{build.project_name}.elf"
104114

105115
## Create eeprom

variants/_linked/linker_script.ld renamed to variants/_ldscripts/build-linked.ld

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
INCLUDE "provides.ld"
2-
3-
MEMORY
4-
{
5-
/* 16 below compensates for the zsk header that is added before the .bin */
6-
FLASH (rx) : ORIGIN = _sketch_start + 16, LENGTH = _sketch_max_size - 16
7-
RAM (rwx) : ORIGIN = kheap_llext_heap, LENGTH = kheap_llext_heap_size
8-
}
9-
10-
PROVIDE(__heap_start = kheap__system_heap);
11-
PROVIDE(__heap_end = kheap__system_heap + kheap__system_heap_size);
12-
131
ENTRY(entry_point)
142
SECTIONS {
15-
163
/DISCARD/ : {
174
*(.ARM.attributes)
185
*(.ARM.attributes.*)
File renamed without changes.

variants/_ldscripts/memory-check.ld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
MEMORY
2+
{
3+
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x10000000
4+
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000000
5+
}
6+
7+
PROVIDE(__heap_start = 0x40000000);
8+
PROVIDE(__heap_end = 0x50000000);

variants/_ldscripts/memory-linked.ld

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MEMORY
2+
{
3+
/* 16 below compensates for the zsk header that is added before the .bin */
4+
FLASH (rx) : ORIGIN = _sketch_start + 16, LENGTH = _sketch_max_size - 16
5+
RAM (rwx) : ORIGIN = kheap_llext_heap, LENGTH = kheap_llext_heap_size
6+
}
7+
8+
PROVIDE(__heap_start = kheap__system_heap);
9+
PROVIDE(__heap_end = kheap__system_heap + kheap__system_heap_size);

0 commit comments

Comments
 (0)