Skip to content

Commit 59ae7da

Browse files
committed
[BOLT][DWARF][NFC] Remove option to write to DWP
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60292935
1 parent 1978c21 commit 59ae7da

9 files changed

+12
-504
lines changed

bolt/include/bolt/Rewrite/DWARFRewriter.h

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "bolt/Core/GDBIndex.h"
1616
#include "llvm/ADT/StringRef.h"
1717
#include "llvm/CodeGen/DIE.h"
18-
#include "llvm/DWP/DWP.h"
1918
#include "llvm/MC/MCContext.h"
2019
#include "llvm/Support/ToolOutputFile.h"
2120
#include <cstdint>
@@ -194,35 +193,6 @@ class DWARFRewriter {
194193
const std::string &, DebugLocWriter &,
195194
DebugStrOffsetsWriter &, DebugStrWriter &);
196195
using KnownSectionsEntry = std::pair<MCSection *, DWARFSectionKind>;
197-
struct DWPState {
198-
std::unique_ptr<ToolOutputFile> Out;
199-
std::unique_ptr<BinaryContext> TmpBC;
200-
std::unique_ptr<MCStreamer> Streamer;
201-
std::unique_ptr<DWPStringPool> Strings;
202-
/// Used to store String sections for .dwo files if they are being modified.
203-
std::vector<std::unique_ptr<DebugBufferVector>> StrSections;
204-
const MCObjectFileInfo *MCOFI = nullptr;
205-
const DWARFUnitIndex *CUIndex = nullptr;
206-
std::deque<SmallString<32>> UncompressedSections;
207-
MapVector<uint64_t, UnitIndexEntry> IndexEntries;
208-
MapVector<uint64_t, UnitIndexEntry> TypeIndexEntries;
209-
StringMap<KnownSectionsEntry> KnownSections;
210-
uint32_t ContributionOffsets[8] = {};
211-
uint32_t IndexVersion = 2;
212-
uint64_t DebugInfoSize = 0;
213-
uint16_t Version = 0;
214-
bool IsDWP = false;
215-
};
216-
/// Init .dwp file
217-
void initDWPState(DWPState &);
218-
219-
/// Write out .dwp File
220-
void finalizeDWP(DWPState &);
221-
222-
/// add content of dwo to .dwp file.
223-
void updateDWP(DWARFUnit &, const OverriddenSectionsMap &, const UnitMeta &,
224-
UnitMetaVectorType &, DWPState &, DebugLocWriter &,
225-
DebugStrOffsetsWriter &, DebugStrWriter &);
226196
};
227197

228198
} // namespace bolt

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 12 additions & 241 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,8 @@ static cl::opt<bool> KeepARanges(
331331

332332
static cl::opt<std::string> DwarfOutputPath(
333333
"dwarf-output-path",
334-
cl::desc("Path to where .dwo files or dwp file will be written out to."),
335-
cl::init(""), cl::cat(BoltCategory));
336-
337-
static cl::opt<bool>
338-
WriteDWP("write-dwp",
339-
cl::desc("output a single dwarf package file (dwp) instead of "
340-
"multiple non-relocatable dwarf object files (dwo)."),
341-
cl::init(false), cl::cat(BoltCategory));
334+
cl::desc("Path to where .dwo files will be written out to."), cl::init(""),
335+
cl::cat(BoltCategory));
342336

343337
static cl::opt<bool> CreateDebugNames(
344338
"create-debug-names-section",
@@ -481,12 +475,13 @@ emitUnit(DIEBuilder &DIEBldr, DIEStreamer &Streamer, DWARFUnit &Unit) {
481475
return {U.UnitOffset, U.UnitLength, TypeHash};
482476
}
483477

484-
static void
485-
emitDWOBuilder(const std::string &DWOName, DIEBuilder &DWODIEBuilder,
486-
DWARFRewriter &Rewriter, DWARFUnit &SplitCU, DWARFUnit &CU,
487-
DWARFRewriter::DWPState &State, DebugLocWriter &LocWriter,
488-
DebugStrOffsetsWriter &StrOffstsWriter,
489-
DebugStrWriter &StrWriter, GDBIndex &GDBIndexSection) {
478+
static void emitDWOBuilder(const std::string &DWOName,
479+
DIEBuilder &DWODIEBuilder, DWARFRewriter &Rewriter,
480+
DWARFUnit &SplitCU, DWARFUnit &CU,
481+
DebugLocWriter &LocWriter,
482+
DebugStrOffsetsWriter &StrOffstsWriter,
483+
DebugStrWriter &StrWriter,
484+
GDBIndex &GDBIndexSection) {
490485
// Populate debug_info and debug_abbrev for current dwo into StringRef.
491486
DWODIEBuilder.generateAbbrevs();
492487
DWODIEBuilder.finish();
@@ -547,12 +542,8 @@ emitDWOBuilder(const std::string &DWOName, DIEBuilder &DWODIEBuilder,
547542
continue;
548543
OverriddenSections[Kind] = Contents;
549544
}
550-
if (opts::WriteDWP)
551-
Rewriter.updateDWP(CU, OverriddenSections, CUMI, TUMetaVector, State,
552-
LocWriter, StrOffstsWriter, StrWriter);
553-
else
554-
Rewriter.writeDWOFiles(CU, OverriddenSections, DWOName, LocWriter,
555-
StrOffstsWriter, StrWriter);
545+
Rewriter.writeDWOFiles(CU, OverriddenSections, DWOName, LocWriter,
546+
StrOffstsWriter, StrWriter);
556547
}
557548

558549
using DWARFUnitVec = std::vector<DWARFUnit *>;
@@ -665,9 +656,6 @@ void DWARFRewriter::updateDebugInfo() {
665656
DWARF5AcceleratorTable DebugNamesTable(opts::CreateDebugNames, BC,
666657
*StrWriter);
667658
GDBIndex GDBIndexSection(BC);
668-
DWPState State;
669-
if (opts::WriteDWP)
670-
initDWPState(State);
671659
auto processSplitCU = [&](DWARFUnit &Unit, DWARFUnit &SplitCU,
672660
DIEBuilder &DIEBlder,
673661
DebugRangesSectionWriter &TempRangesSectionWriter,
@@ -691,7 +679,7 @@ void DWARFRewriter::updateDebugInfo() {
691679
if (Unit.getVersion() >= 5)
692680
TempRangesSectionWriter.finalizeSection();
693681

694-
emitDWOBuilder(DWOName, DWODIEBuilder, *this, SplitCU, Unit, State,
682+
emitDWOBuilder(DWOName, DWODIEBuilder, *this, SplitCU, Unit,
695683
DebugLocDWoWriter, DWOStrOffstsWriter, DWOStrWriter,
696684
GDBIndexSection);
697685
};
@@ -771,9 +759,6 @@ void DWARFRewriter::updateDebugInfo() {
771759

772760
DebugNamesTable.emitAccelTable();
773761

774-
if (opts::WriteDWP)
775-
finalizeDWP(State);
776-
777762
finalizeDebugSections(DIEBlder, DebugNamesTable, *Streamer, *ObjOS, OffsetMap,
778763
*FinalAddrWriter);
779764
GDBIndexSection.updateGdbIndexSection(OffsetMap, CUIndex,
@@ -1819,220 +1804,6 @@ std::optional<StringRef> updateDebugData(
18191804

18201805
} // namespace
18211806

1822-
void DWARFRewriter::initDWPState(DWPState &State) {
1823-
SmallString<0> OutputNameStr;
1824-
StringRef OutputName;
1825-
if (opts::DwarfOutputPath.empty()) {
1826-
OutputName =
1827-
Twine(opts::OutputFilename).concat(".dwp").toStringRef(OutputNameStr);
1828-
} else {
1829-
StringRef ExeFileName = llvm::sys::path::filename(opts::OutputFilename);
1830-
OutputName = Twine(opts::DwarfOutputPath)
1831-
.concat("/")
1832-
.concat(ExeFileName)
1833-
.concat(".dwp")
1834-
.toStringRef(OutputNameStr);
1835-
errs() << "BOLT-WARNING: dwarf-output-path is in effect and .dwp file will "
1836-
"possibly be written to another location that is not the same as "
1837-
"the executable\n";
1838-
}
1839-
std::error_code EC;
1840-
State.Out =
1841-
std::make_unique<ToolOutputFile>(OutputName, EC, sys::fs::OF_None);
1842-
const object::ObjectFile *File = BC.DwCtx->getDWARFObj().getFile();
1843-
State.TmpBC = createDwarfOnlyBC(*File);
1844-
State.Streamer = State.TmpBC->createStreamer(State.Out->os());
1845-
State.MCOFI = State.Streamer->getContext().getObjectFileInfo();
1846-
State.KnownSections = createKnownSectionsMap(*State.MCOFI);
1847-
MCSection *const StrSection = State.MCOFI->getDwarfStrDWOSection();
1848-
1849-
// Data Structures for DWP book keeping
1850-
// Size of array corresponds to the number of sections supported by DWO format
1851-
// in DWARF4/5.
1852-
1853-
State.Strings = std::make_unique<DWPStringPool>(*State.Streamer, StrSection);
1854-
1855-
// Setup DWP code once.
1856-
DWARFContext *DWOCtx = BC.getDWOContext();
1857-
1858-
if (DWOCtx) {
1859-
State.CUIndex = &DWOCtx->getCUIndex();
1860-
State.IsDWP = !State.CUIndex->getRows().empty();
1861-
}
1862-
}
1863-
1864-
void DWARFRewriter::finalizeDWP(DWPState &State) {
1865-
if (State.Version < 5) {
1866-
// Lie about there being no info contributions so the TU index only includes
1867-
// the type unit contribution for DWARF < 5. In DWARFv5 the TU index has a
1868-
// contribution to the info section, so we do not want to lie about it.
1869-
State.ContributionOffsets[0] = 0;
1870-
}
1871-
writeIndex(*State.Streamer.get(), State.MCOFI->getDwarfTUIndexSection(),
1872-
State.ContributionOffsets, State.TypeIndexEntries,
1873-
State.IndexVersion);
1874-
1875-
if (State.Version < 5) {
1876-
// Lie about the type contribution for DWARF < 5. In DWARFv5 the type
1877-
// section does not exist, so no need to do anything about this.
1878-
State.ContributionOffsets[getContributionIndex(DW_SECT_EXT_TYPES, 2)] = 0;
1879-
// Unlie about the info contribution
1880-
State.ContributionOffsets[0] = 1;
1881-
}
1882-
writeIndex(*State.Streamer.get(), State.MCOFI->getDwarfCUIndexSection(),
1883-
State.ContributionOffsets, State.IndexEntries, State.IndexVersion);
1884-
1885-
State.Streamer->finish();
1886-
State.Out->keep();
1887-
}
1888-
1889-
void DWARFRewriter::updateDWP(DWARFUnit &CU,
1890-
const OverriddenSectionsMap &OverridenSections,
1891-
const DWARFRewriter::UnitMeta &CUMI,
1892-
DWARFRewriter::UnitMetaVectorType &TUMetaVector,
1893-
DWPState &State, DebugLocWriter &LocWriter,
1894-
DebugStrOffsetsWriter &StrOffstsWriter,
1895-
DebugStrWriter &StrWriter) {
1896-
const uint64_t DWOId = *CU.getDWOId();
1897-
MCSection *const StrOffsetSection = State.MCOFI->getDwarfStrOffDWOSection();
1898-
assert(StrOffsetSection && "StrOffsetSection does not exist.");
1899-
// Skipping CUs that we failed to load.
1900-
std::optional<DWARFUnit *> DWOCU = BC.getDWOCU(DWOId);
1901-
if (!DWOCU)
1902-
return;
1903-
1904-
if (State.Version == 0) {
1905-
State.Version = CU.getVersion();
1906-
State.IndexVersion = State.Version < 5 ? 2 : 5;
1907-
} else if (State.Version != CU.getVersion()) {
1908-
errs() << "BOLT-ERROR: incompatible DWARF compile unit versions\n";
1909-
exit(1);
1910-
}
1911-
1912-
UnitIndexEntry CurEntry = {};
1913-
CurEntry.DWOName = dwarf::toString(
1914-
CU.getUnitDIE().find({dwarf::DW_AT_dwo_name, dwarf::DW_AT_GNU_dwo_name}),
1915-
"");
1916-
const char *Name = CU.getUnitDIE().getShortName();
1917-
if (Name)
1918-
CurEntry.Name = Name;
1919-
StringRef CurStrSection;
1920-
StringRef CurStrOffsetSection;
1921-
1922-
// This maps each section contained in this file to its length.
1923-
// This information is later on used to calculate the contributions,
1924-
// i.e. offset and length, of each compile/type unit to a section.
1925-
std::vector<std::pair<DWARFSectionKind, uint32_t>> SectionLength;
1926-
1927-
const DWARFUnitIndex::Entry *CUDWOEntry = nullptr;
1928-
if (State.IsDWP)
1929-
CUDWOEntry = State.CUIndex->getFromHash(DWOId);
1930-
1931-
bool StrSectionWrittenOut = false;
1932-
const object::ObjectFile *DWOFile =
1933-
(*DWOCU)->getContext().getDWARFObj().getFile();
1934-
1935-
DebugRangeListsSectionWriter *RangeListssWriter = nullptr;
1936-
if (CU.getVersion() == 5) {
1937-
assert(RangeListsWritersByCU.count(DWOId) != 0 &&
1938-
"No RangeListsWriter for DWO ID.");
1939-
RangeListssWriter = RangeListsWritersByCU[DWOId].get();
1940-
}
1941-
auto AddType = [&](unsigned int Index, uint32_t IndexVersion, uint64_t Offset,
1942-
uint64_t Length, uint64_t Hash) -> void {
1943-
UnitIndexEntry TUEntry = CurEntry;
1944-
if (IndexVersion < 5)
1945-
TUEntry.Contributions[0] = {};
1946-
TUEntry.Contributions[Index].setOffset(Offset);
1947-
TUEntry.Contributions[Index].setLength(Length);
1948-
State.ContributionOffsets[Index] +=
1949-
TUEntry.Contributions[Index].getLength32();
1950-
State.TypeIndexEntries.insert(std::make_pair(Hash, TUEntry));
1951-
};
1952-
std::unique_ptr<DebugBufferVector> StrOffsetsOutputData;
1953-
std::unique_ptr<DebugBufferVector> StrOutputData;
1954-
for (const SectionRef &Section : DWOFile->sections()) {
1955-
std::unique_ptr<DebugBufferVector> OutputData = nullptr;
1956-
StringRef SectionName = getSectionName(Section);
1957-
Expected<StringRef> ContentsExp = Section.getContents();
1958-
assert(ContentsExp && "Invalid contents.");
1959-
std::optional<StringRef> TOutData =
1960-
updateDebugData((*DWOCU)->getContext(), SectionName, *ContentsExp,
1961-
State.KnownSections, *State.Streamer, *this, CUDWOEntry,
1962-
DWOId, OutputData, RangeListssWriter, LocWriter,
1963-
StrOffstsWriter, StrWriter, OverridenSections);
1964-
if (!TOutData)
1965-
continue;
1966-
1967-
StringRef OutData = *TOutData;
1968-
if (SectionName == "debug_types.dwo") {
1969-
State.Streamer->emitBytes(OutData);
1970-
continue;
1971-
}
1972-
1973-
if (SectionName == "debug_str.dwo") {
1974-
CurStrSection = OutData;
1975-
StrOutputData = std::move(OutputData);
1976-
} else {
1977-
// Since handleDebugDataPatching returned true, we already know this is
1978-
// a known section.
1979-
auto SectionIter = State.KnownSections.find(SectionName);
1980-
if (SectionIter->second.second == DWARFSectionKind::DW_SECT_STR_OFFSETS) {
1981-
CurStrOffsetSection = OutData;
1982-
StrOffsetsOutputData = std::move(OutputData);
1983-
} else {
1984-
State.Streamer->emitBytes(OutData);
1985-
}
1986-
unsigned int Index =
1987-
getContributionIndex(SectionIter->second.second, State.IndexVersion);
1988-
uint64_t Offset = State.ContributionOffsets[Index];
1989-
uint64_t Length = OutData.size();
1990-
if (CU.getVersion() >= 5 &&
1991-
SectionIter->second.second == DWARFSectionKind::DW_SECT_INFO) {
1992-
for (UnitMeta &MI : TUMetaVector)
1993-
MI.Offset += State.DebugInfoSize;
1994-
1995-
Offset = State.DebugInfoSize + CUMI.Offset;
1996-
Length = CUMI.Length;
1997-
State.DebugInfoSize += OutData.size();
1998-
}
1999-
CurEntry.Contributions[Index].setOffset(Offset);
2000-
CurEntry.Contributions[Index].setLength(Length);
2001-
State.ContributionOffsets[Index] +=
2002-
CurEntry.Contributions[Index].getLength32();
2003-
}
2004-
2005-
// Strings are combined in to a new string section, and de-duplicated
2006-
// based on hash.
2007-
if (!StrSectionWrittenOut && !CurStrOffsetSection.empty() &&
2008-
!CurStrSection.empty()) {
2009-
// If debug_str.dwo section was modified storing it until dwp is written
2010-
// out. DWPStringPool stores raw pointers to strings.
2011-
if (StrOutputData)
2012-
State.StrSections.push_back(std::move(StrOutputData));
2013-
writeStringsAndOffsets(*State.Streamer.get(), *State.Strings.get(),
2014-
StrOffsetSection, CurStrSection,
2015-
CurStrOffsetSection, CU.getVersion());
2016-
StrSectionWrittenOut = true;
2017-
}
2018-
}
2019-
CompileUnitIdentifiers CUI{DWOId, CurEntry.Name.c_str(),
2020-
CurEntry.DWOName.c_str()};
2021-
auto P = State.IndexEntries.insert(std::make_pair(CUI.Signature, CurEntry));
2022-
if (!P.second) {
2023-
Error Err = buildDuplicateError(*P.first, CUI, "");
2024-
errs() << "BOLT-ERROR: " << toString(std::move(Err)) << "\n";
2025-
return;
2026-
}
2027-
2028-
// Handling TU
2029-
const unsigned Index = getContributionIndex(
2030-
State.IndexVersion < 5 ? DW_SECT_EXT_TYPES : DW_SECT_INFO,
2031-
State.IndexVersion);
2032-
for (UnitMeta &MI : TUMetaVector)
2033-
AddType(Index, State.IndexVersion, MI.Offset, MI.Length, MI.TUHash);
2034-
}
2035-
20361807
void DWARFRewriter::writeDWOFiles(
20371808
DWARFUnit &CU, const OverriddenSectionsMap &OverridenSections,
20381809
const std::string &DWOName, DebugLocWriter &LocWriter,

bolt/test/X86/debug-fission-single-convert.s

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,6 @@
4141
# CHECK-ADDR-SEC: 0x00000000: Addrs: [
4242
# CHECK-ADDR-SEC: 0x0000000000601000
4343

44-
# RUN: llvm-bolt %t.exe --reorder-blocks=reverse --update-debug-sections --dwarf-output-path=%T -o %t.bolt.2.exe --write-dwp=true \
45-
# RUN: --always-convert-to-ranges=true
46-
# RUN: not llvm-dwarfdump --show-form --verbose --debug-info %t.bolt.2.exe.dwp &> %tAddrIndexTestDwp
47-
# RUN: cat %tAddrIndexTestDwp | FileCheck %s --check-prefix=CHECK-DWP-DEBUG
48-
49-
# CHECK-DWP-DEBUG: DW_TAG_compile_unit [1] *
50-
# CHECK-DWP-DEBUG: DW_AT_producer [DW_FORM_GNU_str_index] (indexed (0000000a) string = "clang version 13.0.0")
51-
# CHECK-DWP-DEBUG: DW_AT_language [DW_FORM_data2] (DW_LANG_C_plus_plus)
52-
# CHECK-DWP-DEBUG: DW_AT_name [DW_FORM_GNU_str_index] (indexed (0000000b) string = "foo")
53-
# CHECK-DWP-DEBUG: DW_AT_GNU_dwo_name [DW_FORM_GNU_str_index] (indexed (0000000c) string = "foo")
54-
# CHECK-DWP-DEBUG: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x06105e732fad3796)
55-
56-
5744
//clang++ -ffunction-sections -fno-exceptions -g -gsplit-dwarf=split -S debug-fission-simple.cpp -o debug-fission-simple.s
5845
static int foo = 2;
5946
int doStuff(int val) {

bolt/test/X86/debug-fission-single.s

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,6 @@
4242
# CHECK-ADDR-SEC: 0x00000000: Addrs: [
4343
# CHECK-ADDR-SEC: 0x0000000000601000
4444

45-
# RUN: llvm-bolt %t.exe --reorder-blocks=reverse --update-debug-sections --dwarf-output-path=%T -o %t.bolt.2.exe --write-dwp=true
46-
# RUN: llvm-dwarfdump --show-form --verbose --debug-info %t.bolt.2.exe.dwp &> %tAddrIndexTestDwp
47-
# RUN: cat %tAddrIndexTestDwp | FileCheck %s --check-prefix=CHECK-DWP-DEBUG
48-
49-
# CHECK-DWP-DEBUG: DW_TAG_compile_unit [1] *
50-
# CHECK-DWP-DEBUG: DW_AT_producer [DW_FORM_GNU_str_index] (indexed (0000000a) string = "clang version 13.0.0")
51-
# CHECK-DWP-DEBUG: DW_AT_language [DW_FORM_data2] (DW_LANG_C_plus_plus)
52-
# CHECK-DWP-DEBUG: DW_AT_name [DW_FORM_GNU_str_index] (indexed (0000000b) string = "foo")
53-
# CHECK-DWP-DEBUG: DW_AT_GNU_dwo_name [DW_FORM_GNU_str_index] (indexed (0000000c) string = "foo")
54-
# CHECK-DWP-DEBUG: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x06105e732fad3796)
55-
56-
5745
//clang++ -ffunction-sections -fno-exceptions -g -gsplit-dwarf=split -S debug-fission-simple.cpp -o debug-fission-simple.s
5846
static int foo = 2;
5947
int doStuff(int val) {

0 commit comments

Comments
 (0)