Skip to content

Commit b63e528

Browse files
agattidpgeorge
authored andcommitted
examples/natmod/btree: Fix build on RV32 with Picolibc.
This commit fixes building the "btree" example natmod on RV32 when Picolibc is being used and uses thread-local storage for storing the errno variable. The fix is surprisingly simple: Picolibc allows overriding the function that will provide a pointer to the "errno" variable, and the btree natmod integration code already has all of this machinery set up as part of its library integration. Redirecting Picolibc to the already existing pointer provider function via a compile-time definition is enough to let the module compile and pass QEMU tests. This workaround will work on any Picolibc versions (Arm, RV32, Xtensa, etc.) even if TLS support was not enabled to begin with, and will effectively do nothing if the toolchain used will rely on Newlib to provide standard C library functions. Given that the btree module now builds and passes the relevant natmod tests, said module is now part of the QEMU port's natmod testing procedure, and CI now will build the btree module for RV32 as part to its checks. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
1 parent 5f55f8d commit b63e528

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

examples/natmod/btree/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ ifeq ($(ARCH),xtensa)
3636
MPY_EXTERN_SYM_FILE=$(MPY_DIR)/ports/esp8266/boards/eagle.rom.addr.v6.ld
3737
endif
3838

39+
# Use our own errno implementation if Picolibc is used
40+
CFLAGS += -D__PICOLIBC_ERRNO_FUNCTION=__errno
41+
3942
include $(MPY_DIR)/py/dynruntime.mk
4043

4144
# btree needs gnu99 defined

ports/qemu/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,11 @@ test_full: $(BUILD)/firmware.elf
191191
cd $(TOP)/tests && ./run-tests.py $(RUN_TESTS_FULL_ARGS) --via-mpy
192192
cd $(TOP)/tests && ./run-tests.py $(RUN_TESTS_FULL_ARGS) --via-mpy --emit native
193193

194-
# "btree" currently does not build for rv32imc (Picolibc TLS incompatibility).
195194
.PHONY: test_natmod
196195
test_natmod: $(BUILD)/firmware.elf
197196
$(eval DIRNAME=ports/$(notdir $(CURDIR)))
198197
cd $(TOP)/tests && \
199-
for natmod in deflate framebuf heapq random_basic re; do \
198+
for natmod in btree deflate framebuf heapq random_basic re; do \
200199
./run-natmodtests.py -p -d execpty:"$(QEMU_SYSTEM) $(QEMU_ARGS) -serial pty -kernel ../$(DIRNAME)/$<" extmod/$$natmod*.py; \
201200
done
202201

tools/ci.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ function ci_native_mpy_modules_build {
563563
else
564564
arch=$1
565565
fi
566-
for natmod in deflate features1 features3 features4 framebuf heapq random re
566+
for natmod in btree deflate features1 features3 features4 framebuf heapq random re
567567
do
568568
make -C examples/natmod/$natmod ARCH=$arch clean
569569
make -C examples/natmod/$natmod ARCH=$arch
@@ -576,12 +576,6 @@ function ci_native_mpy_modules_build {
576576
else
577577
make -C examples/natmod/features2 ARCH=$arch
578578
fi
579-
580-
# btree requires thread local storage support on rv32imc.
581-
if [ $arch != "rv32imc" ]; then
582-
make -C examples/natmod/btree ARCH=$arch clean
583-
make -C examples/natmod/btree ARCH=$arch
584-
fi
585579
}
586580

587581
function ci_native_mpy_modules_32bit_build {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy