[Git][ghc/ghc][master] 2 commits: rts/linker: Don't unload code when profiling is enabled
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Mon Mar 11 05:21:21 UTC 2024
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
8b2513e8 by Ben Gamari at 2024-03-11T01:20:03-04:00
rts/linker: Don't unload code when profiling is enabled
The heap census may contain references (e.g. `Counter.identity`) to
static data which must be available when the census is reported at the
end of execution.
Fixes #24512.
- - - - -
7810b4c3 by Ben Gamari at 2024-03-11T01:20:03-04:00
rts/linker: Don't unload native objects when dlinfo isn't available
To do so is unsafe as we have no way of identifying references to
symbols provided by the object.
Fixes #24513. Fixes #23993.
- - - - -
5 changed files:
- rts/CheckUnload.c
- rts/Linker.c
- rts/LinkerInternals.h
- rts/linker/Elf.c
- testsuite/tests/rts/linker/unload_multiple_objs/linker_unload_multiple_objs.c
Changes:
=====================================
rts/CheckUnload.c
=====================================
@@ -165,6 +165,18 @@ ObjectCode *loaded_objects;
// map static closures to their ObjectCode.
static OCSectionIndices *global_s_indices = NULL;
+// Is it safe for us to unload code?
+static bool safeToUnload(void)
+{
+ if (RtsFlags.ProfFlags.doHeapProfile != NO_HEAP_PROFILING) {
+ // We mustn't unload anything as the heap census may contain
+ // references into static data (e.g. cost centre names).
+ // See #24512.
+ return false;
+ }
+ return true;
+}
+
static OCSectionIndices *createOCSectionIndices(void)
{
// TODO (osa): Maybe initialize as empty (without allocation) and allocate
@@ -457,6 +469,8 @@ void checkUnload(void)
{
if (global_s_indices == NULL) {
return;
+ } else if (!safeToUnload()) {
+ return;
}
// At this point we've marked all dynamically loaded static objects
@@ -478,8 +492,6 @@ void checkUnload(void)
next = oc->next;
ASSERT(oc->status == OBJECT_UNLOADED);
- removeOCSectionIndices(s_indices, oc);
-
// Symbols should be removed by unloadObj_.
// NB (osa): If this assertion doesn't hold then freeObjectCode below
// will corrupt symhash as keys of that table live in ObjectCodes. If
@@ -487,8 +499,17 @@ void checkUnload(void)
// RTS) then it's probably because this assertion did not hold.
ASSERT(oc->symbols == NULL);
- freeObjectCode(oc);
- n_unloaded_objects -= 1;
+ if (oc->unloadable) {
+ removeOCSectionIndices(s_indices, oc);
+ freeObjectCode(oc);
+ n_unloaded_objects -= 1;
+ } else {
+ // If we don't have enough information to
+ // accurately determine the reachability of
+ // the object then hold onto it.
+ oc->next = objects;
+ objects = oc;
+ }
}
old_objects = NULL;
=====================================
rts/Linker.c
=====================================
@@ -1385,6 +1385,8 @@ mkOc( ObjectType type, pathchar *path, char *image, int imageSize,
oc->prev = NULL;
oc->next_loaded_object = NULL;
oc->mark = object_code_mark_bit;
+ /* this will get cleared by the caller if object is not safely unloadable */
+ oc->unloadable = true;
oc->dependencies = allocHashSet();
#if defined(NEED_M32)
=====================================
rts/LinkerInternals.h
=====================================
@@ -313,8 +313,14 @@ struct _ObjectCode {
struct _ObjectCode *next_loaded_object;
// Mark bit
+ // N.B. This is a full word as we CAS it.
StgWord mark;
+ // Can this object be safely unloaded? Not true for
+ // dynamic objects when dlinfo is not available as
+ // we cannot determine liveness.
+ bool unloadable;
+
// Set of dependencies (ObjectCode*) of the object file. Traverse
// dependencies using `iterHashTable`.
//
@@ -376,7 +382,9 @@ struct _ObjectCode {
/* handle returned from dlopen */
void *dlopen_handle;
- /* virtual memory ranges of loaded code */
+ /* virtual memory ranges of loaded code. NULL if no range information is
+ * available (e.g. if dlinfo is unavailable on the current platform).
+ */
NativeCodeRange *nc_ranges;
};
=====================================
rts/linker/Elf.c
=====================================
@@ -2186,6 +2186,10 @@ void * loadNativeObj_ELF (pathchar *path, char **errmsg)
copyErrmsg(errmsg, "dl_iterate_phdr failed to find obj");
goto dl_iterate_phdr_fail;
}
+ nc->unloadable = true;
+#else
+ nc->nc_ranges = NULL;
+ nc->unloadable = false;
#endif /* defined (HAVE_DLINFO) */
insertOCSectionIndices(nc);
=====================================
testsuite/tests/rts/linker/unload_multiple_objs/linker_unload_multiple_objs.c
=====================================
@@ -64,7 +64,7 @@ void check_object_freed(char *obj_path) {
OStatus st;
st = getObjectLoadStatus(toPathchar(obj_path));
if (st != OBJECT_NOT_LOADED) {
- errorBelch("object %s status != OBJECT_NOT_LOADED", obj_path);
+ errorBelch("object %s status != OBJECT_NOT_LOADED, is %d instead", obj_path, st);
exit(1);
}
}
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/dc207d06e9a42bfb531cc0d24271547557b1c488...7810b4c37c7d03772215102a8db5e84d29fe2221
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/dc207d06e9a42bfb531cc0d24271547557b1c488...7810b4c37c7d03772215102a8db5e84d29fe2221
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240311/5e14ec81/attachment-0001.html>
More information about the ghc-commits
mailing list