Skip to content

Commit 3f77ade

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

File tree

4 files changed

+61
-39
lines changed

4 files changed

+61
-39
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,34 @@ jobs:
677677
verbose: true
678678
cflags: "-O0"
679679
secrets: inherit
680+
check_hol_light_bytecode:
681+
strategy:
682+
fail-fast: false
683+
matrix:
684+
target:
685+
- system: macos-latest
686+
nix_shell: hol_light
687+
nix_cache: false
688+
- system: macos-intel
689+
nix_shell: hol_light
690+
nix_cache: false
691+
- system: ubuntu-latest
692+
nix_shell: hol_light-cross-aarch64
693+
nix_cache: true
694+
- system: pqcp-arm64
695+
nix_shell: hol_light
696+
nix_cache: false
697+
runs-on: ${{ matrix.target.system }}
698+
name: Check HOL-Light bytecode ${{ matrix.target.system }}
699+
steps:
700+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
701+
- uses: ./.github/actions/setup-shell
702+
with:
703+
nix-shell: ${{ matrix.target.nix_shell }}
704+
nix-cache: ${{ matrix.target.nix_cache }}
705+
gh_token: ${{ secrets.GITHUB_TOKEN }}
706+
script: |
707+
python3 ./scripts/autogen --dry-run --update-hol-light-bytecode
680708
check_autogenerated_files:
681709
strategy:
682710
fail-fast: false
@@ -693,11 +721,3 @@ jobs:
693721
gh_token: ${{ secrets.GITHUB_TOKEN }}
694722
script: |
695723
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

flake.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@
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+
};
123+
devShells.hol_light-cross-aarch64 = util.mkShell {
124+
packages = builtins.attrValues { inherit (config.packages) linters toolchain_aarch64 hol_light s2n_bignum; };
125+
};
126+
devShells.hol_light-cross-x86_64 = util.mkShell {
127+
packages = builtins.attrValues { inherit (config.packages) linters toolchain_x86_64 hol_light s2n_bignum; };
128+
};
120129
devShells.ci-cross = util.mkShell {
121130
packages = builtins.attrValues { inherit (config.packages) linters toolchains; };
122131
};

proofs/hol_light/arm/Makefile

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,53 +19,46 @@ 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 ($(ARCHTYPE_RESULT)-$(OSTYPE_RESULT),x86_64-Darwin)
30+
ASSEMBLE=as -arch arm64
31+
OBJDUMP=otool -tvV
32+
else
33+
ifeq ($(filter $(ARCHTYPE_RESULT),aarch64 arm64),)
34+
CROSS_PREFIX=aarch64-unknown-linux-gnu-
35+
# Check if cross-toolchain exists
36+
ifeq ($(shell command -v $(ASSEMBLE) >/dev/null 2>&1 && echo yes || echo no),no)
37+
$(error Cross-toolchain not found. Please run in the 'hol_light' nix shell via: nix develop .#hol_light)
38+
endif
39+
endif
40+
ASSEMBLE=$(CROSS_PREFIX)as $(ARCHFLAGS)
41+
OBJDUMP=$(CROSS_PREFIX)objdump -d
42+
endif
43+
2244
# Add explicit language input parameter to cpp, otherwise the use of #n for
2345
# numeric literals in ARM code is a problem when used inside #define macros
2446
# since normally that means stringization.
2547
#
2648
# Some clang-based preprocessors seem to behave differently, and get confused
2749
# by single-quote characters in comments, so we eliminate // comments first.
2850

29-
ARCHFLAGS=-march=armv8.4-a+sha3
3051
ifeq ($(OSTYPE_RESULT),Darwin)
3152
PREPROCESS=sed -e 's/\/\/.*//' | $(CC) -E -xassembler-with-cpp -
3253
else
33-
PREPROCESS=$(CC) $(ARCHFLAGS) -E -xassembler-with-cpp -
54+
PREPROCESS=$(CC) -E -xassembler-with-cpp -
3455
endif
3556

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

3960
SPLIT=tr ';' '\n'
4061

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-
6962
OBJ = mlkem/mlkem_ntt.o \
7063
mlkem/mlkem_intt.o \
7164
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)