summaryrefslogtreecommitdiff
path: root/rts
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2020-09-30 23:41:40 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-10-12 19:16:40 -0400
commit82a89df72fbf5da437f52a1375bf1d6ded1c61c5 (patch)
treead599f7e613ce912a4a0b8e14a203e3d441469a2 /rts
parent9257abebdf4904407f607814c4cfa27002d404e8 (diff)
downloadhaskell-82a89df72fbf5da437f52a1375bf1d6ded1c61c5.tar.gz
rts/linker: Define _DYNAMIC when necessary
Usually the dynamic linker would define _DYNAMIC. However, when dynamic linking is not supported (e.g. on musl) it is safe to define it to be NULL.
Diffstat (limited to 'rts')
-rw-r--r--rts/Linker.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/rts/Linker.c b/rts/Linker.c
index d297f3a8ff..b31142e8e4 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -870,7 +870,19 @@ SymbolAddr* lookupDependentSymbol (SymbolName* lbl, ObjectCode *dependent)
IF_DEBUG(linker, debugBelch("lookupSymbol: symbol '%s' not found, trying dlsym\n", lbl));
# if defined(OBJFORMAT_ELF)
- return internal_dlsym(lbl);
+ SymbolAddr *ret = internal_dlsym(lbl);
+
+ // Generally the dynamic linker would define _DYNAMIC, which is
+ // supposed to point to various bits of dynamic linker state (see
+ // [1]). However, if dynamic linking isn't supported (e.g. in the case
+ // of musl) then we can safely declare that it is NULL.
+ //
+ // [1] https://wiki.gentoo.org/wiki/Hardened/Introduction_to_Position_Independent_Code
+ if (ret == NULL && strcmp(lbl, "_DYNAMIC") == 0) {
+ static void *RTS_DYNAMIC = NULL;
+ ret = (SymbolAddr *) &RTS_DYNAMIC;
+ }
+ return ret;
# elif defined(OBJFORMAT_MACHO)
/* HACK: On OS X, all symbols are prefixed with an underscore.