summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2020-11-21 11:08:57 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-11-30 19:48:53 -0500
commit5eb163f321fdc9a3dbb5e02a157b7f8194e70fcc (patch)
treed8839ce67d6257905e68322b94ae67f3b187e782
parentab334262a605b0ebc228096d8af88a55aa5ea6b8 (diff)
downloadhaskell-5eb163f321fdc9a3dbb5e02a157b7f8194e70fcc.tar.gz
rts/linker: Don't allow shared libraries to be loaded multiple times
-rw-r--r--rts/Linker.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/rts/Linker.c b/rts/Linker.c
index 9defb1efa0..211b65150f 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -2027,6 +2027,15 @@ static void * loadNativeObj_ELF (pathchar *path, char **errmsg)
retval = NULL;
ACQUIRE_LOCK(&dl_mutex);
+ /* Loading the same object multiple times will lead to chaos
+ * as we will have two ObjectCodes but one underlying dlopen
+ * handle. Fail if this happens.
+ */
+ if (getObjectLoadStatus_(path) != OBJECT_NOT_LOADED) {
+ copyErrmsg(errmsg, "loadNativeObj_ELF: Already loaded");
+ goto dlopen_fail;
+ }
+
nc = mkOc(DYNAMIC_OBJECT, path, NULL, 0, true, NULL, 0);
foreignExportsLoadingObject(nc);