otrv4 / libgoldilocks

An implementation of Mike Hamburg's Ed448 (Goldilocks) curve - derived from libdecaf. This is a mirror of https://bugs.otr.im/otrv4/libgoldilocks
Other
18 stars 6 forks source link

musl-gcc: `goldilocks_gen_tables` is not a statically linked executable when `--enable-static` and `--disable-shared` is passed to `./configure` #13

Open odiferousmint opened 5 years ago

odiferousmint commented 5 years ago

Hello.

Due to goldilocks_gen_tables being a dynamically linked executable, it cannot be executed when compiled with musl-gcc:

$ ./configure --enable-static --disable-shared CC=musl-gcc --host amd64 && make -j2

Result:

[...]
libtool: link: musl-gcc -std=c99 -fno-strict-aliasing -pedantic -Wall -Wextra -Werror -Wunreachable-code -Wmissing-declarations -Wunused-function -Wno-overlength-strings -I../src -I../src/include -I../src/public_include -I../src/arch_x86_64 -I../src/include/arch_x86_64 -O2 -maes -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -fPIC -g -O2 -o goldilocks_gen_tables goldilocks_gen_tables-utils.o goldilocks_gen_tables-goldilocks_gen_tables.o arch_x86_64/goldilocks_gen_tables-f_impl.o goldilocks_gen_tables-f_arithmetic.o goldilocks_gen_tables-f_generic.o goldilocks_gen_tables-goldilocks.o goldilocks_gen_tables-scalar.o 
./goldilocks_gen_tables > GEN/decaf_tables.c || (rm GEN/decaf_tables.c; exit 1)
/bin/sh: ./goldilocks_gen_tables: No such file or directory
make[2]: *** [Makefile:1078: GEN/decaf_tables.c] Error 1
make[2]: Leaving directory '/tmp/libgoldilocks/src'
make[1]: *** [Makefile:419: all-recursive] Error 1
make[1]: Leaving directory '/tmp/libgoldilocks'
make: *** [Makefile:350: all] Error 2

The solution is adding -static to create a statically linked executable instead of a dynamically linked one:

cd src && musl-gcc -static -std=c99 -fno-strict-aliasing -pedantic -Wall -Wextra -Werror -Wunreachable-code -Wmissing-declarations -Wunused-function -Wno-overlength-strings -I../src -I../src/include -I../src/public_include -I../src/arch_x86_64 -I../src/include/arch_x86_64 -O2 -maes -ffunction-sections -fdata-sections -fvisibility=hidden -fomit-frame-pointer -fPIC -g -O2 -o goldilocks_gen_tables goldilocks_gen_tables-utils.o goldilocks_gen_tables-goldilocks_gen_tables.o arch_x86_64/goldilocks_gen_tables-f_impl.o goldilocks_gen_tables-f_arithmetic.o goldilocks_gen_tables-f_generic.o goldilocks_gen_tables-goldilocks.o goldilocks_gen_tables-scalar.o

It seems to be the case that if we append -static, everything seems to work, the executable can be executed (it cannot if we omit -static, ldd shows invalid ELF header), and all tests pass.

The issue arises only when CC is set to musl-gcc. It works with gcc.

I apologize for the long title, I could not come up with a shorter one that summarizes the issue. :/

claucece commented 4 years ago

Hi, @odiferousmint !

Thanks for this! I'll look it this week ;)

Thanks!