summaryrefslogtreecommitdiff
path: root/llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp')
-rw-r--r--llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp98
1 files changed, 34 insertions, 64 deletions
diff --git a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp
index b0b819cf9778..a052969e74c0 100644
--- a/llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp
+++ b/llvm/lib/DWARFLinker/Parallel/DWARFLinkerImpl.cpp
@@ -32,11 +32,9 @@ DWARFLinkerImpl::DWARFLinkerImpl(MessageHandlerTy ErrorHandler,
DWARFLinkerImpl::LinkContext::LinkContext(LinkingGlobalData &GlobalData,
DWARFFile &File,
StringMap<uint64_t> &ClangModules,
- std::atomic<size_t> &UniqueUnitID,
- std::optional<Triple> TargetTriple)
+ std::atomic<size_t> &UniqueUnitID)
: OutputSections(GlobalData), InputDWARFFile(File),
- ClangModules(ClangModules), TargetTriple(TargetTriple),
- UniqueUnitID(UniqueUnitID) {
+ ClangModules(ClangModules), UniqueUnitID(UniqueUnitID) {
if (File.Dwarf) {
if (!File.Dwarf->compile_units().empty())
@@ -63,25 +61,10 @@ void DWARFLinkerImpl::LinkContext::addModulesCompileUnit(
ModulesCompileUnits.emplace_back(std::move(Unit));
}
-Error DWARFLinkerImpl::createEmitter(const Triple &TheTriple,
- OutputFileType FileType,
- raw_pwrite_stream &OutFile) {
-
- TheDwarfEmitter = std::make_unique<DwarfEmitterImpl>(FileType, OutFile);
-
- return TheDwarfEmitter->init(TheTriple, "__DWARF");
-}
-
-ExtraDwarfEmitter *DWARFLinkerImpl::getEmitter() {
- return TheDwarfEmitter.get();
-}
-
void DWARFLinkerImpl::addObjectFile(DWARFFile &File, ObjFileLoaderTy Loader,
CompileUnitHandlerTy OnCUDieLoaded) {
ObjectContexts.emplace_back(std::make_unique<LinkContext>(
- GlobalData, File, ClangModules, UniqueUnitID,
- (TheDwarfEmitter.get() == nullptr ? std::optional<Triple>(std::nullopt)
- : TheDwarfEmitter->getTargetTriple())));
+ GlobalData, File, ClangModules, UniqueUnitID));
if (ObjectContexts.back()->InputDWARFFile.Dwarf) {
for (const std::unique_ptr<DWARFUnit> &CU :
@@ -117,8 +100,9 @@ Error DWARFLinkerImpl::link() {
0, dwarf::DwarfFormat::DWARF32};
llvm::endianness GlobalEndianness = llvm::endianness::native;
- if (TheDwarfEmitter) {
- GlobalEndianness = TheDwarfEmitter->getTargetTriple().isLittleEndian()
+ if (std::optional<std::reference_wrapper<const Triple>> CurTriple =
+ GlobalData.getTargetTriple()) {
+ GlobalEndianness = (*CurTriple).get().isLittleEndian()
? llvm::endianness::little
: llvm::endianness::big;
}
@@ -131,7 +115,8 @@ Error DWARFLinkerImpl::link() {
}
if (GlobalData.getOptions().Verbose) {
- outs() << "OBJECT: " << Context->InputDWARFFile.FileName << "\n";
+ outs() << "DEBUG MAP OBJECT: " << Context->InputDWARFFile.FileName
+ << "\n";
for (const std::unique_ptr<DWARFUnit> &OrigCU :
Context->InputDWARFFile.Dwarf->compile_units()) {
@@ -147,7 +132,7 @@ Error DWARFLinkerImpl::link() {
if (GlobalData.getOptions().VerifyInputDWARF)
verifyInput(Context->InputDWARFFile);
- if (!TheDwarfEmitter)
+ if (!GlobalData.getTargetTriple())
GlobalEndianness = Context->getEndianness();
GlobalFormat.AddrSize =
std::max(GlobalFormat.AddrSize, Context->getFormParams().AddrSize);
@@ -173,9 +158,9 @@ Error DWARFLinkerImpl::link() {
}
if (GlobalFormat.AddrSize == 0) {
- if (TheDwarfEmitter)
- GlobalFormat.AddrSize =
- TheDwarfEmitter->getTargetTriple().isArch32Bit() ? 4 : 8;
+ if (std::optional<std::reference_wrapper<const Triple>> TargetTriple =
+ GlobalData.getTargetTriple())
+ GlobalFormat.AddrSize = (*TargetTriple).get().isArch32Bit() ? 4 : 8;
else
GlobalFormat.AddrSize = 8;
}
@@ -225,12 +210,10 @@ Error DWARFLinkerImpl::link() {
->getValue()
.load()
->Children.empty()) {
- std::optional<Triple> OutTriple = TheDwarfEmitter.get() == nullptr
- ? std::optional<Triple>(std::nullopt)
- : TheDwarfEmitter->getTargetTriple();
-
- if (Error Err = ArtificialTypeUnit.get()->finishCloningAndEmit(OutTriple))
- return Err;
+ if (GlobalData.getTargetTriple().has_value())
+ if (Error Err = ArtificialTypeUnit.get()->finishCloningAndEmit(
+ (*GlobalData.getTargetTriple()).get()))
+ return Err;
}
// At this stage each compile units are cloned to their own set of debug
@@ -258,8 +241,6 @@ Error DWARFLinkerImpl::validateAndUpdateOptions() {
return createStringError(std::errc::invalid_argument,
"target DWARF version is not set");
- GlobalData.Options.NoOutput = TheDwarfEmitter.get() == nullptr;
-
if (GlobalData.getOptions().Verbose && GlobalData.getOptions().Threads != 1) {
GlobalData.Options.Threads = 1;
GlobalData.warn(
@@ -690,7 +671,8 @@ void DWARFLinkerImpl::LinkContext::linkSingleCompileUnit(
if (CU.isClangModule() ||
GlobalData.getOptions().UpdateIndexTablesOnly ||
CU.getContaingFile().Addresses->hasValidRelocs()) {
- if (Error Err = CU.cloneAndEmit(TargetTriple, ArtificialTypeUnit))
+ if (Error Err = CU.cloneAndEmit(GlobalData.getTargetTriple(),
+ ArtificialTypeUnit))
return std::move(Err);
}
@@ -727,7 +709,7 @@ void DWARFLinkerImpl::LinkContext::linkSingleCompileUnit(
}
Error DWARFLinkerImpl::LinkContext::emitInvariantSections() {
- if (GlobalData.getOptions().NoOutput)
+ if (!GlobalData.getTargetTriple().has_value())
return Error::success();
getOrCreateSectionDescriptor(DebugSectionKind::DebugLoc).OS
@@ -749,7 +731,7 @@ Error DWARFLinkerImpl::LinkContext::emitInvariantSections() {
}
Error DWARFLinkerImpl::LinkContext::cloneAndEmitDebugFrame() {
- if (GlobalData.getOptions().NoOutput)
+ if (!GlobalData.getTargetTriple().has_value())
return Error::success();
if (InputDWARFFile.Dwarf.get() == nullptr)
@@ -870,8 +852,9 @@ void DWARFLinkerImpl::LinkContext::emitFDE(uint32_t CIEOffset,
}
void DWARFLinkerImpl::glueCompileUnitsAndWriteToTheOutput() {
- if (GlobalData.getOptions().NoOutput)
+ if (!GlobalData.getTargetTriple().has_value())
return;
+ assert(SectionHandler);
// Go through all object files, all compile units and assign
// offsets to them.
@@ -1154,21 +1137,23 @@ void DWARFLinkerImpl::emitCommonSectionsAndWriteCompileUnitsToTheOutput() {
AccelTableKind::DebugNames))
CommonSections.getOrCreateSectionDescriptor(DebugSectionKind::DebugNames);
- const Triple &TargetTriple = TheDwarfEmitter->getTargetTriple();
-
// Emit .debug_str and .debug_line_str sections.
TG.spawn([&]() { emitStringSections(); });
if (llvm::is_contained(GlobalData.Options.AccelTables,
AccelTableKind::Apple)) {
// Emit apple accelerator sections.
- TG.spawn([&]() { emitAppleAcceleratorSections(TargetTriple); });
+ TG.spawn([&]() {
+ emitAppleAcceleratorSections((*GlobalData.getTargetTriple()).get());
+ });
}
if (llvm::is_contained(GlobalData.Options.AccelTables,
AccelTableKind::DebugNames)) {
// Emit .debug_names section.
- TG.spawn([&]() { emitDWARFv5DebugNamesSection(TargetTriple); });
+ TG.spawn([&]() {
+ emitDWARFv5DebugNamesSection((*GlobalData.getTargetTriple()).get());
+ });
}
// Write compile units to the output file.
@@ -1374,7 +1359,8 @@ void DWARFLinkerImpl::emitDWARFv5DebugNamesSection(const Triple &TargetTriple) {
case DwarfUnit::AccelType::Namespace:
case DwarfUnit::AccelType::Type: {
DebugNames->addName(*DebugStrStrings.getExistingEntry(Info.String),
- Info.OutOffset, Info.Tag, CU->getUniqueID());
+ Info.OutOffset, std::nullopt /*ParentDIEOffset*/,
+ Info.Tag, CU->getUniqueID());
} break;
default:
@@ -1419,33 +1405,17 @@ void DWARFLinkerImpl::cleanupDataAfterDWARFOutputIsWritten() {
}
void DWARFLinkerImpl::writeCompileUnitsToTheOutput() {
- bool HasAbbreviations = false;
-
// Enumerate all sections and store them into the final emitter.
forEachObjectSectionsSet([&](OutputSections &Sections) {
- Sections.forEach([&](SectionDescriptor &OutSection) {
- if (!HasAbbreviations && !OutSection.getContents().empty() &&
- OutSection.getKind() == DebugSectionKind::DebugAbbrev)
- HasAbbreviations = true;
-
+ Sections.forEach([&](std::shared_ptr<SectionDescriptor> OutSection) {
// Emit section content.
- TheDwarfEmitter->emitSectionContents(OutSection.getContents(),
- OutSection.getName());
- OutSection.clearSectionContent();
+ SectionHandler(OutSection);
});
});
-
- if (!HasAbbreviations) {
- const SmallVector<std::unique_ptr<DIEAbbrev>> Abbreviations;
- TheDwarfEmitter->emitAbbrevs(Abbreviations, 3);
- }
}
void DWARFLinkerImpl::writeCommonSectionsToTheOutput() {
- CommonSections.forEach([&](SectionDescriptor &OutSection) {
- // Emit section content.
- TheDwarfEmitter->emitSectionContents(OutSection.getContents(),
- OutSection.getName());
- OutSection.clearSectionContent();
+ CommonSections.forEach([&](std::shared_ptr<SectionDescriptor> OutSection) {
+ SectionHandler(OutSection);
});
}