-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MacOS: code fails to compile under current Xcode #6
Comments
mouse07410
changed the title
MacOS: ref fails to compile under current Xcode
MacOS: code fails to compile under current Xcode
Apr 6, 2020
Finally, the following patch allows build and tests succeed using Xcode-11.4 clang: diff --git a/avx2/Makefile b/avx2/Makefile
index 83c0285..41ef314 100644
--- a/avx2/Makefile
+++ b/avx2/Makefile
@@ -1,6 +1,6 @@
-CC = /usr/bin/gcc
-CFLAGS = -no-pie -Wall -Wextra -g -O3 -fomit-frame-pointer -msse2avx -mavx2 -march=native
-NISTFLAGS = -O3 -fomit-frame-pointer -march=native -fPIC -no-pie
+CC ?= gcc
+CFLAGS = -ffreestanding -fno-stack-check -no-pie -Wall -Wextra -g -O3 -fomit-frame-pointer -msse2 -mavx -mavx2 -march=native -I/opt/local/include -L/opt/local/lib
+NISTFLAGS = -ffreestanding -fno-stack-check -O3 -fomit-frame-pointer -march=native -fPIC -no-pie -I/opt/local/include -L/opt/local/lib
HEADERS = params.h poly.h randombytes.h ntt.h reduce.h verify.h cpapke.h
SOURCES = poly.c reduce.c fips202.c verify.c cpapke.c ntt_double.s ntt.c precomp.c
@@ -19,7 +19,7 @@ all: PQCgenKAT_cpakem512 \
speed_cpakem512 \
speed_cpakem1024 \
speed_ccakem512 \
- speed_ccakem1024 \
+ speed_ccakem1024
PQCgenKAT_cpakem512: $(SOURCES) $(HEADERS) PQCgenKAT_kem.c rng.c rng.h
ln -sf cpakem.h api.h
diff --git a/avx2/poly.h b/avx2/poly.h
index 1bfa840..92d4d0a 100644
--- a/avx2/poly.h
+++ b/avx2/poly.h
@@ -2,6 +2,7 @@
#define POLY_H
#include <stdint.h>
+#include <stddef.h>
#include "params.h"
typedef struct {
diff --git a/avx2/speed.c b/avx2/speed.c
index bb9c225..a3f0d64 100644
--- a/avx2/speed.c
+++ b/avx2/speed.c
@@ -13,7 +13,7 @@ static int cmp_llu(const void *a, const void*b)
return 0;
}
-static unsigned long long median(unsigned long long *l, size_t llen)
+static unsigned long long median(unsigned long long *l, const size_t llen)
{
qsort(l,llen,sizeof(unsigned long long),cmp_llu);
@@ -21,7 +21,7 @@ static unsigned long long median(unsigned long long *l, size_t llen)
else return (l[llen/2-1]+l[llen/2])/2;
}
-static unsigned long long average(unsigned long long *t, size_t tlen)
+static unsigned long long average(unsigned long long *t, const size_t tlen)
{
unsigned long long acc=0;
size_t i;
@@ -30,7 +30,7 @@ static unsigned long long average(unsigned long long *t, size_t tlen)
return acc/(tlen);
}
-static void print_results(const char *s, unsigned long long *t, size_t tlen)
+static void print_results(const char *s, unsigned long long *t, const size_t tlen)
{
size_t i;
printf("%s", s);
diff --git a/avx2/test_newhope.c b/avx2/test_newhope.c
index e30ddcd..23b85d1 100644
--- a/avx2/test_newhope.c
+++ b/avx2/test_newhope.c
@@ -1,9 +1,9 @@
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
#include "api.h"
#include "poly.h"
#include "randombytes.h"
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
#define NTESTS 1000
@@ -24,7 +24,7 @@ int test_keys()
//Bob derives a secret key and creates a response
crypto_kem_enc(sendb, key_b, pk);
- //Alice uses Bobs response to get her secre key
+ //Alice uses Bobs response to get her secret key
crypto_kem_dec(key_a, sendb, sk_a);
if(memcmp(key_a, key_b, 32))
@@ -65,7 +65,7 @@ int test_invalid_sk_a()
//Replace secret key with random values
fread(sk_a, CRYPTO_SECRETKEYBYTES, 1, urandom);
- //Alice uses Bobs response to get her secre key
+ //Alice uses Bobs response to get her secret key
crypto_kem_dec(key_a, sendb, sk_a);
if(!memcmp(key_a, key_b, 32))
@@ -99,7 +99,7 @@ int test_invalid_ciphertext()
//Change some byte in the ciphertext (i.e., encapsulated key)
sendb[42] ^= 23;
- //Alice uses Bobs response to get her secre key
+ //Alice uses Bobs response to get her secret key
crypto_kem_dec(key_a, sendb, sk_a);
if(!memcmp(key_a, key_b, 32))
diff --git a/avx2/verify.c b/avx2/verify.c
index 7d01a47..b634a24 100644
--- a/avx2/verify.c
+++ b/avx2/verify.c
@@ -2,7 +2,7 @@
#include <stdint.h>
/* returns 0 for equal strings, 1 for non-equal strings */
-int verify(const unsigned char *a, const unsigned char *b, size_t len)
+int verify(const unsigned char *a, const unsigned char *b, const size_t len)
{
uint64_t r;
size_t i;
diff --git a/avx2/verify.h b/avx2/verify.h
index 5394316..693af4b 100644
--- a/avx2/verify.h
+++ b/avx2/verify.h
@@ -4,7 +4,7 @@
#include <stdio.h>
/* returns 0 for equal strings, 1 for non-equal strings */
-int verify(const unsigned char *a, const unsigned char *b, size_t len);
+int verify(const unsigned char *a, const unsigned char *b, const size_t len);
/* b = 1 means mov, b = 0 means don't mov*/
void cmov(unsigned char *r, const unsigned char *x, size_t len, unsigned char b);
diff --git a/ref/Makefile b/ref/Makefile
index f7d4469..a133512 100644
--- a/ref/Makefile
+++ b/ref/Makefile
@@ -1,6 +1,6 @@
-CC = /usr/bin/gcc
-CFLAGS = -Wall -Wextra -g -O3 -fomit-frame-pointer -march=native
-NISTFLAGS = -O3 -fomit-frame-pointer -march=native -fPIC -no-pie
+CC ?= gcc
+CFLAGS = -Wall -Wextra -g -O3 -fomit-frame-pointer -march=native -I/opt/local/include -L/opt/local/lib
+NISTFLAGS = -O3 -fomit-frame-pointer -march=native -fPIC -no-pie -I/opt/local/include -L/opt/local/lib
HEADERS = params.h poly.h randombytes.h ntt.h reduce.h verify.h cpapke.h
SOURCES = poly.c reduce.c fips202.c verify.c cpapke.c ntt.c precomp.c
@@ -18,7 +18,7 @@ all: PQCgenKAT_cpakem512 \
speed_cpakem512 \
speed_cpakem1024 \
speed_ccakem512 \
- speed_ccakem1024 \
+ speed_ccakem1024
PQCgenKAT_cpakem512: $(SOURCES) $(HEADERS) PQCgenKAT_kem.c rng.c rng.h
ln -sf cpakem.h api.h
diff --git a/ref/poly.h b/ref/poly.h
index efe5f49..4728a30 100644
--- a/ref/poly.h
+++ b/ref/poly.h
@@ -2,6 +2,7 @@
#define POLY_H
#include <stdint.h>
+#include <stddef.h>
#include "params.h"
/* I took the liberty of adding Here's the patch file: macosx.patch.zip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This happens with the
ref/Makefile
intact:After pointing the compiler at the correct location of the OpenSSL-1.1.1 (there's no other usable OpenSSL on this box, except for OpenSSL-3.0 Dev master):
the code in
ref/
builds but crashes:The problem appears to be stack alignment that gets screwed up by the Xcode compilers - from the crash report:
This workaround (adding
-ffrestanding
flag) helps:and produces desirable results:
Switching from Xcode clang to Macports-installed
clang-mp-9.0
alleviated the need to add-ffreestanding
flag.Update
Similar problem with
avx2/
code, for the same reason ("stack not 16-byte aligned").Compiling with Macports-installed
clang-mp-9.0
, or adding-ffreestanding
flag resolved it here as well.The text was updated successfully, but these errors were encountered: