summaryrefslogtreecommitdiff
path: root/rts/Linker.c
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2021-10-08 09:13:29 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-07-16 23:50:36 -0400
commit616365b01ea6552c39e211a42df4cb33762f481e (patch)
treeab04f2e26bde63305ee9fec55e69e3f7a8d58e13 /rts/Linker.c
parente38a268491347c3aceba359d47034e272afcdf6b (diff)
downloadhaskell-616365b01ea6552c39e211a42df4cb33762f481e.tar.gz
rts/linker/Elf: Introduce support for invoking finalizers on unload
Addresses #20494.
Diffstat (limited to 'rts/Linker.c')
-rw-r--r--rts/Linker.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/rts/Linker.c b/rts/Linker.c
index 8c7cc2848a..cd469b4f2d 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -1136,6 +1136,16 @@ void freeObjectCode (ObjectCode *oc)
{
IF_DEBUG(linker, ocDebugBelch(oc, "start\n"));
+ // Run finalizers
+ if (oc->type == STATIC_OBJECT &&
+ (oc->status == OBJECT_READY || oc->status == OBJECT_UNLOADED)) {
+ // Only run finalizers if the initializers have also been run, which
+ // happens when we resolve the object.
+#if defined(OBJFORMAT_ELF)
+ ocRunFini_ELF(oc);
+#endif
+ }
+
if (oc->type == DYNAMIC_OBJECT) {
#if defined(OBJFORMAT_ELF)
ACQUIRE_LOCK(&dl_mutex);