Skip to content

Commit

Permalink
Merge pull request #13 from jean-edouard/x64_more_segv
Browse files Browse the repository at this point in the history
ghc: add yet another segv fix
  • Loading branch information
eric-ch authored Mar 29, 2019
2 parents 88caec5 + de80ecd commit a791556
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
From a5879a6c2412452fbda8c96e9d921c35279b9d9d Mon Sep 17 00:00:00 2001
From: Simon Marlow <[email protected]>
Date: Tue, 19 Feb 2013 09:58:31 +0000
Subject: [PATCH] Fix segfault in retainer profiling when using multiple cores
(#5909)

Thanks to @akio on the ticket for the diagnosis and the patch. I
modified the comments a bit.
---
rts/sm/Evac.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)

--- a/rts/sm/Evac.c
+++ b/rts/sm/Evac.c
@@ -33,7 +33,7 @@ StgWord64 whitehole_spin = 0;
#define HEAP_ALLOCED_GC(p) HEAP_ALLOCED(p)
#endif

-#if !defined(PARALLEL_GC)
+#if !defined(PARALLEL_GC) || defined(PROFILING)
#define copy_tag_nolock(p, info, src, size, stp, tag) \
copy_tag(p, info, src, size, stp, tag)
#endif
@@ -114,6 +114,17 @@ copy_tag(StgClosure **p, const StgInfoTa
const StgInfoTable *new_info;
new_info = (const StgInfoTable *)cas((StgPtr)&src->header.info, (W_)info, MK_FORWARDING_PTR(to));
if (new_info != info) {
+#ifdef PROFILING
+ // We copied this object at the same time as another
+ // thread. We'll evacuate the object again and the copy
+ // we just made will be discarded at the next GC, but we
+ // may have copied it after the other thread called
+ // SET_EVACUAEE_FOR_LDV(), which would confuse the LDV
+ // profiler when it encounters this closure in
+ // processHeapClosureForDead. So we reset the LDVW field
+ // here.
+ LDVW(to) = 0;
+#endif
return evacuate(p); // does the failed_to_evac stuff
} else {
*p = TAG_CLOSURE(tag,(StgClosure*)to);
@@ -127,11 +138,13 @@ copy_tag(StgClosure **p, const StgInfoTa
#ifdef PROFILING
// We store the size of the just evacuated object in the LDV word so that
// the profiler can guess the position of the next object later.
+ // This is safe only if we are sure that no other thread evacuates
+ // the object again, so we cannot use copy_tag_nolock when PROFILING.
SET_EVACUAEE_FOR_LDV(from, size);
#endif
}

-#if defined(PARALLEL_GC)
+#if defined(PARALLEL_GC) && !defined(PROFILING)
STATIC_INLINE void
copy_tag_nolock(StgClosure **p, const StgInfoTable *info,
StgClosure *src, nat size, step *stp, StgWord tag)
1 change: 1 addition & 0 deletions recipes-devtools/ghc/ghc-6.12.3.inc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ SRC_URI = " \
file://0006-stdcall-x86-64.patch \
file://0007-x64-more-stack.patch \
file://0008-7919-large-objects.patch \
file://0009-Fix-segfault-in-retainer-profiling-when-using-multiple-cores-5909.patch \
"
SRC_URI[md5sum] = "4c2663c2eff833d7b9f39ef770eefbd6"
SRC_URI[sha256sum] = "6cbdbe415011f2c7d15e4d850758d8d393f70617b88cb3237d2c602bb60e5e68"
Expand Down

0 comments on commit a791556

Please sign in to comment.