Skip to content

Commit d0a46b3

Browse files
committed
build system: use thread-safe stdio
This makes use of the new bug modeling to declare all platforms that can use newlib and have no reentrancy hooks as affected by the non-thread-safe stdio bug. (Which is every platform but ESP* and AVR, the former because the reentrancy hooks are provided, the latter because we do not and never will support newlib on them.) Building on that, the mpaland-printf package is used when newlib is used and the bug is present. This way we can rely on the stdio being thread-safe on evyer platform and not causing random crashes at run time.
1 parent 792057e commit d0a46b3

File tree

6 files changed

+19
-1
lines changed

6 files changed

+19
-1
lines changed

cpu/cortexm_common/Makefile.features

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
FEATURES_PROVIDED += arch_32bit
22
FEATURES_PROVIDED += arch_arm
3+
FEATURES_PROVIDED += bug_newlib_broken_stdio
34
FEATURES_PROVIDED += cortexm_svc
45
FEATURES_PROVIDED += cpp
56
FEATURES_PROVIDED += cpu_check_address
@@ -9,8 +10,8 @@ FEATURES_PROVIDED += libstdcpp
910
FEATURES_PROVIDED += newlib
1011
FEATURES_PROVIDED += periph_flashpage_aux
1112
FEATURES_PROVIDED += periph_pm
12-
FEATURES_PROVIDED += puf_sram
1313
FEATURES_PROVIDED += picolibc
14+
FEATURES_PROVIDED += puf_sram
1415
FEATURES_PROVIDED += ssp
1516

1617
# cortex-m33, cortex-m4f and cortex-m7 provide FPU support

cpu/msp430/Makefile.features

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ endif
1414

1515
FEATURES_PROVIDED += arch_16bit
1616
FEATURES_PROVIDED += arch_msp430
17+
FEATURES_PROVIDED += bug_newlib_broken_stdio
1718
FEATURES_PROVIDED += cpu_$(CPU_FAM)
1819
FEATURES_PROVIDED += dbgpin
1920
FEATURES_PROVIDED += newlib

cpu/riscv_common/Makefile.features

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ endif
44

55
FEATURES_PROVIDED += arch_32bit
66
FEATURES_PROVIDED += arch_riscv
7+
FEATURES_PROVIDED += bug_newlib_broken_stdio
78
FEATURES_PROVIDED += cpp
89
FEATURES_PROVIDED += libstdcpp
910
FEATURES_PROVIDED += newlib

features.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,3 +925,10 @@ groups:
925925
feature prefixed with "bug_" provided in a build always be used,
926926
regardless of build configuration.
927927
features:
928+
- name: bug_newlib_broken_stdio
929+
help: newlib's stdio is not inherently thread-safe, but depends on the
930+
reentrancy hooks to be provided for correct operation. When
931+
reentrancy is not enabled, using newlib's stdio is racy, causing
932+
random crashes at runtime. Use of this feature will cause an
933+
alternative stdio implementation to be used if (and only if) newlib
934+
is in used as standard c lib.

makefiles/features_existing.inc.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ FEATURES_EXISTING := \
4444
ble_phy_coded \
4545
board_bat_voltage \
4646
bootloader_stm32 \
47+
bug_newlib_broken_stdio \
4748
can_rx_mailbox \
4849
cortexm_fpu \
4950
cortexm_mpu \

sys/Makefile.dep

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ ifneq (,$(filter newlib,$(USEMODULE)))
237237
endif
238238
endif
239239
endif
240+
ifneq (,$(filter bug_newlib_broken_stdio,$(FEATURES_USED)))
241+
# work around broken newlib stdio by using alternative stdio implementation,
242+
# unless stdio_null is used, which is inherently thread-safe :)
243+
ifeq (,$(filter stdio_null,$(USEMODULE)))
244+
USEPKG += mpaland-printf
245+
endif
246+
endif
240247
endif
241248

242249
ifneq (,$(filter posix_select,$(USEMODULE)))

0 commit comments

Comments
 (0)