From e687e5ba74781a712eec153b91a998f1c9ba0d7e Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sat, 8 Jan 2022 05:55:32 -0700 Subject: [PATCH] LibCrypt: Link the SHA2 hash implementation into LibCrypt privately Previously, we linked LibCrypt against LibCrypto. This creates a circular symbol dependency between LibCore, LibCrypto and LibCrypt. LibCrypto uses Core::DateTime, LibCrypt uses Crypto::SHA2, and LibCore uses crypt in Core::Account. The GNU toolchain massages the DT_NEEDED lines of each library and applications that use each library such that the Loader finds all the symbols as necessary. However, when using the Clang toolchain, the circular library dependency is not as tolerated. We get a symbol not found error in the Loader at runtime, and the app in question crashes. Now, we build the SHA2.cpp implementation file into LibCrypt using an object library and `-fvisibility=hidden -fvisibility-hidden-inlines`. This adds the implementation in a way that only creates STB_LOCAL symbols and should avoid nasty ODR problems in the future. An alternative approach to resolving this dependency would be to move Core::DateTime to AK, or to make Crypto::ASN1::parse_utc_date return a struct tm instead of a Core::DateTime. One of those approaches to remove the LibCore dependency from LibCrypto should probabably be investigated further in the future. The net effect of removing this circular library dependency is that one can now build and run the python3 port with the Clang toolchain :^) --- Userland/Libraries/LibCrypt/CMakeLists.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibCrypt/CMakeLists.txt b/Userland/Libraries/LibCrypt/CMakeLists.txt index f24d3f318af..4f9ea904471 100644 --- a/Userland/Libraries/LibCrypt/CMakeLists.txt +++ b/Userland/Libraries/LibCrypt/CMakeLists.txt @@ -1,6 +1,14 @@ + +# HACK ALERT! +# To avoid a circular dependency chain with LibCrypt --> LibCrypto --> LibCore --> LibCrypt +# We include the SHA2 implementation from LibCrypto here manually +add_library(LibCryptSHA2 OBJECT ../LibCrypto/Hash/SHA2.cpp) +set_target_properties(LibCryptSHA2 PROPERTIES CXX_VISIBILITY_PRESET hidden) +set_target_properties(LibCryptSHA2 PROPERTIES VISIBILITY_INLINES_HIDDEN ON) + set(SOURCES crypt.cpp ) serenity_libc(LibCrypt crypt) -target_link_libraries(LibCrypt LibC LibCrypto) +target_link_libraries(LibCrypt LibC LibCryptSHA2)