summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-06-18 12:07:50 -0400
committerBen Gamari <ben@smart-cactus.org>2019-06-26 13:46:33 -0400
commit17b084af334dec19d7efffe9bc61e760fbd6c805 (patch)
tree3e503cdc06039e2b91a41a946477d3be133d3707
parent4d8a7206b3d8cf4be5084b49705e0a0db86e386b (diff)
downloadhaskell-17b084af334dec19d7efffe9bc61e760fbd6c805.tar.gz
rts: Reset STATIC_LINK field of reverted CAFs
When we revert a CAF we must reset the STATIC_LINK field lest the GC might ignore the CAF (e.g. as it carries the STATIC_FLAG_LIST flag) and will consequently overlook references to object code that we are trying to unload. This would result in the reachable object code being unloaded. See Note [CAF lists] and Note [STATIC_LINK fields]. This fixes #16842. Idea-due-to: Phuong Trinh <lolotp@fb.com> (cherry picked from commit 2a960c3a04afcfcdb25a13e9a6e65c94c22a169f)
-rw-r--r--rts/sm/GCAux.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/rts/sm/GCAux.c b/rts/sm/GCAux.c
index 23ed3f0622..e8ca0c4002 100644
--- a/rts/sm/GCAux.c
+++ b/rts/sm/GCAux.c
@@ -114,16 +114,21 @@ isAlive(StgClosure *p)
void
revertCAFs( void )
{
- StgIndStatic *c;
+ StgIndStatic *c = revertible_caf_list;
- for (c = revertible_caf_list;
- c != (StgIndStatic *)END_OF_CAF_LIST;
- c = (StgIndStatic *)c->static_link)
- {
+ while (c != (StgIndStatic *) END_OF_CAF_LIST) {
c = (StgIndStatic *)UNTAG_STATIC_LIST_PTR(c);
+ StgIndStatic *next = (StgIndStatic *) c->static_link;
+
SET_INFO((StgClosure *)c, c->saved_info);
c->saved_info = NULL;
- // could, but not necessary: c->static_link = NULL;
+ // We must reset static_link lest the major GC finds that
+ // static_flag==3 and will consequently ignore references
+ // into code that we are trying to unload. This would result
+ // in reachable object code being unloaded prematurely.
+ // See #16842.
+ c->static_link = NULL;
+ c = next;
}
revertible_caf_list = (StgIndStatic*)END_OF_CAF_LIST;
}