Skip to content

Commit 697b34f

Browse files
authored
[dsymutil] Remove paper trail warnings (llvm#67041)
Remove the paper trail warning from dsymutil and the DWARF linker. The original purpose of this functionality was to leave a paper trail in the output artifact about missing object files. The current implementation however has diverged and is the source of a pretty serious bug: - In the debug map parser, missing object files are not the only warnings we emit. When paper trail warnings are enabled, all of them end up in the dSYM which wasn't the goal. - When warnings are associated with a object file in the debug map, it is skipped by the DWARF linker. This only makes sense if the object file is missing and is obviously incorrect for any other type of warning (such as a missing symbol). The combination of the two means that we can generate broken DWARF when the feature is enabled. AFAIK it was only used by Apple and nobody I spoke to has relied on it, so rather than fixing the broken behavior I propose we remove it.
1 parent d7359bc commit 697b34f

File tree

17 files changed

+31
-313
lines changed

17 files changed

+31
-313
lines changed

llvm/docs/CommandGuide/dsymutil.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,6 @@ OPTIONS
100100
Specifies an alternate ``path`` to place the dSYM bundle. The default dSYM
101101
bundle path is created by appending ``.dSYM`` to the executable name.
102102

103-
.. option:: --papertrail
104-
105-
When running dsymutil as part of your build system, it can be desirable for
106-
warnings to be part of the end product, rather than just being emitted to the
107-
output stream. When enabled warnings are embedded in the linked DWARF debug
108-
information.
109-
110103
.. option:: --remarks-drop-without-debug
111104

112105
Drop remarks without valid debug locations. Without this flags, all remarks are kept.

llvm/include/llvm/DWARFLinker/DWARFLinker.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ class DwarfEmitter {
9999
public:
100100
virtual ~DwarfEmitter();
101101

102-
/// Emit DIE containing warnings.
103-
virtual void emitPaperTrailWarningsDie(DIE &Die) = 0;
104-
105102
/// Emit section named SecName with data SecData.
106103
virtual void emitSectionContents(StringRef SecData, StringRef SecName) = 0;
107104

@@ -272,11 +269,9 @@ class DWARFFile {
272269
public:
273270
using UnloadCallbackTy = std::function<void(StringRef FileName)>;
274271
DWARFFile(StringRef Name, std::unique_ptr<DWARFContext> Dwarf,
275-
std::unique_ptr<AddressesMap> Addresses,
276-
const std::vector<std::string> &Warnings,
277-
UnloadCallbackTy = nullptr)
272+
std::unique_ptr<AddressesMap> Addresses, UnloadCallbackTy = nullptr)
278273
: FileName(Name), Dwarf(std::move(Dwarf)),
279-
Addresses(std::move(Addresses)), Warnings(Warnings) {}
274+
Addresses(std::move(Addresses)) {}
280275

281276
/// The object file name.
282277
StringRef FileName;
@@ -286,9 +281,6 @@ class DWARFFile {
286281

287282
/// Helpful address information(list of valid address ranges, relocations).
288283
std::unique_ptr<AddressesMap> Addresses;
289-
290-
/// Warnings for this object file.
291-
const std::vector<std::string> &Warnings;
292284
};
293285

294286
typedef std::map<std::string, std::string> swiftInterfacesMap;
@@ -508,10 +500,6 @@ class DWARFLinker {
508500
ErrorHandler(Warning, File.FileName, DIE);
509501
}
510502

511-
/// Emit warnings as Dwarf compile units to leave a trail after linking.
512-
bool emitPaperTrailWarnings(const DWARFFile &File,
513-
OffsetsStringPool &StringPool);
514-
515503
void copyInvariantDebugSection(DWARFContext &Dwarf);
516504

517505
/// Keep information for referenced clang module: already loaded DWARF info

llvm/include/llvm/DWARFLinker/DWARFStreamer.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ class DwarfStreamer : public DwarfEmitter {
7272
void emitAbbrevs(const std::vector<std::unique_ptr<DIEAbbrev>> &Abbrevs,
7373
unsigned DwarfVersion) override;
7474

75-
/// Emit DIE containing warnings.
76-
void emitPaperTrailWarningsDie(DIE &Die) override;
77-
7875
/// Emit contents of section SecName From Obj.
7976
void emitSectionContents(StringRef SecData, StringRef SecName) override;
8077

llvm/include/llvm/DWARFLinkerParallel/DWARFFile.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class DWARFFile {
2929

3030
DWARFFile(StringRef Name, std::unique_ptr<DWARFContext> Dwarf,
3131
std::unique_ptr<AddressesMap> Addresses,
32-
const std::vector<std::string> &Warnings,
3332
UnloadCallbackTy UnloadFunc = nullptr);
3433

3534
/// Object file name.
@@ -41,9 +40,6 @@ class DWARFFile {
4140
/// Helpful address information(list of valid address ranges, relocations).
4241
std::unique_ptr<AddressesMap> Addresses;
4342

44-
/// Warnings for object file.
45-
const std::vector<std::string> &Warnings;
46-
4743
/// Callback to the module keeping object file to unload.
4844
UnloadCallbackTy UnloadFunc;
4945

llvm/lib/DWARFLinker/DWARFLinker.cpp

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2584,69 +2584,6 @@ uint64_t DWARFLinker::DIECloner::cloneAllCompileUnits(
25842584
return OutputDebugInfoSize - StartOutputDebugInfoSize;
25852585
}
25862586

2587-
bool DWARFLinker::emitPaperTrailWarnings(const DWARFFile &File,
2588-
OffsetsStringPool &StringPool) {
2589-
2590-
if (File.Warnings.empty())
2591-
return false;
2592-
2593-
DIE *CUDie = DIE::get(DIEAlloc, dwarf::DW_TAG_compile_unit);
2594-
CUDie->setOffset(11);
2595-
StringRef Producer;
2596-
StringRef WarningHeader;
2597-
2598-
switch (DwarfLinkerClientID) {
2599-
case DwarfLinkerClient::Dsymutil:
2600-
Producer = StringPool.internString("dsymutil");
2601-
WarningHeader = "dsymutil_warning";
2602-
break;
2603-
2604-
default:
2605-
Producer = StringPool.internString("dwarfopt");
2606-
WarningHeader = "dwarfopt_warning";
2607-
break;
2608-
}
2609-
2610-
StringRef FileName = StringPool.internString(File.FileName);
2611-
CUDie->addValue(DIEAlloc, dwarf::DW_AT_producer, dwarf::DW_FORM_strp,
2612-
DIEInteger(StringPool.getStringOffset(Producer)));
2613-
DIEBlock *String = new (DIEAlloc) DIEBlock();
2614-
DIEBlocks.push_back(String);
2615-
for (auto &C : FileName)
2616-
String->addValue(DIEAlloc, dwarf::Attribute(0), dwarf::DW_FORM_data1,
2617-
DIEInteger(C));
2618-
String->addValue(DIEAlloc, dwarf::Attribute(0), dwarf::DW_FORM_data1,
2619-
DIEInteger(0));
2620-
2621-
CUDie->addValue(DIEAlloc, dwarf::DW_AT_name, dwarf::DW_FORM_string, String);
2622-
for (const auto &Warning : File.Warnings) {
2623-
DIE &ConstDie = CUDie->addChild(DIE::get(DIEAlloc, dwarf::DW_TAG_constant));
2624-
ConstDie.addValue(DIEAlloc, dwarf::DW_AT_name, dwarf::DW_FORM_strp,
2625-
DIEInteger(StringPool.getStringOffset(WarningHeader)));
2626-
ConstDie.addValue(DIEAlloc, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag,
2627-
DIEInteger(1));
2628-
ConstDie.addValue(DIEAlloc, dwarf::DW_AT_const_value, dwarf::DW_FORM_strp,
2629-
DIEInteger(StringPool.getStringOffset(Warning)));
2630-
}
2631-
unsigned Size = 4 /* FORM_strp */ + FileName.size() + 1 +
2632-
File.Warnings.size() * (4 + 1 + 4) + 1 /* End of children */;
2633-
DIEAbbrev Abbrev = CUDie->generateAbbrev();
2634-
assignAbbrev(Abbrev);
2635-
CUDie->setAbbrevNumber(Abbrev.getNumber());
2636-
Size += getULEB128Size(Abbrev.getNumber());
2637-
// Abbreviation ordering needed for classic compatibility.
2638-
for (auto &Child : CUDie->children()) {
2639-
Abbrev = Child.generateAbbrev();
2640-
assignAbbrev(Abbrev);
2641-
Child.setAbbrevNumber(Abbrev.getNumber());
2642-
Size += getULEB128Size(Abbrev.getNumber());
2643-
}
2644-
CUDie->setSize(Size);
2645-
TheDwarfEmitter->emitPaperTrailWarningsDie(*CUDie);
2646-
2647-
return true;
2648-
}
2649-
26502587
void DWARFLinker::copyInvariantDebugSection(DWARFContext &Dwarf) {
26512588
TheDwarfEmitter->emitSectionContents(Dwarf.getDWARFObj().getLocSection().Data,
26522589
"debug_loc");
@@ -2711,9 +2648,6 @@ Error DWARFLinker::link() {
27112648
outs() << "OBJECT FILE: " << OptContext.File.FileName << "\n";
27122649
}
27132650

2714-
if (emitPaperTrailWarnings(OptContext.File, DebugStrPool))
2715-
continue;
2716-
27172651
if (!OptContext.File.Dwarf)
27182652
continue;
27192653

llvm/lib/DWARFLinker/DWARFStreamer.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -234,18 +234,6 @@ void DwarfStreamer::emitSectionContents(StringRef SecData, StringRef SecName) {
234234
}
235235
}
236236

237-
/// Emit DIE containing warnings.
238-
void DwarfStreamer::emitPaperTrailWarningsDie(DIE &Die) {
239-
switchToDebugInfoSection(/* Version */ 2);
240-
auto &Asm = getAsmPrinter();
241-
Asm.emitInt32(11 + Die.getSize() - 4);
242-
Asm.emitInt16(2);
243-
Asm.emitInt32(0);
244-
Asm.emitInt8(MC->getTargetTriple().isArch64Bit() ? 8 : 4);
245-
DebugInfoSectionSize += 11;
246-
emitDIE(Die);
247-
}
248-
249237
/// Emit the debug_str section stored in \p Pool.
250238
void DwarfStreamer::emitStrings(const NonRelocatableStringpool &Pool) {
251239
Asm->OutStreamer->switchSection(MOFI->getDwarfStrSection());

llvm/lib/DWARFLinkerParallel/DWARFFile.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
llvm::dwarflinker_parallel::DWARFFile::DWARFFile(
1313
StringRef Name, std::unique_ptr<DWARFContext> Dwarf,
1414
std::unique_ptr<AddressesMap> Addresses,
15-
const std::vector<std::string> &Warnings,
1615
DWARFFile::UnloadCallbackTy UnloadFunc)
1716
: FileName(Name), Dwarf(std::move(Dwarf)), Addresses(std::move(Addresses)),
18-
Warnings(Warnings), UnloadFunc(UnloadFunc) {}
17+
UnloadFunc(UnloadFunc) {}

llvm/lib/DWARFLinkerParallel/DWARFLinkerImpl.cpp

Lines changed: 18 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -371,27 +371,26 @@ Error DWARFLinkerImpl::LinkContext::loadClangModule(
371371

372372
Error DWARFLinkerImpl::LinkContext::link() {
373373
InterCUProcessingStarted = false;
374-
if (InputDWARFFile.Warnings.empty()) {
375-
if (!InputDWARFFile.Dwarf)
376-
return Error::success();
374+
if (!InputDWARFFile.Dwarf)
375+
return Error::success();
377376

378-
// Preload macro tables, as they can't be loaded asynchronously.
379-
InputDWARFFile.Dwarf->getDebugMacinfo();
380-
InputDWARFFile.Dwarf->getDebugMacro();
377+
// Preload macro tables, as they can't be loaded asynchronously.
378+
InputDWARFFile.Dwarf->getDebugMacinfo();
379+
InputDWARFFile.Dwarf->getDebugMacro();
381380

382-
// Link modules compile units first.
383-
parallelForEach(ModulesCompileUnits, [&](RefModuleUnit &RefModule) {
384-
linkSingleCompileUnit(*RefModule.Unit);
385-
});
381+
// Link modules compile units first.
382+
parallelForEach(ModulesCompileUnits, [&](RefModuleUnit &RefModule) {
383+
linkSingleCompileUnit(*RefModule.Unit);
384+
});
386385

387-
// Check for live relocations. If there is no any live relocation then we
388-
// can skip entire object file.
389-
if (!GlobalData.getOptions().UpdateIndexTablesOnly &&
390-
!InputDWARFFile.Addresses->hasValidRelocs()) {
391-
if (GlobalData.getOptions().Verbose)
392-
outs() << "No valid relocations found. Skipping.\n";
393-
return Error::success();
394-
}
386+
// Check for live relocations. If there is no any live relocation then we
387+
// can skip entire object file.
388+
if (!GlobalData.getOptions().UpdateIndexTablesOnly &&
389+
!InputDWARFFile.Addresses->hasValidRelocs()) {
390+
if (GlobalData.getOptions().Verbose)
391+
outs() << "No valid relocations found. Skipping.\n";
392+
return Error::success();
393+
}
395394

396395
OriginalDebugInfoSize = getInputDebugInfoSize();
397396

@@ -460,21 +459,8 @@ Error DWARFLinkerImpl::LinkContext::link() {
460459
linkSingleCompileUnit(*CU, CompileUnit::Stage::Cleaned);
461460
});
462461
}
463-
}
464462

465-
if (!InputDWARFFile.Warnings.empty()) {
466-
// Create compile unit with paper trail warnings.
467-
468-
Error ResultErr = Error::success();
469-
// We use task group here as PerThreadBumpPtrAllocator should be called from
470-
// the threads created by ThreadPoolExecutor.
471-
parallel::TaskGroup TGroup;
472-
TGroup.spawn([&]() {
473-
if (Error Err = cloneAndEmitPaperTrails())
474-
ResultErr = std::move(Err);
475-
});
476-
return ResultErr;
477-
} else if (GlobalData.getOptions().UpdateIndexTablesOnly) {
463+
if (GlobalData.getOptions().UpdateIndexTablesOnly) {
478464
// Emit Invariant sections.
479465

480466
if (Error Err = emitInvariantSections())
@@ -715,102 +701,6 @@ void DWARFLinkerImpl::LinkContext::emitFDE(uint32_t CIEOffset,
715701
Section.OS.write(FDEBytes.data(), FDEBytes.size());
716702
}
717703

718-
Error DWARFLinkerImpl::LinkContext::cloneAndEmitPaperTrails() {
719-
CompileUnits.emplace_back(std::make_unique<CompileUnit>(
720-
GlobalData, UniqueUnitID.fetch_add(1), "", InputDWARFFile,
721-
getUnitForOffset, Format, Endianness));
722-
723-
CompileUnit &CU = *CompileUnits.back();
724-
725-
BumpPtrAllocator Allocator;
726-
727-
DIEGenerator ParentGenerator(Allocator, CU);
728-
729-
SectionDescriptor &DebugInfoSection =
730-
CU.getOrCreateSectionDescriptor(DebugSectionKind::DebugInfo);
731-
OffsetsPtrVector PatchesOffsets;
732-
733-
uint64_t CurrentOffset = CU.getDebugInfoHeaderSize();
734-
DIE *CUDie =
735-
ParentGenerator.createDIE(dwarf::DW_TAG_compile_unit, CurrentOffset);
736-
CU.setOutUnitDIE(CUDie);
737-
738-
DebugInfoSection.notePatchWithOffsetUpdate(
739-
DebugStrPatch{{CurrentOffset},
740-
GlobalData.getStringPool().insert("dsymutil").first},
741-
PatchesOffsets);
742-
CurrentOffset += ParentGenerator
743-
.addStringPlaceholderAttribute(dwarf::DW_AT_producer,
744-
dwarf::DW_FORM_strp)
745-
.second;
746-
747-
CurrentOffset +=
748-
ParentGenerator
749-
.addInplaceString(dwarf::DW_AT_name, InputDWARFFile.FileName)
750-
.second;
751-
752-
size_t SizeAbbrevNumber = ParentGenerator.finalizeAbbreviations(true);
753-
CurrentOffset += SizeAbbrevNumber;
754-
for (uint64_t *OffsetPtr : PatchesOffsets)
755-
*OffsetPtr += SizeAbbrevNumber;
756-
for (const auto &Warning : CU.getContaingFile().Warnings) {
757-
PatchesOffsets.clear();
758-
DIEGenerator ChildGenerator(Allocator, CU);
759-
760-
DIE *ChildDie =
761-
ChildGenerator.createDIE(dwarf::DW_TAG_constant, CurrentOffset);
762-
ParentGenerator.addChild(ChildDie);
763-
764-
DebugInfoSection.notePatchWithOffsetUpdate(
765-
DebugStrPatch{
766-
{CurrentOffset},
767-
GlobalData.getStringPool().insert("dsymutil_warning").first},
768-
PatchesOffsets);
769-
CurrentOffset += ChildGenerator
770-
.addStringPlaceholderAttribute(dwarf::DW_AT_name,
771-
dwarf::DW_FORM_strp)
772-
.second;
773-
774-
CurrentOffset +=
775-
ChildGenerator
776-
.addScalarAttribute(dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1)
777-
.second;
778-
779-
DebugInfoSection.notePatchWithOffsetUpdate(
780-
DebugStrPatch{{CurrentOffset},
781-
GlobalData.getStringPool().insert(Warning).first},
782-
PatchesOffsets);
783-
CurrentOffset += ChildGenerator
784-
.addStringPlaceholderAttribute(
785-
dwarf::DW_AT_const_value, dwarf::DW_FORM_strp)
786-
.second;
787-
788-
SizeAbbrevNumber = ChildGenerator.finalizeAbbreviations(false);
789-
790-
CurrentOffset += SizeAbbrevNumber;
791-
for (uint64_t *OffsetPtr : PatchesOffsets)
792-
*OffsetPtr += SizeAbbrevNumber;
793-
794-
ChildDie->setSize(CurrentOffset - ChildDie->getOffset());
795-
}
796-
797-
CurrentOffset += 1; // End of children
798-
CUDie->setSize(CurrentOffset - CUDie->getOffset());
799-
800-
uint64_t UnitSize = 0;
801-
UnitSize += CU.getDebugInfoHeaderSize();
802-
UnitSize += CUDie->getSize();
803-
CU.setUnitSize(UnitSize);
804-
805-
if (GlobalData.getOptions().NoOutput)
806-
return Error::success();
807-
808-
if (Error Err = CU.emitDebugInfo(*TargetTriple))
809-
return Err;
810-
811-
return CU.emitAbbreviations();
812-
}
813-
814704
void DWARFLinkerImpl::glueCompileUnitsAndWriteToTheOutput() {
815705
if (GlobalData.getOptions().NoOutput)
816706
return;

llvm/lib/DWARFLinkerParallel/DWARFLinkerImpl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,6 @@ class DWARFLinkerImpl : public DWARFLinker {
294294
void emitFDE(uint32_t CIEOffset, uint32_t AddrSize, uint64_t Address,
295295
StringRef FDEBytes, SectionDescriptor &Section);
296296

297-
/// Clone and emit paper trails.
298-
Error cloneAndEmitPaperTrails();
299-
300297
std::function<CompileUnit *(uint64_t)> getUnitForOffset =
301298
[&](uint64_t Offset) -> CompileUnit * {
302299
auto CU = llvm::upper_bound(

0 commit comments

Comments
 (0)