Skip to content

Commit 5347510

Browse files
committed
Don't explicitly override __cxa_thread_atexit_impl, rely on LLVM to optimize it out
1 parent 348009c commit 5347510

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

genbindings.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ else
8787
LDK_LIB="$1"/lightning-c-bindings/target/$LDK_TARGET/release/libldk.a
8888
if [ "$IS_MAC" = "false" ]; then
8989
COMPILE="$COMPILE -Wl,--version-script=libcode.version -fuse-ld=lld"
90-
echo "// __cxa_thread_atexit_impl is used to more effeciently cleanup per-thread local storage by rust libstd." >> src/main/jni/bindings.c
91-
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
92-
echo "// Because it is weak-linked on the rust side, we should be able to simply define it explicitly here, forcing rust to use the fallback." >> src/main/jni/bindings.c
93-
echo "void *__cxa_thread_atexit_impl = NULL;" >> src/main/jni/bindings.c
94-
# Note that the above is not sufficient. For some reason involving ancient dark magic and
95-
# haunted code segments, overriding the weak symbol only impacts sites which *call* the
96-
# symbol in question, not sites which *compare with* the symbol in question.
90+
# __cxa_thread_atexit_impl is used to more effeciently cleanup per-thread local storage by rust libstd.
91+
# However, it is not available on glibc versions 2.17 or earlier, and rust libstd has a null-check and
92+
# fallback in case it is missing.
93+
# Because it is weak-linked on the rust side, we should be able to simply define it
94+
# explicitly, forcing rust to use the fallback. However, for some reason involving ancient
95+
# dark magic and haunted code segments, overriding the weak symbol only impacts sites which
96+
# *call* the symbol in question, not sites which *compare with* the symbol in question.
9797
# This means that the NULL check in rust's libstd will always think the function is
9898
# callable while the function which is called ends up being NULL (leading to a jmp to the
9999
# zero page and a quick SEGFAULT).
@@ -104,6 +104,9 @@ else
104104
# After exhausting nearly every flag documented in lld, the only reliable method appears
105105
# to be editing the LDK binary. Luckily, LLVM's tooling makes this rather easy as we can
106106
# disassemble it into very readable code, edit it, and then reassemble it.
107+
# Note that if we do so we don't have to bother overriding the actual call, LLVM should
108+
# optimize it away, which also provides a good check that there isn't anything actually
109+
# relying on it elsewhere.
107110
[ ! -f "$1"/lightning-c-bindings/target/$LDK_TARGET/release/libldk.a ] && exit 1
108111
if [ "$(ar t "$1"/lightning-c-bindings/target/$LDK_TARGET/release/libldk.a | grep -v "\.o$" || echo)" != "" ]; then
109112
echo "Archive contained non-object files!"

0 commit comments

Comments
 (0)