[llvm] r261988 - llvm-dwp: provide diagnostics for duplicate DWO IDs
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 25 23:30:16 PST 2016
Author: dblaikie
Date: Fri Feb 26 01:30:15 2016
New Revision: 261988
URL: http://llvm.org/viewvc/llvm-project?rev=261988&view=rev
Log:
llvm-dwp: provide diagnostics for duplicate DWO IDs
These diagnostics aren't perfect - in the case of merging several dwos
into dwps and those dwps into more dwps - just getting the message about
the original source file name might not be much help (since it's the
same in both dwos, by definition - but doesn't tell you which chain of
dwps to backtrack)
It might be worth adding the DW_AT_dwo_id to the split debug info to
improve the diagnostic experience - might help track down the duplicates
better.
Added:
llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate/
llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate/ac.dwp
llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate/bc.dwp
llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate/c.dwo
llvm/trunk/test/tools/llvm-dwp/X86/duplicate.test
Modified:
llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
Added: llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate/ac.dwp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate/ac.dwp?rev=261988&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate/ac.dwp (added) and llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate/ac.dwp Fri Feb 26 01:30:15 2016 differ
Added: llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate/bc.dwp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate/bc.dwp?rev=261988&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate/bc.dwp (added) and llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate/bc.dwp Fri Feb 26 01:30:15 2016 differ
Added: llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate/c.dwo
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate/c.dwo?rev=261988&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate/c.dwo (added) and llvm/trunk/test/tools/llvm-dwp/Inputs/duplicate/c.dwo Fri Feb 26 01:30:15 2016 differ
Added: llvm/trunk/test/tools/llvm-dwp/X86/duplicate.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/X86/duplicate.test?rev=261988&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-dwp/X86/duplicate.test (added)
+++ llvm/trunk/test/tools/llvm-dwp/X86/duplicate.test Fri Feb 26 01:30:15 2016
@@ -0,0 +1,18 @@
+RUN: not llvm-dwp %p/../Inputs/duplicate/c.dwo %p/../Inputs/duplicate/c.dwo -o %t 2>&1 \
+RUN: | FileCheck --check-prefix=CHECK %s
+
+RUN: not llvm-dwp %p/../Inputs/duplicate/c.dwo %p/../Inputs/duplicate/bc.dwp -o %t 2>&1 \
+RUN: | FileCheck --check-prefix=CHECK --check-prefix=DWP2 %s
+
+RUN: not llvm-dwp %p/../Inputs/duplicate/ac.dwp %p/../Inputs/duplicate/c.dwo -o %t 2>&1 \
+RUN: | FileCheck --check-prefix=CHECK --check-prefix=DWP1 %s
+
+RUN: not llvm-dwp %p/../Inputs/duplicate/ac.dwp %p/../Inputs/duplicate/bc.dwp -o %t 2>&1 \
+RUN: | FileCheck --check-prefix=CHECK --check-prefix=DWP1 --check-prefix=DWP2 %s
+
+Build from a, b, and c.c all containing a single void() func by the name of the file.
+
+CHECK: Duplicate DWO ID ({{.*}}) in 'c.c'
+DWP1-SAME: (from '{{.*}}ac.dwp')
+CHECK-SAME: and 'c.c'
+DWP2-SAME: (from '{{.*}}bc.dwp')
Modified: llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp?rev=261988&r1=261987&r2=261988&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp (original)
+++ llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp Fri Feb 26 01:30:15 2016
@@ -24,6 +24,7 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
#include <list>
+#include <iostream>
#include <memory>
#include <system_error>
#include <unordered_set>
@@ -106,6 +107,43 @@ static uint32_t getCUAbbrev(StringRef Ab
return Offset;
}
+static const char *getCUName(StringRef Abbrev, StringRef Info,
+ StringRef StrOffsets, StringRef Str) {
+ uint32_t Offset = 0;
+ DataExtractor InfoData(Info, true, 0);
+ InfoData.getU32(&Offset); // Length
+ uint16_t Version = InfoData.getU16(&Offset);
+ InfoData.getU32(&Offset); // Abbrev offset (should be zero)
+ uint8_t AddrSize = InfoData.getU8(&Offset);
+
+ uint32_t AbbrCode = InfoData.getULEB128(&Offset);
+
+ DataExtractor AbbrevData(Abbrev, true, 0);
+ uint32_t AbbrevOffset = getCUAbbrev(Abbrev, AbbrCode);
+ uint64_t Tag = AbbrevData.getULEB128(&AbbrevOffset);
+ (void)Tag;
+ // FIXME: Real error handling
+ assert(Tag == dwarf::DW_TAG_compile_unit);
+ // DW_CHILDREN
+ AbbrevData.getU8(&AbbrevOffset);
+ uint32_t Name;
+ uint32_t Form;
+ while ((Name = AbbrevData.getULEB128(&AbbrevOffset)) |
+ (Form = AbbrevData.getULEB128(&AbbrevOffset)) &&
+ Name != dwarf::DW_AT_name) {
+ DWARFFormValue::skipValue(Form, InfoData, &Offset, Version, AddrSize);
+ }
+ // FIXME: Real error handling
+ assert(Name == dwarf::DW_AT_name);
+ auto StrIndex = InfoData.getULEB128(&Offset);
+
+ DataExtractor StrOffsetsData(StrOffsets, true, 0);
+ uint32_t StrOffsetsOffset = 4 * StrIndex;
+ uint32_t StrOffset = StrOffsetsData.getU32(&StrOffsetsOffset);
+ DataExtractor StrData(Str, true, 0);
+ return StrData.getCStr(&StrOffset);
+}
+
static uint64_t getCUSignature(StringRef Abbrev, StringRef Info) {
uint32_t Offset = 0;
DataExtractor InfoData(Info, true, 0);
@@ -138,8 +176,17 @@ static uint64_t getCUSignature(StringRef
struct UnitIndexEntry {
DWARFUnitIndex::Entry::SectionContribution Contributions[8];
+ std::string Name;
+ StringRef DWPName;
};
+StringRef getSubsection(StringRef Section, const DWARFUnitIndex::Entry &Entry, DWARFSectionKind Kind) {
+ const auto *Off = Entry.getOffset(Kind);
+ if (!Off)
+ return StringRef();
+ return Section.substr(Off->Offset, Off->Length);
+}
+
static void addAllTypesFromDWP(
MCStreamer &Out, MapVector<uint64_t, UnitIndexEntry> &TypeIndexEntries,
const DWARFUnitIndex &TUIndex, MCSection *OutputTypes, StringRef Types,
@@ -416,8 +463,22 @@ static std::error_code write(MCStreamer
continue;
auto P =
IndexEntries.insert(std::make_pair(E.getSignature(), CurEntry));
- // FIXME: Check P.second and error for duplicate CU signatures
+ const char* Name = getCUName(
+ getSubsection(AbbrevSection, E, DW_SECT_ABBREV),
+ getSubsection(InfoSection, E, DW_SECT_INFO),
+ getSubsection(CurStrOffsetSection, E, DW_SECT_STR_OFFSETS),
+ CurStrSection);
+ if (!P.second) {
+ auto &PrevE = *P.first;
+ std::cerr << "Duplicate DWO ID (" << PrevE.first << ") in '" << PrevE.second.Name << "' ";
+ if (!PrevE.second.DWPName.empty())
+ std::cerr << "(from '" << PrevE.second.DWPName.str() << "') ";
+ std::cerr << "and '" << Name << "' (from '" << Input << "')\n";
+ return make_error_code(std::errc::invalid_argument);
+ }
auto &NewEntry = P.first->second;
+ NewEntry.Name = Name;
+ NewEntry.DWPName = Input;
for (auto Kind : CUIndex.getColumnKinds()) {
auto &C = NewEntry.Contributions[Kind - DW_SECT_INFO];
C.Offset += I->Offset;
@@ -439,9 +500,20 @@ static std::error_code write(MCStreamer
ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]);
}
} else {
- IndexEntries.insert(
+ auto P = IndexEntries.insert(
std::make_pair(getCUSignature(AbbrevSection, InfoSection), CurEntry));
- // FIXME: Check P.second and error for duplicate CU signatures
+ const char *Name = getCUName(AbbrevSection, InfoSection,
+ CurStrOffsetSection, CurStrSection);
+ if (!P.second) {
+ auto &E = *P.first;
+ std::cerr << "Duplicate DWO ID (" << E.first << ") in '" << Name
+ << "' ";
+ if (!E.second.DWPName.empty())
+ std::cerr << "(from '" << E.second.DWPName.str() << "') ";
+ std::cerr << "and '" << E.second.Name << "'\n";
+ return make_error_code(std::errc::invalid_argument);
+ }
+ P.first->second.Name = Name;
addAllTypes(Out, TypeIndexEntries, TypesSection, CurTypesSection,
CurEntry, ContributionOffsets[DW_SECT_TYPES - DW_SECT_INFO]);
}
More information about the llvm-commits
mailing list