blueprint-freespeech / ricochet-refresh

Anonymous peer-to-peer instant messaging
https://www.ricochetrefresh.net
Other
187 stars 27 forks source link

NixOS source build errors while trying to link TOR components #103

Closed deliciouslytyped closed 3 years ago

deliciouslytyped commented 3 years ago

I'm building from source on NixOS and run into the following errors:

/nix/store/cp1sa3xxvl71cypiinw2c62i5s33chlr-binutils-2.35.1/bin/ld: /build/source/src/qmake_includes/../../build/debug/tego_ui/../libtego/libtego.a(ed25519_tor.o): in function `ed25519_donna_seckey':
/build/source/src/libtego/../extern/tor/src/ext/ed25519/donna/ed25519_tor.c:158: undefined reference to `crypto_strongest_rand'
/nix/store/cp1sa3xxvl71cypiinw2c62i5s33chlr-binutils-2.35.1/bin/ld: /build/source/src/libtego/../extern/tor/src/ext/ed25519/donna/ed25519_tor.c:162: undefined reference to `memwipe'
/nix/store/cp1sa3xxvl71cypiinw2c62i5s33chlr-binutils-2.35.1/bin/ld: /build/source/src/qmake_includes/../../build/debug/tego_ui/../libtego/libtego.a(ed25519_tor.o): in function `ed25519_donna_blind_secret_key':
/build/source/src/libtego/../extern/tor/src/ext/ed25519/donna/ed25519_tor.c:284: undefined reference to `memwipe'
/nix/store/cp1sa3xxvl71cypiinw2c62i5s33chlr-binutils-2.35.1/bin/ld: /build/source/src/libtego/../extern/tor/src/ext/ed25519/donna/ed25519_tor.c:285: undefined reference to `memwipe'
/nix/store/cp1sa3xxvl71cypiinw2c62i5s33chlr-binutils-2.35.1/bin/ld: /build/source/src/libtego/../extern/tor/src/ext/ed
25519/donna/ed25519_tor.c:286: undefined reference to `memwipe'
/nix/store/cp1sa3xxvl71cypiinw2c62i5s33chlr-binutils-2.35.1/bin/ld: /build/source/src/qmake_includes/../../build/debug/tego_ui/../libtego/libtego.a(ed25519_tor.o): in function `ed25519_donna_blind_public_key':
/build/source/src/libtego/../extern/tor/src/ext/ed25519/donna/ed25519_tor.c:315: undefined reference to `memwipe'
/nix/store/cp1sa3xxvl71cypiinw2c62i5s33chlr-binutils-2.35.1/bin/ld: /build/source/src/qmake_includes/../../build/debug/tego_ui/../libtego/libtego.a(ed25519_tor.o):/build/source/src/libtego/../extern/tor/src/ext/ed25519/donna/ed25519_tor.c:316: more undefined references to `memwipe' follow
/nix/store/cp1sa3xxvl71cypiinw2c62i5s33chlr-binutils-2.35.1/bin/ld: /build/source/src/qmake_includes/../../build/debug/tego_ui/../libtego/libtego.a(crypto_digest_openssl.o): in function `crypto_digest_get_digest':
/build/source/src/libtego/../extern/tor/src/lib/crypt_ops/crypto_digest_openssl.c:341: undefined reference to `crypto_digest_algorithm_get_length'
/nix/store/cp1sa3xxvl71cypiinw2c62i5s33chlr-binutils-2.35.1/bin/ld: /build/source/src/libtego/../extern/tor/src/lib/crypt_ops/crypto_digest_openssl.c:349: undefined reference to `crypto_digest_algorithm_get_length'
/nix/store/cp1sa3xxvl71cypiinw2c62i5s33chlr-binutils-2.35.1/bin/ld: /build/source/src/libtego/../extern/tor/src/lib/crypt_ops/crypto_digest_openssl.c:393: undefined reference to `memwipe'
/nix/store/cp1sa3xxvl71cypiinw2c62i5s33chlr-binutils-2.35.1/bin/ld: /build/source/src/qmake_includes/../../build/debug/tego_ui/../libtego/libtego.a(crypto_digest_openssl.o): in function `crypto_digest_dup':
/build/source/src/libtego/../extern/tor/src/lib/crypt_ops/crypto_digest_openssl.c:407: undefined reference to `tor_memdup_'
/nix/store/cp1sa3xxvl71cypiinw2c62i5s33chlr-binutils-2.35.1/bin/ld: link errors found, deleting executable `/build/source/build/debug/tego_ui/ricochet-refresh'
collect2: error: ld returned 1 exit status

Using a script to search for definitions of a missing symbol, for example crypto_strongest_rand, I find no definitions:

$ find /tmp/nix-build-ricochet-refresh.drv-37/source/ -exec bash -c 'gcc-nm "{}" | sed -e "s|^|{}|"' \; 2>/dev/null | grep crypto_strongest_rand
/tmp/nix-build-ricochet-refresh.drv-37/source/build/debug/libtego/libtego.a                 U crypto_strongest_rand
/tmp/nix-build-ricochet-refresh.drv-37/source/build/debug/libtego/.obj/ed25519_tor.o                 U crypto_strongest_rand

Looking at https://linux.die.net/man/1/nm , "U" means a symbol is undefined, for a definition there should probably be an entry with something like "T".

So my question is how is this supposed to build/be built? The lack of a symbol suggests that there are object files which I am not building, which should exist. - or that I forgot a dependency somewhere.

cc @pospeselr

morganava commented 3 years ago

This is happening because link-time optimization is disabled. See: https://github.com/blueprint-freespeech/ricochet-refresh/blob/main/src/libtego/source/tor_stubs.cpp

morganava commented 3 years ago

To expand on this, we are using tor's ed25519 code, which unfortunately is fairly tightly integrated into the tor daemon, so has some extra baggage we don't need. The functions that we do call, also live in compilation units with a lot of functionality we do not need. Without link-time optimization enabled, these functions are marked as required by the linker (which you see above) even though they are never actually called.

We can't enable lto on Windows build targets because of an outstanding mingw bug that results in some really interesting runtime failures on x86_64 targets, so the functions are just stubbed out in that tor_stubs.cpp file.

deliciouslytyped commented 3 years ago

Ok, I'll look into enabling LTO again, but IIUC that had it's own issues. So just checking: compiling ricochet-refresh without LTO is not supported.