Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: Fail to looking for symbols in BoringSSL #13523

Closed
pkropachev opened this issue May 3, 2024 · 6 comments
Closed

CMake: Fail to looking for symbols in BoringSSL #13523

pkropachev opened this issue May 3, 2024 · 6 comments
Labels
cmake HTTP/3 h3 or quic related not-a-curl-bug This is not a bug in curl

Comments

@pkropachev
Copy link

I did this

I'm trying to build libcurl with Quiche and BoringSSL using CMake.

BoringSSL and Quiche are built with the following commands:

cd boringssl
cmake -Bbuild -DCMAKE_POSITION_INDEPENDENT_CODE=on
cmake --build build -- -j8
mkdir lib
ln -s ../build/ssl/libssl.a ./lib/
ln -s ../build/crypto/libcrypto.a ./lib/
cd quiche
QUICHE_BSSL_PATH="$PWD/../boringssl" cargo build --package quiche --release --features ffi,pkg-config-meta,qlog

So, lib directory with libssl.a and libcrypto.a is located in root tree of boringssl directory.

During attempt to libcurl using the following command:

cd curl
cmake -Bbuild -DOPENSSL_ROOT_DIR=$PWD/../boringssl/ \
    -DUSE_QUICHE=ON \
    -DQUICHE_LIBRARY=$PWD/../quiche/target/release/libquiche.a \
    -DQUICHE_INCLUDE_DIR=$PWD/../quiche/quiche/include

I get the error:

-- Using CMake version 3.29.2
-- The C compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- curl version=[8.8.0-DEV]
-- Performing Test OPT_Wdouble_promotion
-- Performing Test OPT_Wdouble_promotion - Success
-- Performing Test OPT_Wenum_conversion
-- Performing Test OPT_Wenum_conversion - Failed
-- Performing Test OPT_Wpragmas
-- Performing Test OPT_Wpragmas - Success
-- Performing Test OPT_Wunused_const_variable
-- Performing Test OPT_Wunused_const_variable - Success
-- Picky compiler options: -W -Wall -pedantic -Wbad-function-cast -Wconversion -Winline -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wno-long-long -Wno-multichar -Wpointer-arith -Wshadow -Wsign-compare -Wundef -Wunused -Wwrite-strings -Waddress -Wattributes -Wcast-align -Wdeclaration-after-statement -Wdiv-by-zero -Wempty-body -Wendif-labels -Wfloat-equal -Wformat-security -Wignored-qualifiers -Wmissing-field-initializers -Wmissing-noreturn -Wno-format-nonliteral -Wno-system-headers -Wold-style-definition -Wredundant-decls -Wsign-conversion -Wno-error=sign-conversion -Wstrict-prototypes -Wtype-limits -Wunreachable-code -Wunused-parameter -Wvla -Wclobbered -Wmissing-parameter-type -Wold-style-declaration -Wstrict-aliasing=3 -Wtrampolines -Wformat=2 -Warray-bounds=2 -ftree-vrp -Wduplicated-cond -Wnull-dereference -fdelete-null-pointer-checks -Wshift-negative-value -Wshift-overflow=2 -Walloc-zero -Wduplicated-branches -Wformat-overflow=2 -Wformat-truncation=2 -Wimplicit-fallthrough -Wrestrict -Wdouble-promotion -Wpragmas -Wunused-const-variable
-- Performing Test HAVE_SOCKADDR_IN6_SIN6_ADDR
-- Performing Test HAVE_SOCKADDR_IN6_SIN6_ADDR - Success
-- Performing Test HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
-- Performing Test HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID - Success
-- Found Perl: /usr/bin/perl (found version "5.30.0")
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Looking for connect in socket
-- Looking for connect in socket - not found
-- Looking for gethostname
-- Looking for gethostname - found
-- Found OpenSSL: /home/pk/projects/sandbox/ssl/boringssl/lib/libcrypto.a (found version "")
-- Looking for OPENSSL_IS_BORINGSSL
-- Looking for OPENSSL_IS_BORINGSSL - found
-- Looking for OPENSSL_IS_AWSLC
-- Looking for OPENSSL_IS_AWSLC - not found
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11")
-- Looking for SSL_set0_wbio
-- Looking for SSL_set0_wbio - not found
-- Looking for SSL_CTX_set_srp_username
-- Looking for SSL_CTX_set_srp_username - not found
-- Checking for one of the modules 'quiche'
-- Found QUICHE: /home/pk/projects/sandbox/ssl/quiche/target/release/libquiche.a
-- Looking for SSL_CTX_set_quic_method
-- Looking for SSL_CTX_set_quic_method - not found
CMake Error at CMakeLists.txt:645 (message):
  QUIC support is missing in OpenSSL fork.  Try setting -DOPENSSL_ROOT_DIR
Call Stack (most recent call first):
  CMakeLists.txt:724 (openssl_check_quic)

It looks like check_symbol_exists from openssl_check_symbol_exists macro can't find required symbols. Values of CMAKE_REQUIRED_INCLUDES and CMAKE_REQUIRED_LIBRARIES look correct (valid path to headers and libraries). Maybe this is due to static libraries of BoringSSL are used.

I expected the following

Required symbols are found in specified version of BoringSSL.

curl/libcurl version

curl 8.8.0-DEV (master branch)

operating system

Ubuntu 20.04 LTS
Linux kwx1252784oftdls 5.13.0-52-generic #59~20.04.1-Ubuntu SMP Thu Jun 16 21:21:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

@bagder
Copy link
Member

bagder commented May 3, 2024

Which BoringSSL version is this? Note that quiche is not compatible with their latest versions atm: cloudflare/quiche#1761

@bagder bagder added cmake HTTP/3 h3 or quic related labels May 3, 2024
@pkropachev
Copy link
Author

pkropachev commented May 3, 2024

Ah. I use BoringSSL from master branch. Let me check with version of BoringSSL from Quiche.

@pkropachev
Copy link
Author

Daniel, you're right. All is ok in case using BoringSSL version used by Quiche (commit f1c7534 in deps). Perhaps it also works with more newer versions of BorringSSL, but not with the current master branch.

In my case steps look like the following.

BoringSSL (commit f1c7534):

cd boringssl/src
cmake -Bbuild \
    -DCMAKE_C_FLAGS="-ffunction-sections -fdata-sections -fPIC -m64" \
    -DCMAKE_CXX_FLAGS="-ffunction-sections -fdata-sections -fPIC -m64" \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo .. 
cmake --build build --config RelWithDebInfo -- -j8
mkdir lib
ln -s ../build/libssl.a ./lib/
ln -s ../build/libcrypto.a ./lib/

Quiche (0.21.0):

cd quiche
QUICHE_BSSL_PATH=$PWD/../boringssl/src cargo build --package quiche --release --features ffi,pkg-config-meta,qlog

CMake configuration for libcurl looks correct now:

cd curl
cmake -Bbuild \
    -DOPENSSL_ROOT_DIR=$PWD/../boringssl/src
    -DUSE_QUICHE=ON \
    -DQUICHE_LIBRARY=$PWD/../quiche/target/release/libquiche.a \
    -DQUICHE_INCLUDE_DIR=$PWD/../quiche/quiche/include
cmake --build build -- -j8
...
-- Found OpenSSL: /home/pk/projects/sandbox/ssl/boringssl/src/lib/libcrypto.a (found version "")
-- Looking for OPENSSL_IS_BORINGSSL
-- Looking for OPENSSL_IS_BORINGSSL - found
-- Looking for OPENSSL_IS_AWSLC
-- Looking for OPENSSL_IS_AWSLC - not found
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11")
-- Looking for SSL_set0_wbio
-- Looking for SSL_set0_wbio - found
-- Looking for SSL_CTX_set_srp_username
-- Looking for SSL_CTX_set_srp_username - not found
-- Checking for one of the modules 'quiche'
-- Found QUICHE: /home/pk/projects/sandbox/ssl/quiche/target/release/libquiche.a
-- Looking for SSL_CTX_set_quic_method
-- Looking for SSL_CTX_set_quic_method - found
...

libcurl is built correct, but in the same time I faced with problem during linking curl tool.

...
[ 76%] Linking C shared library libcurl.so
...
[100%] Building C object src/CMakeFiles/curl.dir/__/lib/warnless.c.o
[100%] Linking C executable curl
/usr/bin/ld: ../lib/libcurl.so.4.8.0: undefined reference to `dlsym'
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/curl.dir/build.make:898: src/curl] Error 1
make[1]: *** [CMakeFiles/Makefile2:709: src/CMakeFiles/curl.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

Any suggestions what can be wrong?

@bagder bagder added the not-a-curl-bug This is not a bug in curl label May 3, 2024
@bagder
Copy link
Member

bagder commented May 3, 2024

/usr/bin/ld: ../lib/libcurl.so.4.8.0: undefined reference to `dlsym'

Sounds like you might need to tell it to use -ldl ?

@pkropachev
Copy link
Author

Yep, in my case the problem was solved by adding CMAKE_EXE_LINKER_FLAGS="-Wl,--no-as-needed -ldl" for cmake.

cd curl
cmake -Bbuild \
    -DOPENSSL_ROOT_DIR=$PWD/../boringssl/src \
    -DUSE_QUICHE=ON \
    -DQUICHE_LIBRARY=$PWD/../quiche/target/release/libquiche.a \
    -DQUICHE_INCLUDE_DIR=$PWD/../quiche/quiche/include \
    -DCMAKE_EXE_LINKER_FLAGS="-Wl,--no-as-needed -ldl"
cmake --build build -- -j8

@pkropachev
Copy link
Author

Regarding the cloudflare/quiche#1761 issue.

I built curl with BoringSSL from master branch by adding -lstdc++.

cd curl
cmake -Bbuild \
    -DOPENSSL_ROOT_DIR=$PWD/../boringssl \
    -DCMAKE_EXE_LINKER_FLAGS="-Wl,--no-as-needed -ldl -lstdc++"
cmake --build build --target libcurl_shared curl -- -j8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake HTTP/3 h3 or quic related not-a-curl-bug This is not a bug in curl
Development

No branches or pull requests

2 participants