Skip to content

Commit

Permalink
[Core] Fix heap symbols and syscalls for picolibc
Browse files Browse the repository at this point in the history
picolibc internally uses __heap_start and __heap_end instead of the
defacto chibios linker script standard __heap_base__ and __heap_end__
therefore we introduce these symbols as an alias. Usually all memory
used within QMK is statically allocated, but some algorithms make usage
of malloc and friends.

Also the timeval struct is not defined by picolibc for syscalls, therefore it
is declared as stub.
  • Loading branch information
KarlK90 authored and zvecr committed Nov 20, 2021
1 parent 59914fe commit f4af6d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 9 additions & 6 deletions platforms/chibios/platform.mk
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ endif
#

# Use defined stack sizes of the main thread in linker scripts
LDSYMBOLS =--defsym=__process_stack_size__=$(USE_PROCESS_STACKSIZE),--defsym=__main_stack_size__=$(USE_EXCEPTIONS_STACKSIZE)
SHARED_LDSYMBOLS = -Wl,--defsym=__process_stack_size__=$(USE_PROCESS_STACKSIZE),--defsym=__main_stack_size__=$(USE_EXCEPTIONS_STACKSIZE)

# Shared Compiler flags for all toolchains
SHARED_CFLAGS = -fomit-frame-pointer \
Expand All @@ -327,7 +327,6 @@ SHARED_CFLAGS = -fomit-frame-pointer \

# Shared Linker flags for all toolchains
SHARED_LDFLAGS = -T $(LDSCRIPT) \
-Wl,$(LDSYMBOLS) \
-Wl,--gc-sections \
-nostartfiles

Expand All @@ -349,11 +348,15 @@ ifeq ($(strip $(MCU)), risc-v)
# Default to compiling with picolibc for RISC-V targets if available, which
# is available by default on distributions based on Debian 11+.
ifeq ($(shell $(TOOLCHAIN)gcc --specs=picolibc.specs -E - 2>/dev/null >/dev/null </dev/null ; echo $$?),0)
# Toolchain specific Compiler flags
# Note that we still link with our own linker script
# by providing it via the -T flag above.
# Toolchain specific Compiler flags Note that we still link with our own
# linker script by providing it via the -T flag in SHARED_LDFLAGS.
TOOLCHAIN_CFLAGS = --specs=picolibc.specs

# picolibc internally uses __heap_start and __heap_end instead of the
# defacto chibios linker script standard __heap_base__ and __heap_end__
# therefore we introduce these symbols as an alias.
TOOLCHAIN_LDSYMBOLS = -Wl,--defsym=__heap_start=__heap_base__,--defsym=__heap_end=__heap_end__

# Tell QMK that we are compiling with picolibc.
OPT_DEFS += -DUSE_PICOLIBC
endif
Expand Down Expand Up @@ -404,7 +407,7 @@ CFLAGS += $(SHARED_CFLAGS) $(TOOLCHAIN_CFLAGS)
CXXFLAGS += $(CFLAGS) $(SHARED_CXXFLAGS) $(TOOLCHAIN_CXXFLAGS) -fno-rtti

# Linker flags
LDFLAGS += $(SHARED_LDFLAGS) $(TOOLCHAIN_LDFLAGS) $(MCUFLAGS)
LDFLAGS += $(SHARED_LDFLAGS) $(SHARED_LDSYMBOLS) $(TOOLCHAIN_LDFLAGS) $(TOOLCHAIN_LDSYMBOLS) $(MCUFLAGS)

# Tell QMK that we are hosting it on ChibiOS.
OPT_DEFS += -DPROTOCOL_CHIBIOS
Expand Down
1 change: 1 addition & 0 deletions platforms/chibios/syscall-fallbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* the _reent struct has to be defined. */
#if defined(USE_PICOLIBC)
struct _reent;
struct timeval;
#endif

#pragma GCC diagnostic ignored "-Wmissing-prototypes"
Expand Down

0 comments on commit f4af6d3

Please sign in to comment.