Skip to content

Commit b358c36

Browse files
authored
Merge pull request #24 from TheBlueMatt/main
Support glibc 2.17 and make exception failures explicit
2 parents 0061ee2 + d464171 commit b358c36

File tree

8 files changed

+630
-4
lines changed

8 files changed

+630
-4
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

java_strings.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,12 @@ def native_c_map_trait(self, struct_name, field_vars, flattened_field_vars, fiel
854854
else:
855855
out_c = out_c + ", " + arg_info.arg_name
856856
out_c = out_c + ");\n"
857+
858+
out_c += "\tif ((*env)->ExceptionCheck(env)) {\n"
859+
out_c += "\t\t(*env)->ExceptionDescribe(env);\n"
860+
out_c += "\t\t(*env)->FatalError(env, \"A Java interface method called from rust threw an exception.\");\n"
861+
out_c += "\t}\n"
862+
857863
if fn_line.ret_ty_info.arg_conv is not None:
858864
out_c += "\t" + fn_line.ret_ty_info.arg_conv.replace("\n", "\n\t") + "\n"
859865
out_c += "\t" + self.deconstruct_jenv().replace("\n", "\n\t").strip() + "\n"

src/main/java/org/ldk/impl/bindings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public VecOrSliceDef(long dataptr, long datalen, long stride) {
4848
static native String get_lib_version_string();
4949

5050
public static String get_ldk_java_bindings_version() {
51-
return "v0.0.98.2";
51+
return "v0.0.98.3";
5252
}
5353
public static native String get_ldk_c_bindings_version();
5454
public static native String get_ldk_version();

src/main/jni/bindings.c

Lines changed: 305 additions & 1 deletion
Large diffs are not rendered by default.

src/main/jni/bindings.c.body

Lines changed: 301 additions & 1 deletion
Large diffs are not rendered by default.
-33.3 KB
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)