Skip to content

Commit 01c4f45

Browse files
committed
[DWARFLinkerParallel] Change more cases of compare_exchange_weak to compare_exchange_strong
This is a follow-up to 07bc54b; this seems to perhaps fix occasional crashes in dsymutil on Windows on aarch64. While these are used in loops, which could be tolerant to concurrent accesses, the overall logic seems to assume that they don't have spurious failures; I've observed one case in a debugger, where LastGroup == nullptr within the loop in ArrayList::add(). The remaining uses of compare_exchange_weak() in DWARFLinkerCompileUnit.h also seem very suspicious; if there would be a true concurrent write, leading to compare_exchange_weak() returning false, it seems like we would get stuck in an endless loop - but changing them to compare_exchange_strong() wouldn't make any difference with respect to that.
1 parent a8344a9 commit 01c4f45

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

llvm/lib/DWARFLinker/Parallel/ArrayList.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ template <typename T, size_t ItemsGroupSize = 512> class ArrayList {
4949
if (!CurGroup->Next)
5050
allocateNewGroup(CurGroup->Next);
5151

52-
LastGroup.compare_exchange_weak(CurGroup, CurGroup->Next);
52+
LastGroup.compare_exchange_strong(CurGroup, CurGroup->Next);
5353
} while (true);
5454

5555
// Store item into the current group.
@@ -137,15 +137,15 @@ template <typename T, size_t ItemsGroupSize = 512> class ArrayList {
137137
NewGroup->Next = nullptr;
138138

139139
// Try to replace current group with allocated one.
140-
if (AtomicGroup.compare_exchange_weak(CurGroup, NewGroup))
140+
if (AtomicGroup.compare_exchange_strong(CurGroup, NewGroup))
141141
return true;
142142

143143
// Put allocated group as last group.
144144
while (CurGroup) {
145145
ItemsGroup *NextGroup = CurGroup->Next;
146146

147147
if (!NextGroup) {
148-
if (CurGroup->Next.compare_exchange_weak(NextGroup, NewGroup))
148+
if (CurGroup->Next.compare_exchange_strong(NextGroup, NewGroup))
149149
break;
150150
}
151151

0 commit comments

Comments
 (0)