From 8f0c4ae3f94ccdb87fb46fdb5c3dffe3e7cedaaa Mon Sep 17 00:00:00 2001 From: Bill Nguyen Date: Mon, 28 Sep 2026 13:53:50 +1000 Subject: [PATCH] libmicrokit,loader,monitor: omit stack protector Some distro-packaged compilers enable Stack Smashing Protection (SSP) by default, even with -ffreestanding. If you build Microkit with such a compiler for the same architecture as your host (i.e. using the native rather than a cross toolchain), linking fails with: ``` ld.lld: error: undefined symbol: __stack_chk_fail >>> referenced by util.c:0 (... /monitor/src/util.c:0) ... ``` This is fixed this by building libmicrokit, loader and monitor with -fno-stack-protector. Signed-off-by: Bill Nguyen --- libmicrokit/Makefile | 1 + loader/Makefile | 2 +- monitor/Makefile | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libmicrokit/Makefile b/libmicrokit/Makefile index 334ecf504..b3134f1a1 100644 --- a/libmicrokit/Makefile +++ b/libmicrokit/Makefile @@ -50,6 +50,7 @@ endif CFLAGS := -std=gnu11 \ -g -O3 -nostdlib \ -ffreestanding \ + -fno-stack-protector \ -Wall $(CFLAGS_TOOLCHAIN) \ -Wno-unused-function -Werror \ -Iinclude -I$(SEL4_SDK)/include \ diff --git a/loader/Makefile b/loader/Makefile index c08c18bd9..4a2979131 100644 --- a/loader/Makefile +++ b/loader/Makefile @@ -47,7 +47,7 @@ else ifeq ($(ARCH),riscv64) ARCH_DIR := riscv endif -CFLAGS := -std=gnu11 -g -O3 -nostdlib -ffreestanding \ +CFLAGS := -std=gnu11 -g -O3 -nostdlib -ffreestanding -fno-stack-protector \ -MP -MD $(CFLAGS_ARCH) -DBOARD_$(BOARD) -I$(SEL4_SDK)/include \ -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations \ -Wundef -Wno-nonnull -Wnested-externs diff --git a/monitor/Makefile b/monitor/Makefile index 1223795a1..5e51d17c0 100644 --- a/monitor/Makefile +++ b/monitor/Makefile @@ -53,7 +53,7 @@ else $(error ARCH is unsupported) endif -CFLAGS := -std=gnu11 -g -O3 -nostdlib -ffreestanding -Wall $(CFLAGS_TOOLCHAIN) -Werror -I$(SEL4_SDK)/include $(CFLAGS_ARCH) -DARCH_$(ARCH) +CFLAGS := -std=gnu11 -g -O3 -nostdlib -ffreestanding -fno-stack-protector -Wall $(CFLAGS_TOOLCHAIN) -Werror -I$(SEL4_SDK)/include $(CFLAGS_ARCH) -DARCH_$(ARCH) PROGS := monitor.elf OBJECTS := main.o crt0.o util.o