Skip to content

Commit

Permalink
Fix a crash bug caused by a nested call of parallelForEach.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rui314 committed Apr 17, 2019
1 parent a863435 commit 5081e41
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lld/wasm/OutputSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ void CodeSection::writeTo(uint8_t *Buf) {
memcpy(Buf, CodeSectionHeader.data(), CodeSectionHeader.size());

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

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

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

// Write segment data payload
for (const InputChunk *Chunk : Segment->InputSegments)
Chunk->writeTo(Buf);
});
}
}

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

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

uint32_t CustomSection::numRelocations() const {
Expand Down

0 comments on commit 5081e41

Please sign in to comment.