From 01c4f45c78709497874337c29a5ff0179f3c1a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Tue, 6 May 2025 17:15:12 +0300 Subject: [PATCH 1/2] [DWARFLinkerParallel] Change more cases of compare_exchange_weak to compare_exchange_strong This is a follow-up to 07bc54bf4554398b199f4dc849e5193b98422f23; 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. --- llvm/lib/DWARFLinker/Parallel/ArrayList.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/lib/DWARFLinker/Parallel/ArrayList.h b/llvm/lib/DWARFLinker/Parallel/ArrayList.h index c48f828609be2..d89b6102664be 100644 --- a/llvm/lib/DWARFLinker/Parallel/ArrayList.h +++ b/llvm/lib/DWARFLinker/Parallel/ArrayList.h @@ -49,7 +49,7 @@ template class ArrayList { if (!CurGroup->Next) allocateNewGroup(CurGroup->Next); - LastGroup.compare_exchange_weak(CurGroup, CurGroup->Next); + LastGroup.compare_exchange_strong(CurGroup, CurGroup->Next); } while (true); // Store item into the current group. @@ -137,7 +137,7 @@ template class ArrayList { NewGroup->Next = nullptr; // Try to replace current group with allocated one. - if (AtomicGroup.compare_exchange_weak(CurGroup, NewGroup)) + if (AtomicGroup.compare_exchange_strong(CurGroup, NewGroup)) return true; // Put allocated group as last group. @@ -145,7 +145,7 @@ template class ArrayList { ItemsGroup *NextGroup = CurGroup->Next; if (!NextGroup) { - if (CurGroup->Next.compare_exchange_weak(NextGroup, NewGroup)) + if (CurGroup->Next.compare_exchange_strong(NextGroup, NewGroup)) break; } From baf827facbb90280c5833e8363756f4b38212baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Tue, 6 May 2025 23:24:24 +0300 Subject: [PATCH 2/2] Restore compare_exchange_weak in two cases where it should be ok --- llvm/lib/DWARFLinker/Parallel/ArrayList.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/lib/DWARFLinker/Parallel/ArrayList.h b/llvm/lib/DWARFLinker/Parallel/ArrayList.h index d89b6102664be..d99fdcc8c60c0 100644 --- a/llvm/lib/DWARFLinker/Parallel/ArrayList.h +++ b/llvm/lib/DWARFLinker/Parallel/ArrayList.h @@ -49,7 +49,7 @@ template class ArrayList { if (!CurGroup->Next) allocateNewGroup(CurGroup->Next); - LastGroup.compare_exchange_strong(CurGroup, CurGroup->Next); + LastGroup.compare_exchange_weak(CurGroup, CurGroup->Next); } while (true); // Store item into the current group. @@ -145,7 +145,7 @@ template class ArrayList { ItemsGroup *NextGroup = CurGroup->Next; if (!NextGroup) { - if (CurGroup->Next.compare_exchange_strong(NextGroup, NewGroup)) + if (CurGroup->Next.compare_exchange_weak(NextGroup, NewGroup)) break; }