summaryrefslogtreecommitdiff
path: root/rts/Linker.c
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2020-09-09 15:39:59 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-09-18 15:56:25 -0400
commitc492134912e5270180881b7345ee86dc32756bdd (patch)
tree00e738e307bb6ad44b1c52d70374d29cebd86712 /rts/Linker.c
parent0799b3de3e3462224bddc0e4b6a3156d04a06361 (diff)
downloadhaskell-c492134912e5270180881b7345ee86dc32756bdd.tar.gz
rts: Refactor foreign export tracking
This avoids calling `libc` in the initializers which are responsible for registering foreign exports. We believe this should avoid the corruption observed in #18548. See Note [Tracking foreign exports] in rts/ForeignExports.c for an overview of the new scheme.
Diffstat (limited to 'rts/Linker.c')
-rw-r--r--rts/Linker.c37
1 files changed, 4 insertions, 33 deletions
diff --git a/rts/Linker.c b/rts/Linker.c
index a8ab511719..fa38480fb6 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -26,6 +26,7 @@
#include "RtsSymbols.h"
#include "RtsSymbolInfo.h"
#include "Profiling.h"
+#include "ForeignExports.h"
#include "sm/OSMem.h"
#include "linker/M32Alloc.h"
#include "linker/CacheFlush.h"
@@ -969,37 +970,6 @@ SymbolAddr* lookupSymbol( SymbolName* lbl )
}
/* -----------------------------------------------------------------------------
- Create a StablePtr for a foreign export. This is normally called by
- a C function with __attribute__((constructor)), which is generated
- by GHC and linked into the module.
-
- If the object code is being loaded dynamically, then we remember
- which StablePtrs were allocated by the constructors and free them
- again in unloadObj().
- -------------------------------------------------------------------------- */
-
-static ObjectCode *loading_obj = NULL;
-
-StgStablePtr foreignExportStablePtr (StgPtr p)
-{
- ForeignExportStablePtr *fe_sptr;
- StgStablePtr *sptr;
-
- sptr = getStablePtr(p);
-
- if (loading_obj != NULL) {
- fe_sptr = stgMallocBytes(sizeof(ForeignExportStablePtr),
- "foreignExportStablePtr");
- fe_sptr->stable_ptr = sptr;
- fe_sptr->next = loading_obj->stable_ptrs;
- loading_obj->stable_ptrs = fe_sptr;
- }
-
- return sptr;
-}
-
-
-/* -----------------------------------------------------------------------------
* Debugging aid: look in GHCi's object symbol tables for symbols
* within DELTA bytes of the specified address, and show their names.
*/
@@ -1793,7 +1763,8 @@ int ocTryLoad (ObjectCode* oc) {
IF_DEBUG(linker, debugBelch("ocTryLoad: ocRunInit start\n"));
- loading_obj = oc; // tells foreignExportStablePtr what to do
+ // See Note [Tracking foreign exports] in ForeignExports.c
+ foreignExportsLoadingObject(oc);
#if defined(OBJFORMAT_ELF)
r = ocRunInit_ELF ( oc );
#elif defined(OBJFORMAT_PEi386)
@@ -1803,7 +1774,7 @@ int ocTryLoad (ObjectCode* oc) {
#else
barf("ocTryLoad: initializers not implemented on this platform");
#endif
- loading_obj = NULL;
+ foreignExportsFinishedLoadingObject();
if (!r) { return r; }