open-quantum-safe / liboqs

C library for prototyping and experimenting with quantum-resistant cryptography
https://openquantumsafe.org/
Other
1.88k stars 460 forks source link

liboqs 0.6.0 does not build on Apple M1 #1018

Closed chenrui333 closed 3 years ago

chenrui333 commented 3 years ago

👋 trying to build the latest release, but run into some build issue. The error log is as below:

build failure on 11-arm ``` ld: warning: arm64 function not 4-byte aligned: oqs_kem_sike_mp_subadd751x2_asm from src/kem/sike/CMakeFiles/sike.dir/external/P751/ARM64/fp_arm64_asm.S.o ld: warning: arm64 function not 4-byte aligned: oqs_kem_sike_mp_dblsub751x2_asm from src/kem/sike/CMakeFiles/sike.dir/external/P751/ARM64/fp_arm64_asm.S.o Undefined symbols for architecture arm64: "_oqs_kem_sike_fpadd434_asm", referenced from: _oqs_kem_sike_fpadd434 in P434.c.o _oqs_kem_sike_fp2add434 in P434.c.o ```

relates to Homebrew/homebrew-core#79124

jschanck commented 3 years ago

Thanks for this.

A temporary fix is to remove the OR ... "Darwin" conditions from https://github.com/open-quantum-safe/liboqs/blob/00d6c7d5410fe5949a75e5f4d86120bd1c60bef6/src/kem/sike/CMakeLists.txt#L65 https://github.com/open-quantum-safe/liboqs/blob/00d6c7d5410fe5949a75e5f4d86120bd1c60bef6/src/kem/sike/CMakeLists.txt#L113


@christianpaquin SIKE's ARM64 assembly is missing the leading underscores on function names that are assumed when linking Mach-O objects. We need a fix similar to what's done in the x86-64 code: https://github.com/open-quantum-safe/liboqs/blob/00d6c7d5410fe5949a75e5f4d86120bd1c60bef6/src/kem/sike/external/P434/AMD64/fp_x64_asm.S#L10-L14

jschanck commented 3 years ago

ping @christianpaquin

dstebila commented 3 years ago

The university does have an unused M1 Mac Mini that I can borrow for a bit. May be a week or two until the right staff are next on campus for me to be able to pick it up. Will update you once I have it.

christianpaquin commented 3 years ago

Ok, thanks for the reminder @jschanck. I'll prepare a PR on the upstream. @patricklonga, FYSA.

christianpaquin commented 3 years ago

Pushed PR 48 on SIKE project; waiting for upstream review before merging here. Although it might be interesting to first test on your device when you get it, @dstebila.

christianpaquin commented 3 years ago

Pushed PR 48 on SIKE project; waiting for upstream review before merging here. Although it might be interesting to first test on your device when you get it, @dstebila.

PR #1042 tests the changes from SIKE's PR 48 into OQS directly (since the only issue with the upstream PR is Makefile related, and we can control how the scheme is built here). I can work on Dougla's Mac Mini to test this, but cmake and ninja are missing on the machine and I'm not sure how to install them; @dstebila, can you help?

dstebila commented 3 years ago

PR #1042 tests the changes from SIKE's PR 48 into OQS directly (since the only issue with the upstream PR is Makefile related, and we can control how the scheme is built here). I can work on Dougla's Mac Mini to test this, but cmake and ninja are missing on the machine and I'm not sure how to install them; @dstebila, can you help?

They are installed on my Mac Mini via homebrew. Maybe it's not in your path? The files are in /opt/homebrew/bin.

christianpaquin commented 3 years ago

Tried on the Mac Mini, with changes from PR #1034. Compiles with warnings (same as reported on upstream PR 48 see below), local tests work.

Warnings:

ld: warning: arm64 function not 4-byte aligned: p434 from lib/liboqs.a(fp_arm64_asm.S.o)
ld: warning: arm64 function not 4-byte aligned: p434x2 from lib/liboqs.a(fp_arm64_asm.S.o)
ld: warning: arm64 function not 4-byte aligned: p434x4 from lib/liboqs.a(fp_arm64_asm.S.o)
ld: warning: arm64 function not 4-byte aligned: p434p1_nz from lib/liboqs.a(fp_arm64_asm.S.o)
ld: warning: arm64 function not 4-byte aligned: _oqs_kem_sike_fpadd434_asm from lib/liboqs.a(fp_arm64_asm.S.o)
ld: warning: arm64 function not 4-byte aligned: _oqs_kem_sike_fpsub434_asm from lib/liboqs.a(fp_arm64_asm.S.o)
ld: warning: arm64 function not 4-byte aligned: _oqs_kem_sike_mp_sub434_p2_asm from lib/liboqs.a(fp_arm64_asm.S.o)
ld: warning: arm64 function not 4-byte aligned: _oqs_kem_sike_mp_sub434_p4_asm from lib/liboqs.a(fp_arm64_asm.S.o)
ld: warning: arm64 function not 4-byte aligned: _oqs_kem_sike_mul434_asm from lib/liboqs.a(fp_arm64_asm.S.o)
ld: warning: arm64 function not 4-byte aligned: _oqs_kem_sike_rdc434_asm from lib/liboqs.a(fp_arm64_asm.S.o)
ld: warning: arm64 function not 4-byte aligned: _oqs_kem_sike_mp_add434_asm from lib/liboqs.a(fp_arm64_asm.S.o)
ld: warning: arm64 function not 4-byte aligned: _oqs_kem_sike_mp_add434x2_asm from lib/liboqs.a(fp_arm64_asm.S.o)
ld: warning: arm64 function not 4-byte aligned: _oqs_kem_sike_mp_subadd434x2_asm from lib/liboqs.a(fp_arm64_asm.S.o)
ld: warning: arm64 function not 4-byte aligned: _oqs_kem_sike_mp_dblsub434x2_asm from lib/liboqs.a(fp_arm64_asm.S.o)
jschanck commented 3 years ago

Ah yeah looks like you need a .align 2 directive immediately after the .text on, e.g., line 14 of fp_arm64_asm.S.

christianpaquin commented 3 years ago

Ah yeah looks like you need a .align 2 directive immediately after the .text on, e.g., line 14 of fp_arm64_asm.S.

One question @jschanck : why .align 2 if the warning mentions 4-byte alignment? I tried .align 4 and it also works.

jschanck commented 3 years ago

The OS X assembler reference says that ".align n" means "align on a 2^n byte boundary". Looks like there's also ".p2align n" with the same meaning and a less ambiguous name.

christianpaquin commented 3 years ago

OS X assembler reference says that ".align n" means "align on a 2^n byte boundary".

Oh, I see, thanks for the clarification.