Skip to content

Commit b6a5c04

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 9b1f38c commit b6a5c04

File tree

7 files changed

+40
-20
lines changed

7 files changed

+40
-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-dynamic.ld
10+
syms-static.ld

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-dynamic.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-static.ld
104105

105106
cmake -P extra/gen_arduino_files.cmake $variant

platform.txt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# For more info:
44
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
55

6-
name=Arduino Zephyr Boards (llext)
6+
name=Arduino Zephyr Boards
77
version=9.9.9
88

99
# Compile variables
@@ -55,13 +55,20 @@ upload.extension=elf-zsk.bin
5555
build.ldscript.path={runtime.platform.path}/variants/_ldscripts
5656
build.link_command="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" "-L{build.variant.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.extra_ldflags} {compiler.libraries.ldflags} -Wl,--end-group {build.link_args.{build.link_mode}}
5757

58+
build.check_command-dynamic={build.link_command} {build.link_args.check-dynamic} -o "{build.path}/{build.project_name}_check.tmp"
59+
build.check_command-static=
60+
build.combine_command={build.link_command} {build.link_args.build-{build.link_mode}} {build.link_args.build-common}
61+
5862
# link_args.* are included by any link_command depending on the link_mode
5963
build.link_args.dynamic=-e main
60-
build.link_args.static=-lc -lm -lgcc -L{build.variant.path} -Wl,--wrap=random -Wl,--wrap=calloc -Wl,--wrap=free -Wl,--wrap=malloc -Wl,--wrap=realloc
64+
build.link_args.static=-lc -lm -lgcc -L{build.variant.path} -Wl,--wrap=random -Wl,--wrap=calloc -Wl,--wrap=free -Wl,--wrap=malloc -Wl,--wrap=realloc
65+
66+
# link_args.check-* are used to check the build. Only LLEXT needs these to emulate a static build (no -r!).
67+
build.link_args.check-dynamic="-T{build.variant.path}/syms-dynamic.ld" "-T{build.ldscript.path}/memory-check.ld" "-T{build.ldscript.path}/build-static.ld"
6168

6269
# link_args.build-* are used to create the final binary. -common are added to both static and dynamic.
63-
build.link_args.build-dynamic="-T{build.ldscript.path}/dynamic.ld" -r
64-
build.link_args.build-static="-T{build.variant.path}/provides.ld" "-T{build.ldscript.path}/static.ld"
70+
build.link_args.build-dynamic="-T{build.ldscript.path}/build-dynamic.ld" -r
71+
build.link_args.build-static="-T{build.variant.path}/syms-static.ld" "-T{build.ldscript.path}/memory-static.ld" "-T{build.ldscript.path}/build-static.ld"
6572
build.link_args.build-common="-Wl,-Map,{build.path}/{build.project_name}.map" -o "{build.path}/{build.project_name}_debug.elf"
6673

6774
# zsk_args are used to create the final binary with zephyr-sketch-tool
@@ -109,7 +116,9 @@ recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DARDUIN
109116
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
110117

111118
## Combine gc-sections, archives, and objects
112-
recipe.c.combine.pattern={build.link_command} {build.link_args.build-{build.link_mode}} {build.link_args.build-common}
119+
recipe.c.combine.1.pattern={build.check_command-{build.link_mode}}
120+
recipe.c.combine.2.pattern={build.combine_command}
121+
recipe.c.combine.pattern={build.combine_command}
113122
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"
114123

115124
## Create eeprom
File renamed without changes.

variants/_ldscripts/static.ld renamed to variants/_ldscripts/build-static.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.*)

variants/_ldscripts/memory-check.ld

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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);
9+
PROVIDE(kheap__system_heap = 0x40000000);
10+
PROVIDE(kheap__system_heap_size = 0x10000000);
11+
12+
PROVIDE(kheap_llext_heap = 0x60000000);
13+
PROVIDE(kheap_llext_heap_size = 0x10000000);

variants/_ldscripts/memory-static.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)