From 8a3359e2ee563951e74926acf7299a5f4081164a Mon Sep 17 00:00:00 2001 From: "Thing-han, Lim" <15379156+potsrevennil@users.noreply.github.com> Date: Mon, 18 Nov 2024 13:52:31 +0800 Subject: [PATCH] workaround to make -flto work in nix shell nix gcc comes with lto library, but binutils like ar doesn't seem to properly configured regarding this. The easiest workaround to make -flto work is therefore to avoid building libraries, let gcc take over everything. `CPPFLAGS += -DMLKEM_USE_NATIVE` in `mk/crypto.mk` is removed btw as it's duplicated in `mk/schemes.mk` Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> --- mk/bench.mk | 4 +--- mk/config.mk | 3 --- mk/crypto.mk | 11 ++--------- mk/rules.mk | 18 ++++++------------ mk/schemes.mk | 2 +- 5 files changed, 10 insertions(+), 28 deletions(-) diff --git a/mk/bench.mk b/mk/bench.mk index 6293d1eea..a1a115d82 100644 --- a/mk/bench.mk +++ b/mk/bench.mk @@ -1,5 +1,3 @@ # SPDX-License-Identifier: Apache-2.0 -LIBDEPS += $(LIB_DIR)/libhal.a -LDLIBS += -lhal CPPFLAGS += -Itest/hal -$(LIB_DIR)/libhal.a: $(call OBJS,$(wildcard test/hal/*.c)) +SOURCES += $(wildcard test/hal/*.c) diff --git a/mk/config.mk b/mk/config.mk index 193d5fa1a..5a254d12e 100644 --- a/mk/config.mk +++ b/mk/config.mk @@ -41,8 +41,6 @@ CFLAGS += \ -MMD \ $(CPPFLAGS) -LINKDEPS += $(LIBDEPS) - ################## # Some Variables # ################## @@ -83,7 +81,6 @@ include mk/auto.mk endif BUILD_DIR := test/build -LIB_DIR := $(BUILD_DIR)/lib MAKE_OBJS = $(2:%=$(1)/%.o) OBJS = $(call MAKE_OBJS,$(BUILD_DIR),$(1)) diff --git a/mk/crypto.mk b/mk/crypto.mk index 59ce1f47a..9d096443f 100644 --- a/mk/crypto.mk +++ b/mk/crypto.mk @@ -1,14 +1,7 @@ # SPDX-License-Identifier: Apache-2.0 -LDLIBS += -L$(LIB_DIR) - -LIBDEPS += $(LIB_DIR)/libfips202.a -LDLIBS += -lfips202 CPPFLAGS += -Ifips202 -Ifips202/native -FIPS202_SRCS = $(wildcard fips202/*.c) +SOURCES += $(wildcard fips202/*.c) ifeq ($(OPT),1) - FIPS202_SRCS += $(wildcard fips202/native/aarch64/*.S) $(wildcard fips202/native/x86_64/xkcp/*.c) - CPPFLAGS += -DMLKEM_USE_NATIVE + SOURCES += $(wildcard fips202/native/aarch64/*.S) $(wildcard fips202/native/x86_64/xkcp/*.c) endif - -$(LIB_DIR)/libfips202.a: $(call OBJS, $(FIPS202_SRCS)) diff --git a/mk/rules.mk b/mk/rules.mk index 36519837d..dea93fb21 100644 --- a/mk/rules.mk +++ b/mk/rules.mk @@ -1,24 +1,18 @@ # SPDX-License-Identifier: Apache-2.0 -$(BUILD_DIR)/mlkem512/bin/%: $(LINKDEPS) $(CONFIG) +$(BUILD_DIR)/mlkem512/bin/%: $(CONFIG) $(Q)echo " LD $@" $(Q)[ -d $(@D) ] || mkdir -p $(@D) - $(LD) $(CFLAGS) -o $@ $(filter %.o,$^) $(LDLIBS) + $(LD) $(CFLAGS) -o $@ $(filter %.o,$^) -$(BUILD_DIR)/mlkem768/bin/%: $(LINKDEPS) $(CONFIG) +$(BUILD_DIR)/mlkem768/bin/%: $(CONFIG) $(Q)echo " LD $@" $(Q)[ -d $(@D) ] || mkdir -p $(@D) - $(LD) $(CFLAGS) -o $@ $(filter %.o,$^) $(LDLIBS) + $(LD) $(CFLAGS) -o $@ $(filter %.o,$^) -$(BUILD_DIR)/mlkem1024/bin/%: $(LINKDEPS) $(CONFIG) +$(BUILD_DIR)/mlkem1024/bin/%: $(CONFIG) $(Q)echo " LD $@" $(Q)[ -d $(@D) ] || mkdir -p $(@D) - $(LD) $(CFLAGS) -o $@ $(filter %.o,$^) $(LDLIBS) - -$(LIB_DIR)/%.a: $(CONFIG) - $(Q)echo " AR $@" - $(Q)[ -d $(@D) ] || mkdir -p $(@D) - $(Q)rm -f $@ - $(Q)$(AR) rcs $@ $(filter %.o,$^) + $(LD) $(CFLAGS) -o $@ $(filter %.o,$^) $(BUILD_DIR)/%.c.o: %.c $(CONFIG) $(Q)echo " CC $@" diff --git a/mk/schemes.mk b/mk/schemes.mk index f1dc2be39..6a4e7fec8 100644 --- a/mk/schemes.mk +++ b/mk/schemes.mk @@ -1,5 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 -SOURCES = $(wildcard mlkem/*.c) $(wildcard mlkem/debug/*.c) +SOURCES += $(wildcard mlkem/*.c) $(wildcard mlkem/debug/*.c) ifeq ($(OPT),1) SOURCES += $(wildcard mlkem/native/aarch64/*.[csS]) $(wildcard mlkem/native/x86_64/*.[csS]) CPPFLAGS += -DMLKEM_USE_NATIVE