Skip to content

make check fails with --disable-static #1056

Closed

Description

@xry111

Describe the bug

make check fails with --disable-static.

To Reproduce

./configure --prefix=/usr --disable-static && make && make check

It produces:

/usr/bin/ld: test_auth_keyboard_info_request.o: in function `main':
test_auth_keyboard_info_request.c:(.text.startup+0xec): undefined reference to `userauth_keyboard_interactive_decode_info_request'
/usr/bin/ld: test_auth_keyboard_info_request.c:(.text.startup+0x201): undefined reference to `userauth_keyboard_interactive_decode_info_request'
collect2: error: ld returned 1 exit status

Expected behavior

Test succeeds.

Version:

  • OS and version: Linux (Linux From Scratch)
  • libssh2 version: 1.11.0
  • crypto backend and version: OpenSSL

Additional context

It looks like the reason is userauth_keyboard_interactive_decode_info_request not exported in the shared library because we are linking libssh2.so with -export-symbols-regex '^libssh2_.*'.

Activity

  1. willco007 commented on May 30, 2023

    @willco007
    Member

    This function shouldn't be exported, but also should be available for use in unit tests. Hum.

  2. vszakats commented on May 30, 2023

    @vszakats
    Member

    One (obvious) workaround is to not build the tests (also with --disable-tests, new in 1.11.0) if omitting the static lib, or build the static lib when needing the tests.

    Or try CMake (or Makefile.mk), which will exclude these specific tests when not building the static lib. Probably the same could be implemented for autotools.

  3. vszakats commented on May 30, 2023

    @vszakats
    Member
  4. kloczek commented on May 31, 2023

    @kloczek

    I have more missing symbols with --disable-static with LTO

    [tkloczko@pers-jacek libssh2-libssh2-1.11.0]$ make -k check V=1
    
    [..]
    
    bin/sh ../libtool  --tag=CC   --mode=link /usr/bin/gcc  -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -static -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1 -o test_hostkey test_hostkey.o librunner.la ../src/libssh2.la -L/usr/lib64 -lssl -L/usr/lib64 -lcrypto
    libtool: link: /usr/bin/gcc -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z -Wl,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1 -o test_hostkey test_hostkey.o  ./.libs/librunner.a -L/usr/lib64 ../src/.libs/libssh2.so -lz -lssl -lcrypto -Wl,-rpath -Wl,/home/tkloczko/rpmbuild/BUILD/libssh2-libssh2-1.11.0/src/.libs
    /usr/bin/ld: /tmp/cccXDQtY.lto.o: in function `main':
    /home/tkloczko/rpmbuild/BUILD/libssh2-libssh2-1.11.0/tests/test_hostkey.c:43: undefined reference to `_libssh2_base64_decode'
    /usr/bin/ld: /tmp/cccXDQtY.lto.o:/home/tkloczko/rpmbuild/BUILD/libssh2-libssh2-1.11.0/tests/test_hostkey.c:33: undefined reference to `_libssh2_base64_decode'
    /usr/bin/ld: /tmp/cccXDQtY.lto.o:/home/tkloczko/rpmbuild/BUILD/libssh2-libssh2-1.11.0/tests/test_hostkey.c:38: undefined reference to `_libssh2_base64_decode'
    collect2: error: ld returned 1 exit status
    make[3]: *** [Makefile:1041: test_hostkey] Error 1
    make[3]: 'test_hostkey_hash' is up to date.
    make[3]: 'test_read' is up to date.
    /bin/sh ../libtool  --tag=CC   --mode=link /usr/bin/gcc  -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -static -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1 -o test_simple test_simple.o librunner.la ../src/libssh2.la -L/usr/lib64 -lssl -L/usr/lib64 -lcrypto
    libtool: link: /usr/bin/gcc -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z -Wl,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1 -o test_simple test_simple.o  ./.libs/librunner.a -L/usr/lib64 ../src/.libs/libssh2.so -lz -lssl -lcrypto -Wl,-rpath -Wl,/home/tkloczko/rpmbuild/BUILD/libssh2-libssh2-1.11.0/src/.libs
    /usr/bin/ld: /tmp/ccjkWgZc.lto.o: in function `main':
    /home/tkloczko/rpmbuild/BUILD/libssh2-libssh2-1.11.0/tests/<artificial>:51: undefined reference to `_libssh2_base64_decode'
    collect2: error: ld returned 1 exit status
  5. vszakats commented on May 31, 2023

    @vszakats
    Member

    These are the tests that require the static lib, to access internal functions:

    # Programs of the above that use internal libssh2 functions so they need
    # to be statically linked against libssh2
    TESTS_WITH_LIB_STATIC = \
    test_auth_keyboard_info_request \
    test_hostkey \
    test_simple

  6. xry111 commented on May 31, 2023

    @xry111
    ContributorAuthor

    I have more missing symbols with --disable-static with LTO

    [tkloczko@pers-jacek libssh2-libssh2-1.11.0]$ make -k check V=1
    
    [..]
    
    bin/sh ../libtool  --tag=CC   --mode=link /usr/bin/gcc  -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -static -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1 -o test_hostkey test_hostkey.o librunner.la ../src/libssh2.la -L/usr/lib64 -lssl -L/usr/lib64 -lcrypto
    libtool: link: /usr/bin/gcc -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z -Wl,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1 -o test_hostkey test_hostkey.o  ./.libs/librunner.a -L/usr/lib64 ../src/.libs/libssh2.so -lz -lssl -lcrypto -Wl,-rpath -Wl,/home/tkloczko/rpmbuild/BUILD/libssh2-libssh2-1.11.0/src/.libs
    /usr/bin/ld: /tmp/cccXDQtY.lto.o: in function `main':
    /home/tkloczko/rpmbuild/BUILD/libssh2-libssh2-1.11.0/tests/test_hostkey.c:43: undefined reference to `_libssh2_base64_decode'
    /usr/bin/ld: /tmp/cccXDQtY.lto.o:/home/tkloczko/rpmbuild/BUILD/libssh2-libssh2-1.11.0/tests/test_hostkey.c:33: undefined reference to `_libssh2_base64_decode'
    /usr/bin/ld: /tmp/cccXDQtY.lto.o:/home/tkloczko/rpmbuild/BUILD/libssh2-libssh2-1.11.0/tests/test_hostkey.c:38: undefined reference to `_libssh2_base64_decode'
    collect2: error: ld returned 1 exit status
    make[3]: *** [Makefile:1041: test_hostkey] Error 1
    make[3]: 'test_hostkey_hash' is up to date.
    make[3]: 'test_read' is up to date.
    /bin/sh ../libtool  --tag=CC   --mode=link /usr/bin/gcc  -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -static -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1 -o test_simple test_simple.o librunner.la ../src/libssh2.la -L/usr/lib64 -lssl -L/usr/lib64 -lcrypto
    libtool: link: /usr/bin/gcc -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z -Wl,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1 -o test_simple test_simple.o  ./.libs/librunner.a -L/usr/lib64 ../src/.libs/libssh2.so -lz -lssl -lcrypto -Wl,-rpath -Wl,/home/tkloczko/rpmbuild/BUILD/libssh2-libssh2-1.11.0/src/.libs
    /usr/bin/ld: /tmp/ccjkWgZc.lto.o: in function `main':
    /home/tkloczko/rpmbuild/BUILD/libssh2-libssh2-1.11.0/tests/<artificial>:51: undefined reference to `_libssh2_base64_decode'
    collect2: error: ld returned 1 exit status
    

    It just does not work, no matter if LTO is used.

  7. added 2 commits that reference this issue on May 31, 2023
    1c9f514
    b95e757
  8. kloczek commented on May 31, 2023

    @kloczek

    These are the tests that require the static lib, to access internal functions:

    # Programs of the above that use internal libssh2 functions so they need
    # to be statically linked against libssh2
    TESTS_WITH_LIB_STATIC = \
    test_auth_keyboard_info_request \
    test_hostkey \
    test_simple

    So why not form static library used only on linking test units executables? 🤔

  9. vszakats commented on May 31, 2023

    @vszakats
    Member

    Is that not the same as building the static lib itself?

  10. added a commit that references this issue on May 31, 2023
    572c57c
  11. BrianInglis commented on Jun 3, 2023

    @BrianInglis

    Perhaps --disable-static should disable the static lib install, and/or build a static lib with only those modules?

  12. vszakats commented on Jun 3, 2023

    @vszakats
    Member

    Disabling install is another option (though my autotools skills are too short to implement it). The current solution has the advantage that it works the same way for all build systems. Also with CMake, building static libs doesn't come free (it's a separate build pass) and in some envs an install phase might not be used at all, so disabling it completely can have some advantages.

    I think once we have a more substantial amount of tests relying on internal functions, we might switch to always building the static lib to avoid skipping tests.

  13. added a commit that references this issue on Jul 16, 2023
    693c969
  14. added a commit that references this issue on Dec 4, 2023
  15. added a commit that references this issue on Jul 14, 2024
    989816b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions