diff options
author | Ben Gamari <ben@smart-cactus.org> | 2022-07-12 13:01:43 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-07-16 23:50:36 -0400 |
commit | 033580bc35451e49ed021ae5391da8e199d58c8d (patch) | |
tree | b647899e573a37b382dd6766f60d3ee4880f45b6 | |
parent | 03c69d8d1ffeb85055d71f6c144c18309a13308f (diff) | |
download | haskell-033580bc35451e49ed021ae5391da8e199d58c8d.tar.gz |
rts/linker/PEi386: Refactor handling of oc->info
Previously we would free oc->info after running initializers. However,
we can't do this is we want to also run finalizers.
Moreover, freeing oc->info so early was wrong for another reason:
we will need it in order to unregister the exception tables (see the
call to `RtlDeleteFunctionTable`).
In service of #20494.
-rw-r--r-- | rts/linker/PEi386.c | 10 | ||||
-rw-r--r-- | rts/linker/PEi386Types.h | 4 |
2 files changed, 10 insertions, 4 deletions
diff --git a/rts/linker/PEi386.c b/rts/linker/PEi386.c index 97b7a12e76..f7fa4eff93 100644 --- a/rts/linker/PEi386.c +++ b/rts/linker/PEi386.c @@ -509,13 +509,14 @@ void freePreloadObjectFile_PEi386(ObjectCode *oc) } } +// Free oc->info and oc->sections[i]->info. static void releaseOcInfo(ObjectCode* oc) { if (!oc) return; if (oc->info) { stgFree (oc->info->ch_info); - stgFree (oc->info->str_tab); stgFree (oc->info->symbols); + stgFree (oc->info->str_tab); stgFree (oc->info); oc->info = NULL; } @@ -2014,6 +2015,12 @@ ocResolve_PEi386 ( ObjectCode* oc ) } } + // We now have no more need of info->ch_info and info->symbols. + stgFree(oc->info->ch_info); + oc->info->ch_info = NULL; + stgFree(oc->info->symbols); + oc->info->symbols = NULL; + IF_DEBUG(linker, debugBelch("completed %" PATH_FMT "\n", oc->fileName)); return true; } @@ -2129,7 +2136,6 @@ ocRunInit_PEi386 ( ObjectCode *oc ) (*init)(argc, argv, envv); freeProgEnvv(envc, envv); - releaseOcInfo (oc); return true; } diff --git a/rts/linker/PEi386Types.h b/rts/linker/PEi386Types.h index dbe6d51e3e..747a083779 100644 --- a/rts/linker/PEi386Types.h +++ b/rts/linker/PEi386Types.h @@ -21,9 +21,9 @@ struct ObjectCodeFormatInfo { Section* fini; Section* pdata; Section* xdata; - COFF_HEADER_INFO* ch_info; + COFF_HEADER_INFO* ch_info; // Freed by ocResolve_PEi386 + COFF_symbol* symbols; // Freed by ocResolve_PEi386 char* str_tab; - COFF_symbol* symbols; }; #endif /* OBJFORMAT_PEi386. */ |