randombit / botan

Cryptography Toolkit
https://botan.randombit.net
BSD 2-Clause "Simplified" License
2.59k stars 568 forks source link

Build failure caused by incorrect library paths order #2496

Closed AMDmi3 closed 4 years ago

AMDmi3 commented 4 years ago

botan2 build system has a problem, which leads to system library paths precede local ones. If an [older] copy of botan2 is installed in the system, this leads to older botan2 libraries from that installation to be linked to newly build botan2 code which leads to build failure if the versions are incompatible. This leads, for instance, to inability to update botan2 from 2.15 to 2.17.1 in FreeBSD.

Full build log: https://bz-attachments.freebsd.org/attachment.cgi?id=219640

Relevant excerpt:

c++ -L/usr/local/lib -fstack-protector -pthread build/obj/cli/argon2.o build/obj/cli/asn1.o build/obj/cli/bcrypt.o build/obj/cli/cc_enc.o build/obj/cli/cli.o build/obj/cli/cli_rng.o build/obj/cli/codec.o build/obj/cli/compress.o build/obj/cli/encryption.o build/obj/cli/entropy.o build/obj/cli/hash.o build/obj/cli/hmac.o build/obj/cli/main.o build/obj/cli/math.o build/obj/cli/pbkdf.o build/obj/cli/pk_crypt.o build/obj/cli/psk.o build/obj/cli/pubkey.o build/obj/cli/roughtime.o build/obj/cli/sandbox.o build/obj/cli/speed.o build/obj/cli/timing_tests.o build/obj/cli/tls_client.o build/obj/cli/tls_http_server.o build/obj/cli/tls_proxy.o build/obj/cli/tls_server.o build/obj/cli/tls_utils.o build/obj/cli/tss.o build/obj/cli/utils.o build/obj/cli/x509.o -pthread  -fstack-protector-strong  -L. -lbotan-2 -lboost_system -lbz2 -lcrypto -llzma -lz -o botan
ld: error: undefined symbol: Botan::Stateful_RNG::add_entropy(unsigned char const*, unsigned long)

As you can see, -L/usr/local/lib comes before -L., which leads to an attempt to link with older library. This should be fixed.

AMDmi3 commented 4 years ago

Note that FreeBSD port uses --with-external-includedir and --with-external-libdir flags. Though there seem to be no problems with includes (system path is added after local ones), external libdir is appended right to link command, which doesn't seem to be correct.

randombit commented 4 years ago

Thanks for the report. I think this only hits with --with-external-libdir is used which was why it has been missed so far. Can you try applying 639a5c4515a3 and see if that resolves the issue for you?

AMDmi3 commented 4 years ago

This results with the following link command, which is now correct. Thanks!

c++ -fstack-protector -pthread build/obj/cli/argon2.o build/obj/cli/asn1.o build/obj/cli/bcrypt.o build/obj/cli/cc_enc.o build/obj/cli/cli.o build/obj/cli/cli_rng.o build/obj/cli/codec.o build/obj/cli/compress.o build/obj/cli/encryption.o build/obj/cli/entropy.o build/obj/cli/hash.o build/obj/cli/hmac.o build/obj/cli/main.o build/obj/cli/math.o build/obj/cli/pbkdf.o build/obj/cli/pk_crypt.o build/obj/cli/psk.o build/obj/cli/pubkey.o build/obj/cli/roughtime.o build/obj/cli/sandbox.o build/obj/cli/speed.o build/obj/cli/timing_tests.o build/obj/cli/tls_client.o build/obj/cli/tls_http_server.o build/obj/cli/tls_proxy.o build/obj/cli/tls_server.o build/obj/cli/tls_utils.o build/obj/cli/tss.o build/obj/cli/utils.o build/obj/cli/x509.o -pthread  -fstack-protector-strong  -L. -lbotan-2 -L/usr/local/lib -lboost_system -lbz2 -lcrypto -llzma -lz -o botan