Skip to content

Commit 07bc54b

Browse files
authored
[DWARFLinkerParallel] Fix incorrect uses of compare_exchange_weak (#138129)
The documentation for compare_exchange_weak says that it is allowed to spuriously fail. If compare_exchange_weak is called in a loop, spurious failures usually are benign - but in these cases, a spurious failure would give incorrect behaviour. E.g. in TypePool::getOrCreateTypeEntryBody, we assume that if the compare_exchange call returned false, we had been preempted by another thread and that DIE is non-null. This fixes running the dsymutil tests on Windows on aarch64 (built with a mingw toolchain with libc++).
1 parent a94e560 commit 07bc54b

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,13 +1433,13 @@ DIE *CompileUnit::allocateTypeDie(TypeEntryBody *TypeDescriptor,
14331433
if (IsDeclaration && !DeclarationDie) {
14341434
// Alocate declaration DIE.
14351435
DIE *NewDie = TypeDIEGenerator.createDIE(DieTag, 0);
1436-
if (TypeDescriptor->DeclarationDie.compare_exchange_weak(DeclarationDie,
1437-
NewDie))
1436+
if (TypeDescriptor->DeclarationDie.compare_exchange_strong(DeclarationDie,
1437+
NewDie))
14381438
return NewDie;
14391439
} else if (IsDeclaration && !IsParentDeclaration && OldParentIsDeclaration) {
14401440
// Overwrite existing declaration DIE if it's parent is also an declaration
14411441
// while parent of current declaration DIE is a definition.
1442-
if (TypeDescriptor->ParentIsDeclaration.compare_exchange_weak(
1442+
if (TypeDescriptor->ParentIsDeclaration.compare_exchange_strong(
14431443
OldParentIsDeclaration, false)) {
14441444
DIE *NewDie = TypeDIEGenerator.createDIE(DieTag, 0);
14451445
TypeDescriptor->DeclarationDie = NewDie;
@@ -1449,13 +1449,13 @@ DIE *CompileUnit::allocateTypeDie(TypeEntryBody *TypeDescriptor,
14491449
// Alocate declaration DIE since parent of current DIE is marked as
14501450
// declaration.
14511451
DIE *NewDie = TypeDIEGenerator.createDIE(DieTag, 0);
1452-
if (TypeDescriptor->DeclarationDie.compare_exchange_weak(DeclarationDie,
1453-
NewDie))
1452+
if (TypeDescriptor->DeclarationDie.compare_exchange_strong(DeclarationDie,
1453+
NewDie))
14541454
return NewDie;
14551455
} else if (!IsDeclaration && !IsParentDeclaration) {
14561456
// Allocate definition DIE.
14571457
DIE *NewDie = TypeDIEGenerator.createDIE(DieTag, 0);
1458-
if (TypeDescriptor->Die.compare_exchange_weak(DefinitionDie, NewDie)) {
1458+
if (TypeDescriptor->Die.compare_exchange_strong(DefinitionDie, NewDie)) {
14591459
TypeDescriptor->ParentIsDeclaration = false;
14601460
return NewDie;
14611461
}

llvm/lib/DWARFLinker/Parallel/DWARFLinkerCompileUnit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class alignas(8) CompileUnit : public DwarfUnit {
201201
bool setPlacementIfUnset(DieOutputPlacement Placement) {
202202
auto InputData = Flags.load();
203203
if ((InputData & 0x7) == NotSet)
204-
if (Flags.compare_exchange_weak(InputData, (InputData | Placement)))
204+
if (Flags.compare_exchange_strong(InputData, (InputData | Placement)))
205205
return true;
206206

207207
return false;

llvm/lib/DWARFLinker/Parallel/TypePool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class TypePool
135135
return DIE;
136136

137137
TypeEntryBody *NewDIE = TypeEntryBody::create(Allocator);
138-
if (Entry->getValue().compare_exchange_weak(DIE, NewDIE)) {
138+
if (Entry->getValue().compare_exchange_strong(DIE, NewDIE)) {
139139
ParentEntry->getValue().load()->Children.add(Entry);
140140
return NewDIE;
141141
}

0 commit comments

Comments
 (0)