Skip to content

Commit dde8583

Browse files
committed
HOL-Light: Add support for cross-compilation
Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
1 parent 8a25f12 commit dde8583

File tree

4 files changed

+27
-42
lines changed

4 files changed

+27
-42
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -688,16 +688,8 @@ jobs:
688688
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
689689
- uses: ./.github/actions/setup-shell
690690
with:
691-
nix-shell: 'ci-cross' # Need cross-compiler for ASM simplification
691+
nix-shell: 'hol_light-cross' # Need cross-compiler for ASM simplification
692692
nix-cache: 'true'
693693
gh_token: ${{ secrets.GITHUB_TOKEN }}
694694
script: |
695-
python3 ./scripts/autogen --dry-run --force-cross
696-
- uses: ./.github/actions/setup-shell
697-
# Building the HOL-Light bytecode currently requires native compilation
698-
if: ${{ matrix.system == 'pqcp-arm64' }}
699-
with:
700-
nix-shell: 'hol_light'
701-
gh_token: ${{ secrets.GITHUB_TOKEN }}
702-
script: |
703-
python3 ./scripts/autogen --dry-run --update-hol-light-bytecode
695+
python3 ./scripts/autogen --dry-run --force-cross --update-hol-light-bytecode

flake.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@
117117
devShells.ci-slothy = util.mkShell {
118118
packages = builtins.attrValues { inherit (config.packages) slothy linters toolchains_native; };
119119
};
120+
devShells.hol_light-cross = util.mkShell {
121+
packages = builtins.attrValues { inherit (config.packages) linters toolchains hol_light s2n_bignum; };
122+
};
120123
devShells.ci-cross = util.mkShell {
121124
packages = builtins.attrValues { inherit (config.packages) linters toolchains; };
122125
};

proofs/hol_light/arm/Makefile

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,53 +19,43 @@ ARCHTYPE_RESULT=$(shell uname -m)
1919
SRC ?= $(S2N_BIGNUM_DIR)
2020
SRC_ARM ?= $(SRC)/arm
2121

22+
ARCHFLAGS=-march=armv8.4-a+sha3
23+
24+
# If actually on an AArch64 machine, just use the assembler (as). Otherwise
25+
# use a cross-assembling version so that the code can still be assembled
26+
# and the proofs checked against the object files (though you won't be able
27+
# to run code without additional emulation infrastructure).
28+
29+
ifeq ($(filter $(ARCHTYPE_RESULT),aarch64 arm64),)
30+
CROSS_PREFIX=aarch64-unknown-linux-gnu-
31+
# Check if cross-toolchain exists
32+
ifeq ($(shell command -v $(ASSEMBLE) >/dev/null 2>&1 && echo yes || echo no),no)
33+
$(error Cross-toolchain not found. Please run in the 'hol_light' nix shell via: nix develop .#hol_light)
34+
endif
35+
endif
36+
37+
ASSEMBLE=$(CROSS_PREFIX)as $(ARCHFLAGS)
38+
OBJDUMP=$(CROSS_PREFIX)objdump -d
39+
COMPILE=$(CROSS_PREFIX)$(CC)
40+
2241
# Add explicit language input parameter to cpp, otherwise the use of #n for
2342
# numeric literals in ARM code is a problem when used inside #define macros
2443
# since normally that means stringization.
2544
#
2645
# Some clang-based preprocessors seem to behave differently, and get confused
2746
# by single-quote characters in comments, so we eliminate // comments first.
2847

29-
ARCHFLAGS=-march=armv8.4-a+sha3
3048
ifeq ($(OSTYPE_RESULT),Darwin)
31-
PREPROCESS=sed -e 's/\/\/.*//' | $(CC) -E -xassembler-with-cpp -
49+
PREPROCESS=sed -e 's/\/\/.*//' | $(COMPILE) -E -xassembler-with-cpp -
3250
else
33-
PREPROCESS=$(CC) $(ARCHFLAGS) -E -xassembler-with-cpp -
51+
PREPROCESS=$(COMPILE) $(ARCHFLAGS) -E -xassembler-with-cpp -
3452
endif
3553

3654
# Generally GNU-type assemblers are happy with multiple instructions on
3755
# a line, but we split them up anyway just in case.
3856

3957
SPLIT=tr ';' '\n'
4058

41-
# If actually on an ARM8 machine, just use the assembler (as). Otherwise
42-
# use a cross-assembling version so that the code can still be assembled
43-
# and the proofs checked against the object files (though you won't be able
44-
# to run code without additional emulation infrastructure). For the clang
45-
# version on OS X we just add the "-arch arm64" option. For the Linux/gcc
46-
# toolchain we assume the presence of the special cross-assembler. This
47-
# can be installed via something like:
48-
#
49-
# sudo apt-get install binutils-aarch64-linux-gnu
50-
51-
ifeq ($(ARCHTYPE_RESULT),aarch64)
52-
ASSEMBLE=as $(ARCHFLAGS)
53-
OBJDUMP=objdump -d
54-
else
55-
ifeq ($(ARCHTYPE_RESULT),arm64)
56-
ASSEMBLE=as $(ARCHFLAGS)
57-
OBJDUMP=objdump -d
58-
else
59-
ifeq ($(OSTYPE_RESULT),Darwin)
60-
ASSEMBLE=as -arch arm64
61-
OBJDUMP=otool -tvV
62-
else
63-
ASSEMBLE=aarch64-linux-gnu-as $(ARCHFLAGS)
64-
OBJDUMP=aarch64-linux-gnu-objdump -d
65-
endif
66-
endif
67-
endif
68-
6959
OBJ = mlkem/mlkem_ntt.o \
7060
mlkem/mlkem_intt.o \
7161
mlkem/mlkem_poly_tomont.o \

scripts/simpasm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def simplify(logger, args, asm_input, asm_output=None):
246246
logger.debug(f"Using raw global symbol {sym} going forward ...")
247247

248248
cmd = [args.objdump, "--disassemble", tmp_objfile0]
249-
if platform.system() == "Darwin":
249+
if platform.system() == "Darwin" and args.arch == "aarch64":
250250
cmd += ["--triple=aarch64"]
251251

252252
# Add syntax option if specified

0 commit comments

Comments
 (0)