Skip to content

Commit 3e0bf3d

Browse files
authored
Don't warn about missing DWO files when converting mach-o files. (llvm#152598)
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 b6b4262 commit 3e0bf3d

File tree

4 files changed

+76
-3
lines changed

4 files changed

+76
-3
lines changed

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

Lines changed: 9 additions & 2 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
@@ -97,6 +103,7 @@ class DwarfTransformer {
97103
DWARFContext &DICtx;
98104
GsymCreator &Gsym;
99105
bool LoadDwarfCallSites;
106+
bool IsMachO;
100107

101108
friend class DwarfTransformerTest;
102109
};

llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,10 @@ Error DwarfTransformer::convert(uint32_t NumThreads, OutputAggregator &Out) {
629629
size_t NumBefore = Gsym.getNumFunctionInfos();
630630
auto getDie = [&](DWARFUnit &DwarfUnit) -> DWARFDie {
631631
DWARFDie ReturnDie = DwarfUnit.getUnitDIE(false);
632+
// Apple uses DW_AT_GNU_dwo_id for things other than split DWARF.
633+
if (IsMachO)
634+
return ReturnDie;
635+
632636
if (DwarfUnit.getDWOId()) {
633637
DWARFUnit *DWOCU = DwarfUnit.getNonSkeletonUnitDIE(false).getDwarfUnit();
634638
if (!DWOCU->isDWOUnit())

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,9 @@ static llvm::Error handleObjectFile(ObjectFile &Obj, const std::string &OutFile,
386386

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

llvm/unittests/DebugInfo/GSYM/GSYMTest.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4899,3 +4899,63 @@ TEST(GSYMTest, TestLookupsOfOverlappingAndUnequalRanges) {
48994899
for (const auto &Line : ExpectedDumpLines)
49004900
EXPECT_TRUE(DumpStr.find(Line) != std::string::npos);
49014901
}
4902+
4903+
TEST(GSYMTest, TestUnableToLocateDWO) {
4904+
// Test that llvm-gsymutil will not produce "uanble to locate DWO file" for
4905+
// Apple binaries. Apple uses DW_AT_GNU_dwo_id for non split DWARF purposes
4906+
// and this makes llvm-gsymutil create warnings and errors.
4907+
//
4908+
// 0x0000000b: DW_TAG_compile_unit
4909+
// DW_AT_name ("main.cpp")
4910+
// DW_AT_language (DW_LANG_C)
4911+
// DW_AT_GNU_dwo_id (0xfffffffe)
4912+
StringRef yamldata = R"(
4913+
debug_str:
4914+
- ''
4915+
- main.cpp
4916+
debug_abbrev:
4917+
- ID: 0
4918+
Table:
4919+
- Code: 0x1
4920+
Tag: DW_TAG_compile_unit
4921+
Children: DW_CHILDREN_no
4922+
Attributes:
4923+
- Attribute: DW_AT_name
4924+
Form: DW_FORM_strp
4925+
- Attribute: DW_AT_language
4926+
Form: DW_FORM_udata
4927+
- Attribute: DW_AT_GNU_dwo_id
4928+
Form: DW_FORM_data4
4929+
debug_info:
4930+
- Length: 0x11
4931+
Version: 4
4932+
AbbrevTableID: 0
4933+
AbbrOffset: 0x0
4934+
AddrSize: 8
4935+
Entries:
4936+
- AbbrCode: 0x1
4937+
Values:
4938+
- Value: 0x1
4939+
- Value: 0x2
4940+
- Value: 0xFFFFFFFE
4941+
)";
4942+
auto ErrOrSections = DWARFYAML::emitDebugSections(yamldata);
4943+
ASSERT_THAT_EXPECTED(ErrOrSections, Succeeded());
4944+
std::unique_ptr<DWARFContext> DwarfContext =
4945+
DWARFContext::create(*ErrOrSections, 8);
4946+
ASSERT_TRUE(DwarfContext.get() != nullptr);
4947+
std::string errors;
4948+
raw_string_ostream OS(errors);
4949+
OutputAggregator OSAgg(&OS);
4950+
GsymCreator GC;
4951+
// Make a DWARF transformer that is MachO (Apple) to avoid warnings about
4952+
// not finding DWO files.
4953+
DwarfTransformer DT(*DwarfContext, GC, /*LDCS=*/false, /*MachO*/ true);
4954+
const uint32_t ThreadCount = 1;
4955+
ASSERT_THAT_ERROR(DT.convert(ThreadCount, OSAgg), Succeeded());
4956+
ASSERT_THAT_ERROR(GC.finalize(OSAgg), Succeeded());
4957+
4958+
// Make sure this warning is not in the binary
4959+
std::string warn("warning: Unable to retrieve DWO .debug_info section for");
4960+
EXPECT_TRUE(errors.find(warn) == std::string::npos);
4961+
}

0 commit comments

Comments
 (0)