summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2022-08-15 15:01:32 -0400
committerAndreas Klebinger <klebinger.andreas@gmx.at>2022-10-12 22:49:00 +0000
commitbfc95d1feb0f91cbcd32f8c71e5dd32bec5a1e8e (patch)
tree6f25c2ccb968e74839f5eea309a338d63276bf7b
parent5c50b5210c3c8fa1bd7ba98410d0ccfb010fe0fb (diff)
downloadhaskell-wip/T21847.tar.gz
rts/linker: Add support for .fini sectionswip/T21847
-rw-r--r--rts/linker/Elf.c3
-rw-r--r--rts/linker/InitFini.c5
-rw-r--r--rts/linker/InitFini.h1
3 files changed, 9 insertions, 0 deletions
diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c
index 197edc95e3..b6473bb2a8 100644
--- a/rts/linker/Elf.c
+++ b/rts/linker/Elf.c
@@ -719,6 +719,9 @@ ocGetNames_ELF ( ObjectCode* oc )
if (kind == SECTIONKIND_CODE_OR_RODATA
&& 0 == memcmp(".init", sh_name, 5)) {
addInitFini(&oc->info->init, &oc->sections[i], INITFINI_INIT, 0);
+ } else if (kind == SECTIONKIND_CODE_OR_RODATA
+ && 0 == memcmp(".fini", sh_name, 5)) {
+ addInitFini(&oc->info->fini, &oc->sections[i], INITFINI_FINI, 0);
} else if (kind == SECTIONKIND_INIT_ARRAY
|| 0 == memcmp(".init_array", sh_name, 11)) {
uint32_t prio;
diff --git a/rts/linker/InitFini.c b/rts/linker/InitFini.c
index 48a548e3cf..6c787fe552 100644
--- a/rts/linker/InitFini.c
+++ b/rts/linker/InitFini.c
@@ -120,6 +120,11 @@ static bool runInitFini(struct InitFiniList **head)
(*init)(argc, argv, envv);
break;
}
+ case INITFINI_FINI: {
+ fini_t *fini = (fini_t*)section->start;
+ (*fini)();
+ break;
+ }
case INITFINI_CTORS: {
uint8_t *init_startC = section->start;
init_t *init_start = (init_t*)init_startC;
diff --git a/rts/linker/InitFini.h b/rts/linker/InitFini.h
index f00233d88d..c0a044402e 100644
--- a/rts/linker/InitFini.h
+++ b/rts/linker/InitFini.h
@@ -2,6 +2,7 @@
enum InitFiniKind {
INITFINI_INIT, // .init section
+ INITFINI_FINI, // .fini section
INITFINI_CTORS, // .ctors section
INITFINI_DTORS, // .dtors section
INITFINI_INIT_ARRAY, // .init_array section