[boot-wrapper PATCH v2 3/9] Makefile: Tell compiler to generate bare-metal code

Andre Przywara andre.przywara at arm.com
Wed Dec 22 10:16:01 PST 2021


Our GCC invocation does not provide many parameters, which lets the
toolchain fill in its own default setup.
In case of a native build or when using a full-featured cross-compiler,
this probably means Linux userland, which is not what we want for a
bare-metal application like boot-wrapper.

Tell the compiler to forget about those standard settings, and only use
what we explicitly ask for. In particular that means to not use toolchain
provided libraries and headers, since they might pull in more code than
we want, and might not run well in the boot-wrapper environment.

This also enables optimisation, since it produces much better code and
tends to avoid problems due to missing inlining, for instance.

Signed-off-by: Andre Przywara <andre.przywara at arm.com>
---
 Makefile.am | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index 3e970a3..d9ad6d1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -124,9 +124,14 @@ CHOSEN_NODE	:= chosen {						\
 
 CPPFLAGS	+= $(INITRD_FLAGS)
 CFLAGS		+= -I$(top_srcdir)/include/ -I$(top_srcdir)/$(ARCH_SRC)/include/
-CFLAGS		+= -Wall -fomit-frame-pointer
+CFLAGS		+= -Wall -Wstrict-prototypes -fomit-frame-pointer
+CFLAGS		+= -ffreestanding -nostdinc -nostdlib
+CFLAGS		+= -fno-common -fno-strict-aliasing -fno-stack-protector
+CFLAGS		+= -fno-toplevel-reorder
+CFLAGS		+= -fno-unwind-tables -fno-asynchronous-unwind-tables
 CFLAGS		+= -ffunction-sections -fdata-sections
 CFLAGS		+= -fno-pic -fno-pie
+CFLAGS		+= -Os
 LDFLAGS		+= --gc-sections
 
 OBJ		:= $(addprefix $(ARCH_SRC),$(ARCH_OBJ)) $(addprefix $(COMMON_SRC),$(COMMON_OBJ))
-- 
2.25.1




More information about the linux-arm-kernel mailing list