Skip to content

Commit

Permalink
workaround to make -flto work in nix shell
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
potsrevennil authored and mkannwischer committed Nov 18, 2024
1 parent 78008a2 commit 8a3359e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 28 deletions.
4 changes: 1 addition & 3 deletions mk/bench.mk
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 0 additions & 3 deletions mk/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ CFLAGS += \
-MMD \
$(CPPFLAGS)

LINKDEPS += $(LIBDEPS)

##################
# Some Variables #
##################
Expand Down Expand Up @@ -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))
Expand Down
11 changes: 2 additions & 9 deletions mk/crypto.mk
Original file line number Diff line number Diff line change
@@ -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))
18 changes: 6 additions & 12 deletions mk/rules.mk
Original file line number Diff line number Diff line change
@@ -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 $@"
Expand Down
2 changes: 1 addition & 1 deletion mk/schemes.mk
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 8a3359e

Please sign in to comment.