supranational / blst

Multilingual BLS12-381 signature library
Apache License 2.0
463 stars 178 forks source link

Portable builds fail in shared library build #178

Closed arnetheduck closed 1 year ago

arnetheduck commented 1 year ago
CFLAGS=-D__BLST_PORTABLE__ ./build.sh -shared
+ cc -D__BLST_PORTABLE__ -D__ADX__ -mno-avx -c ./src/server.c
+ cc -D__BLST_PORTABLE__ -D__ADX__ -mno-avx -c ./build/assembly.S
+ ar rc libblst.a assembly.o server.o
+ cc -shared -o libblst.so -Wl,--whole-archive,libblst.a,--no-whole-archive -D__BLST_PORTABLE__ -D__ADX__ -mno-avx -Wl,-Bsymbolic,--version-script=/tmp/ld.blst.279657
/usr/bin/ld: error: libblst.a(server.o): requires dynamic R_X86_64_32 reloc against 'BLS12_381_r' which may overflow at runtime; recompile with -fPIC

4967efe5c49b5abd09895ffa31d54e308835ab15

arnetheduck commented 1 year ago

Ah, misunderstood the build system - CFLAGS="-D__BLST_PORTABLE__ -fPIC" ./build.sh -shared works as expected

dot-asm commented 1 year ago

CFLAGS environment variable has an absolute priority. Formally speaking one can make a case that -fPIC should be passed nevertheless. Meanwhile passing compiler flags directly to build.sh is better suited for all-round purposes, as ./build.sh -shared -D__BLST_PORTABLE__.