summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2020-11-21 11:08:57 -0500
committerBen Gamari <ben@smart-cactus.org>2020-11-29 09:52:59 -0500
commit5bf85a6f0926794f2ea0d151a226aafaaf5a9423 (patch)
tree3319b9a3f738bf9a0b9c04c0ff71a4a9c6e15a6b
parentae14f160c64d20880486ba365348ef3900c84a60 (diff)
downloadhaskell-5bf85a6f0926794f2ea0d151a226aafaaf5a9423.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 96d25fb741..83aeac3779 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -2029,6 +2029,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);