Skip to content

Commit 38853aa

Browse files
committed
Support glibc versions prior to 2.18 for linux builds
1 parent a442b85 commit 38853aa

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

genbindings.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,24 @@ if [ "$3" = "true" ]; then
7878
[ "$IS_MAC" = "false" ] && COMPILE="$COMPILE -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,reallocarray -Wl,-wrap,malloc -Wl,-wrap,free"
7979
$COMPILE -o liblightningjni_debug$LDK_TARGET_SUFFIX.so -g -fsanitize=address -shared-libasan -rdynamic -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c "$1"/lightning-c-bindings/target/$LDK_TARGET/debug/libldk.a -lm
8080
else
81-
[ "$IS_MAC" = "false" ] && COMPILE="$COMPILE -Wl,--version-script=libcode.version -fuse-ld=lld"
81+
if [ "$IS_MAC" = "false" ]; then
82+
COMPILE="$COMPILE -Wl,--version-script=libcode.version -fuse-ld=lld"
83+
echo "// __cxa_thread_atexit_impl is used to more effeciently cleanup per-thread local storage by rust libstd." >> src/main/jni/bindings.c
84+
echo "// However, it is not available on glibc versions 2.17 or earlier, and rust libstd has a null-check and fallback in case it is missing." >> src/main/jni/bindings.c
85+
echo "// Because it is weak-linked on the rust side, we can simply define it explicitly here, forcing rust to use the fallback." >> src/main/jni/bindings.c
86+
echo "void *__cxa_thread_atexit_impl = NULL;" >> src/main/jni/bindings.c
87+
fi
8288
$COMPILE -o liblightningjni_release$LDK_TARGET_SUFFIX.so -flto -O3 -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c "$1"/lightning-c-bindings/target/$LDK_TARGET/release/libldk.a
89+
if [ "$IS_MAC" = "false" ]; then
90+
set +e # grep exits with 1 if no lines were left, which is our success condition
91+
GLIBC_SYMBS="$(objdump -T liblightningjni_release$LDK_TARGET_SUFFIX.so | grep GLIBC_ | grep -v "GLIBC_2\.2\." | grep -v "GLIBC_2\.3\(\.\| \)" | grep -v "GLIBC_2.\(14\|17\) ")"
92+
set -e
93+
if [ "$GLIBC_SYMBS" != "" ]; then
94+
echo "Unexpected glibc version dependency! Some users need glibc 2.17 support, symbols for newer glibcs cannot be included."
95+
echo "$GLIBC_SYMBS"
96+
exit 1
97+
fi
98+
fi
8399
if [ "$LDK_TARGET_SUFFIX" != "" ]; then
84100
# Copy to JNI native directory for inclusion in JARs
85101
cp liblightningjni_release$LDK_TARGET_SUFFIX.so src/main/resources/liblightningjni$LDK_TARGET_SUFFIX.nativelib

0 commit comments

Comments
 (0)