Skip to content

Commit 5081e41

Browse files
committed
Fix a crash bug caused by a nested call of parallelForEach.
parallelForEach is not reentrant. We use parallelForEach to call each section's writeTo(), so calling the same function within writeTo() is not safe. Fixes https://bugs.llvm.org/show_bug.cgi?id=41508 Differential Revision: https://reviews.llvm.org/D60757 llvm-svn: 358547
1 parent a863435 commit 5081e41

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lld/wasm/OutputSections.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ void CodeSection::writeTo(uint8_t *Buf) {
110110
memcpy(Buf, CodeSectionHeader.data(), CodeSectionHeader.size());
111111

112112
// Write code section bodies
113-
parallelForEach(Functions,
114-
[&](const InputChunk *Chunk) { Chunk->writeTo(Buf); });
113+
for (const InputChunk *Chunk : Functions)
114+
Chunk->writeTo(Buf);
115115
}
116116

117117
uint32_t CodeSection::numRelocations() const {
@@ -175,15 +175,15 @@ void DataSection::writeTo(uint8_t *Buf) {
175175
// Write data section headers
176176
memcpy(Buf, DataSectionHeader.data(), DataSectionHeader.size());
177177

178-
parallelForEach(Segments, [&](const OutputSegment *Segment) {
178+
for (const OutputSegment *Segment : Segments) {
179179
// Write data segment header
180180
uint8_t *SegStart = Buf + Segment->SectionOffset;
181181
memcpy(SegStart, Segment->Header.data(), Segment->Header.size());
182182

183183
// Write segment data payload
184184
for (const InputChunk *Chunk : Segment->InputSegments)
185185
Chunk->writeTo(Buf);
186-
});
186+
}
187187
}
188188

189189
uint32_t DataSection::numRelocations() const {
@@ -231,8 +231,8 @@ void CustomSection::writeTo(uint8_t *Buf) {
231231
Buf += NameData.size();
232232

233233
// Write custom sections payload
234-
parallelForEach(InputSections,
235-
[&](const InputSection *Section) { Section->writeTo(Buf); });
234+
for (const InputSection *Section : InputSections)
235+
Section->writeTo(Buf);
236236
}
237237

238238
uint32_t CustomSection::numRelocations() const {

0 commit comments

Comments
 (0)