Skip to content

Commit bacf9cf

Browse files
committed
Revert "[PDB] Defer relocating .debug$S until commit time and parallelize it"
This reverts commit 1a9bd5b. I suspect that this patch may have caused https://crbug.com/1171438.
1 parent 1daaa64 commit bacf9cf

File tree

6 files changed

+292
-629
lines changed

6 files changed

+292
-629
lines changed

lld/COFF/Chunks.cpp

Lines changed: 36 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -367,89 +367,47 @@ void SectionChunk::writeTo(uint8_t *buf) const {
367367
continue;
368368
}
369369

370-
applyRelocation(buf + rel.VirtualAddress, rel);
371-
}
372-
}
370+
uint8_t *off = buf + rel.VirtualAddress;
373371

374-
void SectionChunk::applyRelocation(uint8_t *off,
375-
const coff_relocation &rel) const {
376-
auto *sym = dyn_cast_or_null<Defined>(file->getSymbol(rel.SymbolTableIndex));
377-
378-
// Get the output section of the symbol for this relocation. The output
379-
// section is needed to compute SECREL and SECTION relocations used in debug
380-
// info.
381-
Chunk *c = sym ? sym->getChunk() : nullptr;
382-
OutputSection *os = c ? c->getOutputSection() : nullptr;
372+
auto *sym =
373+
dyn_cast_or_null<Defined>(file->getSymbol(rel.SymbolTableIndex));
383374

384-
// Skip the relocation if it refers to a discarded section, and diagnose it
385-
// as an error if appropriate. If a symbol was discarded early, it may be
386-
// null. If it was discarded late, the output section will be null, unless
387-
// it was an absolute or synthetic symbol.
388-
if (!sym ||
389-
(!os && !isa<DefinedAbsolute>(sym) && !isa<DefinedSynthetic>(sym))) {
390-
maybeReportRelocationToDiscarded(this, sym, rel);
391-
return;
392-
}
375+
// Get the output section of the symbol for this relocation. The output
376+
// section is needed to compute SECREL and SECTION relocations used in debug
377+
// info.
378+
Chunk *c = sym ? sym->getChunk() : nullptr;
379+
OutputSection *os = c ? c->getOutputSection() : nullptr;
380+
381+
// Skip the relocation if it refers to a discarded section, and diagnose it
382+
// as an error if appropriate. If a symbol was discarded early, it may be
383+
// null. If it was discarded late, the output section will be null, unless
384+
// it was an absolute or synthetic symbol.
385+
if (!sym ||
386+
(!os && !isa<DefinedAbsolute>(sym) && !isa<DefinedSynthetic>(sym))) {
387+
maybeReportRelocationToDiscarded(this, sym, rel);
388+
continue;
389+
}
393390

394-
uint64_t s = sym->getRVA();
391+
uint64_t s = sym->getRVA();
395392

396-
// Compute the RVA of the relocation for relative relocations.
397-
uint64_t p = rva + rel.VirtualAddress;
398-
switch (config->machine) {
399-
case AMD64:
400-
applyRelX64(off, rel.Type, os, s, p);
401-
break;
402-
case I386:
403-
applyRelX86(off, rel.Type, os, s, p);
404-
break;
405-
case ARMNT:
406-
applyRelARM(off, rel.Type, os, s, p);
407-
break;
408-
case ARM64:
409-
applyRelARM64(off, rel.Type, os, s, p);
410-
break;
411-
default:
412-
llvm_unreachable("unknown machine type");
413-
}
414-
}
415-
416-
// Defend against unsorted relocations. This may be overly conservative.
417-
void SectionChunk::sortRelocations() {
418-
auto cmpByVa = [](const coff_relocation &l, const coff_relocation &r) {
419-
return l.VirtualAddress < r.VirtualAddress;
420-
};
421-
if (llvm::is_sorted(getRelocs(), cmpByVa))
422-
return;
423-
warn("some relocations in " + file->getName() + " are not sorted");
424-
MutableArrayRef<coff_relocation> newRelocs(
425-
bAlloc.Allocate<coff_relocation>(relocsSize), relocsSize);
426-
memcpy(newRelocs.data(), relocsData, relocsSize * sizeof(coff_relocation));
427-
llvm::sort(newRelocs, cmpByVa);
428-
setRelocs(newRelocs);
429-
}
430-
431-
// Similar to writeTo, but suitable for relocating a subsection of the overall
432-
// section.
433-
void SectionChunk::writeAndRelocateSubsection(ArrayRef<uint8_t> sec,
434-
ArrayRef<uint8_t> subsec,
435-
uint32_t &nextRelocIndex,
436-
uint8_t *buf) const {
437-
assert(!subsec.empty() && !sec.empty());
438-
assert(sec.begin() <= subsec.begin() && subsec.end() <= sec.end() &&
439-
"subsection is not part of this section");
440-
size_t vaBegin = std::distance(sec.begin(), subsec.begin());
441-
size_t vaEnd = std::distance(sec.begin(), subsec.end());
442-
memcpy(buf, subsec.data(), subsec.size());
443-
for (; nextRelocIndex < relocsSize; ++nextRelocIndex) {
444-
const coff_relocation &rel = relocsData[nextRelocIndex];
445-
// Only apply relocations that apply to this subsection. These checks
446-
// assume that all subsections completely contain their relocations.
447-
// Relocations must not straddle the beginning or end of a subsection.
448-
if (rel.VirtualAddress < vaBegin)
449-
continue;
450-
if (rel.VirtualAddress + 1 >= vaEnd)
393+
// Compute the RVA of the relocation for relative relocations.
394+
uint64_t p = rva + rel.VirtualAddress;
395+
switch (config->machine) {
396+
case AMD64:
397+
applyRelX64(off, rel.Type, os, s, p);
398+
break;
399+
case I386:
400+
applyRelX86(off, rel.Type, os, s, p);
401+
break;
402+
case ARMNT:
403+
applyRelARM(off, rel.Type, os, s, p);
451404
break;
452-
applyRelocation(&buf[rel.VirtualAddress - vaBegin], rel);
405+
case ARM64:
406+
applyRelARM64(off, rel.Type, os, s, p);
407+
break;
408+
default:
409+
llvm_unreachable("unknown machine type");
410+
}
453411
}
454412
}
455413

lld/COFF/Chunks.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,6 @@ class SectionChunk final : public Chunk {
204204
ArrayRef<uint8_t> getContents() const;
205205
void writeTo(uint8_t *buf) const;
206206

207-
// Defend against unsorted relocations. This may be overly conservative.
208-
void sortRelocations();
209-
210-
// Write and relocate a portion of the section. This is intended to be called
211-
// in a loop. Relocations must be sorted first.
212-
void writeAndRelocateSubsection(ArrayRef<uint8_t> sec,
213-
ArrayRef<uint8_t> subsec,
214-
uint32_t &nextRelocIndex, uint8_t *buf) const;
215-
216207
uint32_t getOutputCharacteristics() const {
217208
return header->Characteristics & (permMask | typeMask);
218209
}
@@ -221,7 +212,6 @@ class SectionChunk final : public Chunk {
221212
}
222213
void getBaserels(std::vector<Baserel> *res);
223214
bool isCOMDAT() const;
224-
void applyRelocation(uint8_t *off, const coff_relocation &rel) const;
225215
void applyRelX64(uint8_t *off, uint16_t type, OutputSection *os, uint64_t s,
226216
uint64_t p) const;
227217
void applyRelX86(uint8_t *off, uint16_t type, OutputSection *os, uint64_t s,

0 commit comments

Comments
 (0)