From b701edc6bb20536ec3987af7f39a66f7c51ff4a4 Mon Sep 17 00:00:00 2001 From: dim Date: Fri, 12 Jan 2018 18:16:51 +0000 Subject: [PATCH] Pull in r322264 from upstream lld trunk (by me): Fix thread race between SectionPiece's OutputOff and Live members Summary: As reported in bug 35788, rL316280 reintroduces a race between two members of SectionPiece, which share the same 64 bit memory location. To fix the race, check the hash before checking the Live member, as suggested by Rafael. Reviewers: ruiu, rafael Reviewed By: ruiu Subscribers: smeenai, emaste, llvm-commits Differential Revision: https://reviews.llvm.org/D41884 --- contrib/llvm/tools/lld/ELF/SyntheticSections.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/contrib/llvm/tools/lld/ELF/SyntheticSections.cpp b/contrib/llvm/tools/lld/ELF/SyntheticSections.cpp index f878acf8cf3f..3d588a1a37b4 100644 --- a/contrib/llvm/tools/lld/ELF/SyntheticSections.cpp +++ b/contrib/llvm/tools/lld/ELF/SyntheticSections.cpp @@ -2435,10 +2435,8 @@ void MergeNoTailSection::finalizeContents() { parallelForEachN(0, Concurrency, [&](size_t ThreadId) { for (MergeInputSection *Sec : Sections) { for (size_t I = 0, E = Sec->Pieces.size(); I != E; ++I) { - if (!Sec->Pieces[I].Live) - continue; size_t ShardId = getShardId(Sec->Pieces[I].Hash); - if ((ShardId & (Concurrency - 1)) == ThreadId) + if ((ShardId & (Concurrency - 1)) == ThreadId && Sec->Pieces[I].Live) Sec->Pieces[I].OutputOff = Shards[ShardId].add(Sec->getData(I)); } }