Skip to content

Commit efb5d6b

Browse files
committed
Don't warn about missing DWO files when converting mach-o files.
Apple uses the DW_AT_GNU_dwo_id for non split DWARF cases. Any compile units with this attribute would cause many warnings to be emitted: "warning: Unable to retrieve DWO .debug_info section for" This patch fixes the DWARFTransformer to not look for skeleton compile unit in mach-o based binaries and adds a unit test.
1 parent 9e90788 commit efb5d6b

File tree

4 files changed

+263
-178
lines changed

4 files changed

+263
-178
lines changed

llvm/include/llvm/DebugInfo/GSYM/DwarfTransformer.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@ class DwarfTransformer {
4343
///
4444
/// \param LDCS Flag to indicate whether we should load the call site
4545
/// information from DWARF `DW_TAG_call_site` entries
46-
DwarfTransformer(DWARFContext &D, GsymCreator &G, bool LDCS = false)
47-
: DICtx(D), Gsym(G), LoadDwarfCallSites(LDCS) {}
46+
///
47+
/// \param MachO Flag to indicate if the object file is mach-o (Apple's
48+
/// executable format). Apple has some compile unit attributes that look like
49+
/// split DWARF, but they aren't and they can cause warnins to be emitted
50+
/// about missing DWO files.
51+
DwarfTransformer(DWARFContext &D, GsymCreator &G, bool LDCS = false,
52+
bool MachO = false)
53+
: DICtx(D), Gsym(G), LoadDwarfCallSites(LDCS), IsMachO(MachO) {}
4854

4955
/// Extract the DWARF from the supplied object file and convert it into the
5056
/// Gsym format in the GsymCreator object that is passed in. Returns an
@@ -63,7 +69,6 @@ class DwarfTransformer {
6369
LLVM_ABI llvm::Error verify(StringRef GsymPath, OutputAggregator &OS);
6470

6571
private:
66-
6772
/// Parse the DWARF in the object file and convert it into the GsymCreator.
6873
Error parse();
6974

@@ -97,6 +102,7 @@ class DwarfTransformer {
97102
DWARFContext &DICtx;
98103
GsymCreator &Gsym;
99104
bool LoadDwarfCallSites;
105+
bool IsMachO;
100106

101107
friend class DwarfTransformerTest;
102108
};

llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ struct llvm::gsym::CUInfo {
8282
}
8383
};
8484

85-
8685
static DWARFDie GetParentDeclContextDIE(DWARFDie &Die) {
8786
if (DWARFDie SpecDie =
8887
Die.getAttributeValueAsReferencedDie(dwarf::DW_AT_specification)) {
@@ -170,7 +169,7 @@ getQualifiedNameIndex(DWARFDie &Die, uint64_t Language, GsymCreator &Gsym) {
170169
// templates
171170
if (ParentName.front() == '<' && ParentName.back() == '>')
172171
Name = "{" + ParentName.substr(1, ParentName.size() - 2).str() + "}" +
173-
"::" + Name;
172+
"::" + Name;
174173
else
175174
Name = ParentName.str() + "::" + Name;
176175
}
@@ -432,7 +431,7 @@ static void convertFunctionLineTable(OutputAggregator &Out, CUInfo &CUI,
432431
// Skip multiple line entries for the same file and line.
433432
auto LastLE = FI.OptLineTable->last();
434433
if (LastLE && LastLE->File == FileIdx && LastLE->Line == Row.Line)
435-
continue;
434+
continue;
436435
// Only push a row if it isn't an end sequence. End sequence markers are
437436
// included for the last address in a function or the last contiguous
438437
// address in a sequence.
@@ -629,6 +628,10 @@ Error DwarfTransformer::convert(uint32_t NumThreads, OutputAggregator &Out) {
629628
size_t NumBefore = Gsym.getNumFunctionInfos();
630629
auto getDie = [&](DWARFUnit &DwarfUnit) -> DWARFDie {
631630
DWARFDie ReturnDie = DwarfUnit.getUnitDIE(false);
631+
// Apple uses DW_AT_GNU_dwo_id for things other than split DWARF.
632+
if (IsMachO)
633+
return ReturnDie;
634+
632635
if (DwarfUnit.getDWOId()) {
633636
DWARFUnit *DWOCU = DwarfUnit.getNonSkeletonUnitDIE(false).getDwarfUnit();
634637
if (!DWOCU->isDWOUnit())
@@ -718,8 +721,8 @@ llvm::Error DwarfTransformer::verify(StringRef GsymPath,
718721
for (uint32_t I = 0; I < NumAddrs; ++I) {
719722
auto FuncAddr = Gsym->getAddress(I);
720723
if (!FuncAddr)
721-
return createStringError(std::errc::invalid_argument,
722-
"failed to extract address[%i]", I);
724+
return createStringError(std::errc::invalid_argument,
725+
"failed to extract address[%i]", I);
723726

724727
auto FI = Gsym->getFunctionInfo(*FuncAddr);
725728
if (!FI)
@@ -734,8 +737,7 @@ llvm::Error DwarfTransformer::verify(StringRef GsymPath,
734737
if (!LR)
735738
return LR.takeError();
736739

737-
auto DwarfInlineInfos =
738-
DICtx.getInliningInfoForAddress(SectAddr, DLIS);
740+
auto DwarfInlineInfos = DICtx.getInliningInfoForAddress(SectAddr, DLIS);
739741
uint32_t NumDwarfInlineInfos = DwarfInlineInfos.getNumberOfFrames();
740742
if (NumDwarfInlineInfos == 0) {
741743
DwarfInlineInfos.addFrame(
@@ -773,8 +775,7 @@ llvm::Error DwarfTransformer::verify(StringRef GsymPath,
773775
continue;
774776
}
775777

776-
for (size_t Idx = 0, count = LR->Locations.size(); Idx < count;
777-
++Idx) {
778+
for (size_t Idx = 0, count = LR->Locations.size(); Idx < count; ++Idx) {
778779
const auto &gii = LR->Locations[Idx];
779780
if (Idx < NumDwarfInlineInfos) {
780781
const auto &dii = DwarfInlineInfos.getFrame(Idx);

llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,19 +374,20 @@ static llvm::Error handleObjectFile(ObjectFile &Obj, const std::string &OutFile,
374374
// Make sure there is DWARF to convert first.
375375
std::unique_ptr<DWARFContext> DICtx = DWARFContext::create(
376376
Obj,
377-
/*RelocAction=*/DWARFContext::ProcessDebugRelocations::Process,
378-
nullptr,
377+
/*RelocAction=*/DWARFContext::ProcessDebugRelocations::Process, nullptr,
379378
/*DWPName=*/"",
380379
/*RecoverableErrorHandler=*/WithColor::defaultErrorHandler,
381380
/*WarningHandler=*/WithColor::defaultWarningHandler,
382-
/*ThreadSafe*/true);
381+
/*ThreadSafe*/ true);
383382
if (!DICtx)
384383
return createStringError(std::errc::invalid_argument,
385384
"unable to create DWARF context");
386385

387386
// Make a DWARF transformer object and populate the ranges of the code
388387
// so we don't end up adding invalid functions to GSYM data.
389-
DwarfTransformer DT(*DICtx, Gsym, LoadDwarfCallSites);
388+
bool IsMachO = dyn_cast<object::MachOObjectFile>(&Obj) != nullptr;
389+
390+
DwarfTransformer DT(*DICtx, Gsym, LoadDwarfCallSites, IsMachO);
390391
if (!TextRanges.empty())
391392
Gsym.SetValidTextRanges(TextRanges);
392393

0 commit comments

Comments
 (0)