Skip to content

Commit

Permalink
Revert "build: clarify that the libs are tmp artifacts"
Browse files Browse the repository at this point in the history
This reverts commit e953c77.

Signed-off-by: Hanno Becker <[email protected]>
  • Loading branch information
hanno-becker committed Dec 13, 2024
1 parent 7938203 commit ee10493
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: make lib
run: |
make test/build/tmp/libtmp_mlkem.a
make lib
build_kat:
needs: [quickcheck, quickcheck-windows]
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ quickcheck: buildall
./scripts/acvp
$(Q)echo " Functionality and ACVP tests passed!"

lib: $(BUILD_DIR)/libmlkem.a

mlkem: \
$(MLKEM512_DIR)/bin/test_mlkem512 \
$(MLKEM768_DIR)/bin/test_mlkem768 \
Expand Down
1 change: 0 additions & 1 deletion mk/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ include mk/auto.mk
endif

BUILD_DIR ?= test/build
TMP_DIR ?= test/build/tmp

MAKE_OBJS = $(2:%=$(1)/%.o)
OBJS = $(call MAKE_OBJS,$(BUILD_DIR),$(1))
Expand Down
8 changes: 4 additions & 4 deletions mk/crypto.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ ifeq ($(OPT),1)
FIPS202_SRCS += $(wildcard fips202/native/aarch64/*.S) $(wildcard fips202/native/x86_64/xkcp/*.c)
endif

$(TMP_DIR)/libtmp_fips202.a: $(call OBJS, $(FIPS202_SRCS))
$(TMP_DIR)/libtmp_mlkem.a: $(call OBJS, $(FIPS202_SRCS))
$(BUILD_DIR)/libfips202.a: $(call OBJS, $(FIPS202_SRCS))
$(BUILD_DIR)/libmlkem.a: $(call OBJS, $(FIPS202_SRCS))

# all lib<scheme>.a depends on libfips202.a
define ADD_FIPS202
$(TMP_DIR)/libtmp_$(1).a: LDLIBS += -ltmp_fips202
$(BUILD_DIR)/lib$(1).a: LDLIBS += -lfips202
# NOTE:
# - Merging multiple .a files with ar is more complex than building a single library directly from all the object files (.o). Hence, all .o files are added as dependencies here.

$(TMP_DIR)/libtmp_$(1).a: $(TMP_DIR)/libtmp_fips202.a $(call OBJS, $(FIPS202_SRCS))
$(BUILD_DIR)/lib$(1).a: $(BUILD_DIR)/libfips202.a $(call OBJS, $(FIPS202_SRCS))
endef

$(foreach scheme,mlkem512 mlkem768 mlkem1024, \
Expand Down
6 changes: 3 additions & 3 deletions mk/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ $(BUILD_DIR)/%.a: $(CONFIG)
# NOTE:
# $AR doesn't care about duplicated symbols, one can only find it out via actually linking.
# The easiest one to do this that one can think of is to create a dummy C file with empty main function on the fly, pipe it to $CC and link with the built library
$(eval _LIB := $(subst $(shell dirname $@)/lib,,$(@:%.a=%)))
$(eval _LIB := $(subst $(BUILD_DIR)/lib,,$(@:%.a=%)))
ifneq ($(findstring clang,$(shell $(CC) --version)),) # if CC is clang
$(Q)echo "int main() {return 0;}" \
| $(CC) -x c - -L$(shell dirname $@) \
| $(CC) -x c - -L$(BUILD_DIR) \
-all_load -Wl,-undefined,dynamic_lookup -l$(_LIB) \
-Imlkem $(wildcard test/notrandombytes/*.c)
$(Q)rm -f a.out
else # if CC is not clang
$(Q)echo "int main() {return 0;}" \
| $(CC) -x c - -L$(shell dirname $@) \
| $(CC) -x c - -L$(BUILD_DIR) \
-Wl,--whole-archive,--unresolved-symbols=ignore-in-object-files -l$(_LIB) \
-Wl,--no-whole-archive \
-Imlkem $(wildcard test/notrandombytes/*.c)
Expand Down
16 changes: 8 additions & 8 deletions mk/schemes.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ MLKEM1024_DIR = $(BUILD_DIR)/mlkem1024

# build lib<scheme>.a
define BUILD_LIB
$(TMP_DIR)/libtmp_$(1).a: CFLAGS += -static
$(TMP_DIR)/libtmp_$(1).a: $(call MAKE_OBJS,$(BUILD_DIR)/$(1),$(SOURCES))
$(BUILD_DIR)/lib$(1).a: CFLAGS += -static
$(BUILD_DIR)/lib$(1).a: $(call MAKE_OBJS,$(BUILD_DIR)/$(1),$(SOURCES))

# NOTE:
# - The order matters, or else the `MLKEM_K` preprocessor won't be properly set
# - Merging multiple .a files with ar is more complex than building a single library directly from all the object files (.o). Hence, all .o files are added as dependencies here.
$(TMP_DIR)/libtmp_mlkem.a: $(TMP_DIR)/libtmp_$(1).a $(call MAKE_OBJS,$(BUILD_DIR)/$(1),$(SOURCES))
$(BUILD_DIR)/libmlkem.a: $(BUILD_DIR)/lib$(1).a $(call MAKE_OBJS,$(BUILD_DIR)/$(1),$(SOURCES))
endef

$(TMP_DIR)/libtmp_mlkem512.a: CPPFLAGS += -DMLKEM_K=2
$(TMP_DIR)/libtmp_mlkem768.a: CPPFLAGS += -DMLKEM_K=3
$(TMP_DIR)/libtmp_mlkem1024.a: CPPFLAGS += -DMLKEM_K=4
$(BUILD_DIR)/libmlkem512.a: CPPFLAGS += -DMLKEM_K=2
$(BUILD_DIR)/libmlkem768.a: CPPFLAGS += -DMLKEM_K=3
$(BUILD_DIR)/libmlkem1024.a: CPPFLAGS += -DMLKEM_K=4

# build libmlkem512.a libmlkem768.a libmlkem1024.a
$(foreach scheme,mlkem512 mlkem768 mlkem1024, \
$(eval $(call BUILD_LIB,$(scheme))))

# rules for compilation for all tests: mainly linking with mlkem static link library
define ADD_SOURCE
$(BUILD_DIR)/$(1)/bin/$(2)$(shell echo $(1) | tr -d -c 0-9): LDLIBS += -L$(TMP_DIR) -ltmp_$(1)
$(BUILD_DIR)/$(1)/bin/$(2)$(shell echo $(1) | tr -d -c 0-9): $(BUILD_DIR)/$(1)/test/$(2).c.o $(TMP_DIR)/libtmp_$(1).a
$(BUILD_DIR)/$(1)/bin/$(2)$(shell echo $(1) | tr -d -c 0-9): LDLIBS += -L$(BUILD_DIR) -l$(1)
$(BUILD_DIR)/$(1)/bin/$(2)$(shell echo $(1) | tr -d -c 0-9): $(BUILD_DIR)/$(1)/test/$(2).c.o $(BUILD_DIR)/lib$(1).a
endef

$(MLKEM512_DIR)/bin/%: CPPFLAGS += -DMLKEM_K=2
Expand Down

0 comments on commit ee10493

Please sign in to comment.