Search code examples
c++linuxrustopensslmusl

undefined reference to `sigsetjmp' in rust static library musl build with openssl


The previous question that gives a bit of background to this one: undefined reference to symbol 'clock_gettime@@GLIBC_2.4 In rust static library for musl target

Now when compiling the c++ program i get the error:

/mnt/HDD/Project/inkbox-build/inkbox/compiled-binaries/arm-kobo-linux-gnueabihf/bin/../lib/gcc/arm-kobo-linux-gnueabihf/11.2.0/../../../../arm-kobo-linux-gnueabihf/bin/ld.bfd: /mnt/HDD/Project/inkbox-build/inkbox/inkbox-toreader/libs/Libretranslate-rs-to-cpp/lib//libLibretranslate_rs_to_cpp.a(armcap.o): in function `OPENSSL_cpuid_setup':
armcap.c:(.text.startup.OPENSSL_cpuid_setup+0xa2): undefined reference to `sigsetjmp'
/mnt/HDD/Project/inkbox-build/inkbox/compiled-binaries/arm-kobo-linux-gnueabihf/bin/../lib/gcc/arm-kobo-linux-gnueabihf/11.2.0/../../../../arm-kobo-linux-gnueabihf/bin/ld.bfd: armcap.c:(.text.startup.OPENSSL_cpuid_setup+0xae): undefined reference to `sigsetjmp'
/mnt/HDD/Project/inkbox-build/inkbox/compiled-binaries/arm-kobo-linux-gnueabihf/bin/../lib/gcc/arm-kobo-linux-gnueabihf/11.2.0/../../../../arm-kobo-linux-gnueabihf/bin/ld.bfd: armcap.c:(.text.startup.OPENSSL_cpuid_setup+0xf4): undefined reference to `sigsetjmp'
/mnt/HDD/Project/inkbox-build/inkbox/compiled-binaries/arm-kobo-linux-gnueabihf/bin/../lib/gcc/arm-kobo-linux-gnueabihf/11.2.0/../../../../arm-kobo-linux-gnueabihf/bin/ld.bfd: armcap.c:(.text.startup.OPENSSL_cpuid_setup+0x100): undefined reference to `sigsetjmp'
/mnt/HDD/Project/inkbox-build/inkbox/compiled-binaries/arm-kobo-linux-gnueabihf/bin/../lib/gcc/arm-kobo-linux-gnueabihf/11.2.0/../../../../arm-kobo-linux-gnueabihf/bin/ld.bfd: armcap.c:(.text.startup.OPENSSL_cpuid_setup+0x10c): undefined reference to `sigsetjmp'
/mnt/HDD/Project/inkbox-build/inkbox/compiled-binaries/arm-kobo-linux-gnueabihf/bin/../lib/gcc/arm-kobo-linux-gnueabihf/11.2.0/../../../../arm-kobo-linux-gnueabihf/bin/ld.bfd: /mnt/HDD/Project/inkbox-build/inkbox/inkbox-toreader/libs/Libretranslate-rs-to-cpp/lib//libLibretranslate_rs_to_cpp.a(armcap.o):armcap.c:(.text.startup.OPENSSL_cpuid_setup+0x118): more undefined references to `sigsetjmp' follow
collect2: error: ld returned 1 exit status
make: *** [Makefile:505: build/inkbox] Error 1

The only thing i could find was: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59188

Specifically from there:

glibc (at least the 2.17 I have around) doesn't have sigsetjmp function at all,
it only conditionally has sigsetjmp as a macro

So what do I do with that? I don't even have such an old GLIBC

I was able to compile the rust library even with zig with a local not vendored openssl build:

OPENSSL_DIR=/home/build/inkbox/openssl/ cargo zigbuild --target armv7-unknown-linux-musleabihf

but the issue remains the same


Solution

  • glibc (in past at least) did not have the function sigsetjmp. It had a macro defined conditionally like

    #ifdef __USE_POSIX
    # define sigsetjmp(env, savemask) __sigsetjmp (env, savemask)
    #endif
    

    You either do not #include <setjmp.h> somewhere and the compiler uses the implicitly declared int sigsetjmp(), or the macro __USE_POSIX is not defined while compiling the C code in the file armcap.c.

    If that does not fix the issue, you can define your own int sigsetjmp(sigjmp_buf env, int savemask) like in this topic: undefined reference to `siglongjmp' error when compiling android cocos2dx project for x86 architecture.