diff options
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | Makefile.toolchain | 21 | ||||
-rw-r--r-- | third_party/rules.mk | 2 |
3 files changed, 27 insertions, 2 deletions
@@ -268,7 +268,9 @@ include $(BASEDIR)/build.mk ifneq ($(BASEDIR),$(BDIR)) include $(BDIR)/build.mk endif +ifeq ($(USE_BUILTIN_STDLIB), 1) include builtin/build.mk +endif include chip/$(CHIP)/build.mk include core/$(CORE)/build.mk include common/build.mk @@ -308,7 +310,9 @@ ifneq ($(PBDIR),) all-obj-$(1)+=$(call objs_from_dir_p,$(PBDIR),board-private,$(1)) endif all-obj-$(1)+=$(call objs_from_dir_p,common,common,$(1)) +ifeq ($(USE_BUILTIN_STDLIB), 1) all-obj-$(1)+=$(call objs_from_dir_p,builtin,builtin,$(1)) +endif all-obj-$(1)+=$(call objs_from_dir_p,driver,driver,$(1)) all-obj-$(1)+=$(call objs_from_dir_p,power,power,$(1)) ifdef CTS_MODULE @@ -355,7 +359,9 @@ dirs=core/$(CORE) chip/$(CHIP) $(BASEDIR) $(BDIR) common fuzz power test \ dirs+= private private-kandou $(PDIR) $(PBDIR) dirs+=$(shell find common -type d) dirs+=$(shell find driver -type d) +ifeq ($(USE_BUILTIN_STDLIB), 1) dirs+=builtin +endif common_dirs=util ifeq ($(custom-ro_objs-y),) diff --git a/Makefile.toolchain b/Makefile.toolchain index 2ce8f2ba5f..fcb2dd4b00 100644 --- a/Makefile.toolchain +++ b/Makefile.toolchain @@ -23,6 +23,12 @@ ifneq ($(TEST_FUZZ)$(TEST_ASAN)$(TEST_MSAN)$(TEST_UBSAN),) CC=clang endif +# When set to 1, use the subset of the C standard library implemented in EC +# (the "builtin" directory). +# When set to 0, link against the toolchain's implementation of the C standard +# library. +USE_BUILTIN_STDLIB:=1 + # Extract cc-name cc-name:=$(shell $(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc) @@ -124,8 +130,11 @@ HOST_CPPFLAGS=$(CFLAGS_DEFINE) $(CFLAGS_INCLUDE) $(CFLAGS_TEST) \ $(EXTRA_CFLAGS) $(CFLAGS_COVERAGE) $(CFLAGS_HOSTTEST) $(LATE_CFLAGS_DEFINE) \ -DSECTION_IS_$(BLD)=$(EMPTY) -DSECTION=$(BLD) $(CPPFLAGS_$(BLD)) ifneq ($(BOARD),host) -CPPFLAGS+=-ffreestanding -fno-builtin -nostdinc -nostdlib -fno-PIC +CPPFLAGS+=-fno-PIC +ifeq ($(USE_BUILTIN_STDLIB), 1) +CPPFLAGS+=-ffreestanding -fno-builtin -nostdinc -nostdlib CPPFLAGS+=-Ibuiltin/ +endif else CPPFLAGS+=-Og endif @@ -139,6 +148,9 @@ CFLAGS+= -ffat-lto-objects CFLAGS+= -fconserve-stack endif CXXFLAGS+=-DPROTOBUF_INLINE_NOT_IN_HEADERS=0 +ifeq ($(USE_BUILTIN_STDLIB), 1) +CPPFLAGS+=-DUSE_BUILTIN_STDLIB +endif ifeq ($(LIBFTDI_NAME),) FTDIVERSION:=$(shell $(PKG_CONFIG) --modversion libftdi1 2>/dev/null) @@ -173,8 +185,13 @@ HOST_CXXFLAGS=$(HOST_CFLAGS) ifneq (${SYSROOT},) LDFLAGS_EXTRA+=--sysroot=${SYSROOT} endif -LDFLAGS=-nostdlib -g -no-pie -Wl,-X -Wl,--gc-sections -Wl,--build-id=none \ +LDFLAGS=-g -no-pie -Wl,-X -Wl,--gc-sections -Wl,--build-id=none \ $(LDFLAGS_EXTRA) $(CFLAGS_CPU) +ifeq ($(USE_BUILTIN_STDLIB), 1) +LDFLAGS+=-nostdlib +else +LDFLAGS+=-lnosys +endif MEMSIZE_FLAGS= ifeq ($(cc-name),gcc) MEMSIZE_FLAGS+=-Wl,--print-memory-usage diff --git a/third_party/rules.mk b/third_party/rules.mk index 16fd1e52e3..c729aa24ef 100644 --- a/third_party/rules.mk +++ b/third_party/rules.mk @@ -23,8 +23,10 @@ cmd_libcryptoc = $(MAKE) -C $(CRYPTOC_DIR) \ cmd_libcryptoc_clean = $(cmd_libcryptoc) -q && echo clean ifneq ($(BOARD),host) +ifeq ($(USE_BUILTIN_STDLIB), 1) CPPFLAGS += -I$(abspath ./builtin) endif +endif CPPFLAGS += -I$(CRYPTOC_DIR)/include CRYPTOC_LDFLAGS := -L$(out)/cryptoc -lcryptoc |