From dd52b42757d49a6b25dc0b22ce44dc1133c991c0 Mon Sep 17 00:00:00 2001 From: strawberry Date: Tue, 9 Apr 2024 20:18:15 -0400 Subject: [PATCH] add CONFIG_STATIC to skip linking for static binary builds Signed-off-by: strawberry --- Makefile | 18 +++++++++++++++++- config/default.mk | 1 + config/light.mk | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f33f88ea..43b4f94a 100644 --- a/Makefile +++ b/Makefile @@ -18,11 +18,20 @@ $(shell $(CC) $(if $(filter clang%,$(CC)),-Werror=unknown-warning-option) -E $1 endef CPPFLAGS := $(CPPFLAGS) -D_GNU_SOURCE -I include -SHARED_FLAGS := -pipe -O3 -flto -fPIC -fvisibility=hidden -fno-plt \ +SHARED_FLAGS := -pipe -O3 -fPIC -fvisibility=hidden -fno-plt \ -fstack-clash-protection $(call safe_flag,-fcf-protection) -fstack-protector-strong \ -Wall -Wextra $(call safe_flag,-Wcast-align=strict,-Wcast-align) -Wcast-qual -Wwrite-strings \ -Wundef +# assume dynamic build if not specified +ifeq ($(CONFIG_STATIC),) + SHARED_FLAGS += -flto +else ifeq ($(CONFIG_STATIC),false) + SHARED_FLAGS += -flto +else ifeq ($(CC),"gcc") + SHARED_FLAGS += -flto +endif + ifeq ($(CONFIG_WERROR),true) SHARED_FLAGS += -Werror endif @@ -110,8 +119,15 @@ CPPFLAGS += \ -DCONFIG_STATS=$(CONFIG_STATS) \ -DCONFIG_SELF_INIT=$(CONFIG_SELF_INIT) +$(OUT)/libhardened_malloc$(SUFFIX).so: $(OBJECTS) + +ifeq ($(CONFIG_STATIC),) $(OUT)/libhardened_malloc$(SUFFIX).so: $(OBJECTS) | $(OUT) $(CC) $(CFLAGS) $(LDFLAGS) -shared $^ $(LDLIBS) -o $@ +else ifeq ($(CONFIG_STATIC),false) +$(OUT)/libhardened_malloc$(SUFFIX).so: $(OBJECTS) | $(OUT) + $(CC) $(CFLAGS) $(LDFLAGS) -shared $^ $(LDLIBS) -o $@ +endif $(OUT): mkdir -p $(OUT) diff --git a/config/default.mk b/config/default.mk index 71b1cc42..280fe47b 100644 --- a/config/default.mk +++ b/config/default.mk @@ -1,3 +1,4 @@ +CONFIG_STATIC := false CONFIG_WERROR := true CONFIG_NATIVE := true CONFIG_CXX_ALLOCATOR := true diff --git a/config/light.mk b/config/light.mk index 88a0e1f5..ebc64145 100644 --- a/config/light.mk +++ b/config/light.mk @@ -1,3 +1,4 @@ +CONFIG_STATIC := false CONFIG_WERROR := true CONFIG_NATIVE := true CONFIG_CXX_ALLOCATOR := true