Upon developing a basic program to my horror a cri...
# kotlin-native
n
Upon developing a basic program to my horror a critical bug with linking a C library occurs when using Kotlin 1.5.0 (doesn't affect Kotlin 1.4.31):
Copy code
> Task :linkRandom_numDebugExecutableLinuxX64 FAILED
3 actionable tasks: 3 executed
e: /home/napperley/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/bin/ld.gold invocation reported errors

The /home/napperley/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/bin/ld.gold command returned non-zero exit code: 1.
output:
/home/napperley/libsodium-1.0.18/lib/libsodium.so: error: undefined reference to 'getentropy', version 'GLIBC_2.25'
/home/napperley/libsodium-1.0.18/lib/libsodium.so: error: undefined reference to '__explicit_bzero_chk', version 'GLIBC_2.25'
/home/napperley/libsodium-1.0.18/lib/libsodium.so: error: undefined reference to 'getrandom', version 'GLIBC_2.25'
I have tried nearly all forms of C library linking (except for statically linking the user ver of the libsodium lib), which includes the following: • Statically linking the system ver of the lib • Dynamically linking the system ver of the lib • Dynamically linking the user ver of the lib
👀 1
😱 3
s
Actually, your code was working because of incorrect behavior in lld 8 (which is used in Kotlin/Native 1.4.32 and earlier): it was not checking symbol's version. In 1.5.0 we switched to ld.gold and its behavior is more strict and correct. Kotlin/Native uses sysroot that is based on glibc-2.19 (you can see it in /home/napperley/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/bin/ld.gold), while your version of libsodium was build against glibc 2.25 (/home/napperley/libsodium-1.0.18/lib/libsodium.so: error: undefined reference to 'getrandom', version *'GLIBC_2.25*'). So you can try either recompile sodium against earlier version of glibc, or use the following workaround (which should return old incorrect bebavior):
Copy code
-Xoverride-konan-properties="linker.linux_x64=/home/napperley/.konan/dependencies/clang-llvm-8.0.0-linux-x86-64/bin/ld.lld"
Related discussion: https://youtrack.jetbrains.com/issue/KT-43501
👍 1
Still, we should be more explicit about our sysroot version in documentation.
👍 1
n
Ubuntu, and Ubuntu based distros (eg Linux Mint) tend to be finicky ( https://unix.stackexchange.com/questions/12522/installing-two-glibc-alongside-in-debian-ubuntu ), and laborious ( https://stackoverflow.com/questions/2856438/how-can-i-link-to-a-specific-glibc-version ) with glibc versioning, which wouldn't make using an earlier version of glibc a viable option.
Does this mean the new linker will accept any GLIBC version up to v2.19?
Can the override be applied in the build file, and if so where?