1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 12:12:47 +01:00

DebugInfo: Add metadata support for disabling DWARF pub sections

In cases where the debugger load time is a worthwhile tradeoff (or less
costly - such as loading from a DWP instead of a variety of DWOs
(possibly over a high-latency/distributed filesystem)) against object
file size, it can be reasonable to disable pubnames and corresponding
gdb-index creation in the linker.

A backend-flag version of this was implemented for NVPTX in
D44385/r327994 - which was fine for NVPTX which wouldn't mix-and-match
CUs. Now that it's going to be a user-facing option (likely powered by
"-gno-pubnames", the same as GCC) it should be encoded in the
DICompileUnit so it can vary per-CU.

After this, likely the NVPTX support should be migrated to the metadata
& the previous flag implementation should be removed.

Reviewers: aprantl

Differential Revision: https://reviews.llvm.org/D50213

llvm-svn: 339939
This commit is contained in:
David Blaikie 2018-08-16 21:29:55 +00:00
parent 359d729ed5
commit f435a2459a
27 changed files with 289 additions and 76 deletions

View File

@ -134,8 +134,8 @@ namespace llvm {
/// \param SplitDebugInlining Whether to emit inline debug info.
/// \param DebugInfoForProfiling Whether to emit extra debug info for
/// profile collection.
/// \param GnuPubnames Whether to emit .debug_gnu_pubnames section instead
/// of .debug_pubnames.
/// \param nameTableKind Whether to emit .debug_gnu_pubnames,
/// .debug_pubnames, or no pubnames at all.
DICompileUnit *
createCompileUnit(unsigned Lang, DIFile *File, StringRef Producer,
bool isOptimized, StringRef Flags, unsigned RV,
@ -144,7 +144,8 @@ namespace llvm {
DICompileUnit::DebugEmissionKind::FullDebug,
uint64_t DWOId = 0, bool SplitDebugInlining = true,
bool DebugInfoForProfiling = false,
bool GnuPubnames = false);
DICompileUnit::DebugNameTableKind NameTableKind =
DICompileUnit::DebugNameTableKind::Default);
/// Create a file descriptor to hold debugging information for a file.
/// \param Filename File name.

View File

@ -1171,8 +1171,17 @@ public:
LastEmissionKind = DebugDirectivesOnly
};
enum class DebugNameTableKind : unsigned {
Default = 0,
GNU = 1,
None = 2,
LastDebugNameTableKind = None
};
static Optional<DebugEmissionKind> getEmissionKind(StringRef Str);
static const char *emissionKindString(DebugEmissionKind EK);
static Optional<DebugNameTableKind> getNameTableKind(StringRef Str);
static const char *nameTableKindString(DebugNameTableKind PK);
private:
unsigned SourceLanguage;
@ -1182,17 +1191,19 @@ private:
uint64_t DWOId;
bool SplitDebugInlining;
bool DebugInfoForProfiling;
bool GnuPubnames;
unsigned NameTableKind;
DICompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
bool IsOptimized, unsigned RuntimeVersion,
unsigned EmissionKind, uint64_t DWOId, bool SplitDebugInlining,
bool DebugInfoForProfiling, bool GnuPubnames, ArrayRef<Metadata *> Ops)
bool DebugInfoForProfiling, unsigned NameTableKind,
ArrayRef<Metadata *> Ops)
: DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind),
DWOId(DWOId), SplitDebugInlining(SplitDebugInlining),
DebugInfoForProfiling(DebugInfoForProfiling), GnuPubnames(GnuPubnames) {
DebugInfoForProfiling(DebugInfoForProfiling),
NameTableKind(NameTableKind) {
assert(Storage != Uniqued);
}
~DICompileUnit() = default;
@ -1206,14 +1217,15 @@ private:
DIGlobalVariableExpressionArray GlobalVariables,
DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
bool GnuPubnames, StorageType Storage, bool ShouldCreate = true) {
unsigned NameTableKind, StorageType Storage,
bool ShouldCreate = true) {
return getImpl(
Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
IsOptimized, getCanonicalMDString(Context, Flags), RuntimeVersion,
getCanonicalMDString(Context, SplitDebugFilename), EmissionKind,
EnumTypes.get(), RetainedTypes.get(), GlobalVariables.get(),
ImportedEntities.get(), Macros.get(), DWOId, SplitDebugInlining,
DebugInfoForProfiling, GnuPubnames, Storage, ShouldCreate);
DebugInfoForProfiling, NameTableKind, Storage, ShouldCreate);
}
static DICompileUnit *
getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
@ -1222,8 +1234,8 @@ private:
unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
Metadata *GlobalVariables, Metadata *ImportedEntities,
Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining,
bool DebugInfoForProfiling, bool GnuPubnames, StorageType Storage,
bool ShouldCreate = true);
bool DebugInfoForProfiling, unsigned NameTableKind,
StorageType Storage, bool ShouldCreate = true);
TempDICompileUnit cloneImpl() const {
return getTemporary(getContext(), getSourceLanguage(), getFile(),
@ -1232,7 +1244,7 @@ private:
getEmissionKind(), getEnumTypes(), getRetainedTypes(),
getGlobalVariables(), getImportedEntities(),
getMacros(), DWOId, getSplitDebugInlining(),
getDebugInfoForProfiling(), getGnuPubnames());
getDebugInfoForProfiling(), getNameTableKind());
}
public:
@ -1248,11 +1260,11 @@ public:
DIGlobalVariableExpressionArray GlobalVariables,
DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
bool GnuPubnames),
DebugNameTableKind NameTableKind),
(SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
DebugInfoForProfiling, GnuPubnames))
DebugInfoForProfiling, (unsigned)NameTableKind))
DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(
DICompileUnit,
(unsigned SourceLanguage, Metadata *File, MDString *Producer,
@ -1260,11 +1272,12 @@ public:
MDString *SplitDebugFilename, unsigned EmissionKind, Metadata *EnumTypes,
Metadata *RetainedTypes, Metadata *GlobalVariables,
Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId,
bool SplitDebugInlining, bool DebugInfoForProfiling, bool GnuPubnames),
bool SplitDebugInlining, bool DebugInfoForProfiling,
unsigned NameTableKind),
(SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
DebugInfoForProfiling, GnuPubnames))
DebugInfoForProfiling, NameTableKind))
TempDICompileUnit clone() const { return cloneImpl(); }
@ -1278,7 +1291,9 @@ public:
return EmissionKind == DebugDirectivesOnly;
}
bool getDebugInfoForProfiling() const { return DebugInfoForProfiling; }
bool getGnuPubnames() const { return GnuPubnames; }
DebugNameTableKind getNameTableKind() const {
return (DebugNameTableKind)NameTableKind;
}
StringRef getProducer() const { return getStringOperand(1); }
StringRef getFlags() const { return getStringOperand(2); }
StringRef getSplitDebugFilename() const { return getStringOperand(3); }

View File

@ -910,6 +910,11 @@ lltok::Kind LLLexer::LexIdentifier() {
return lltok::EmissionKind;
}
if (Keyword == "GNU" || Keyword == "None" || Keyword == "Default") {
StrVal.assign(Keyword.begin(), Keyword.end());
return lltok::NameTableKind;
}
// Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
// the CFE to avoid forcing it to deal with 64-bit numbers.
if ((TokStart[0] == 'u' || TokStart[0] == 's') &&

View File

@ -3718,6 +3718,13 @@ struct EmissionKindField : public MDUnsignedField {
EmissionKindField() : MDUnsignedField(0, DICompileUnit::LastEmissionKind) {}
};
struct NameTableKindField : public MDUnsignedField {
NameTableKindField()
: MDUnsignedField(
0, (unsigned)
DICompileUnit::DebugNameTableKind::LastDebugNameTableKind) {}
};
struct DIFlagField : public MDFieldImpl<DINode::DIFlags> {
DIFlagField() : MDFieldImpl(DINode::FlagZero) {}
};
@ -3936,6 +3943,25 @@ bool LLParser::ParseMDField(LocTy Loc, StringRef Name, EmissionKindField &Result
return false;
}
template <>
bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
NameTableKindField &Result) {
if (Lex.getKind() == lltok::APSInt)
return ParseMDField(Loc, Name, static_cast<MDUnsignedField &>(Result));
if (Lex.getKind() != lltok::NameTableKind)
return TokError("expected nameTable kind");
auto Kind = DICompileUnit::getNameTableKind(Lex.getStrVal());
if (!Kind)
return TokError("invalid nameTable kind" + Twine(" '") + Lex.getStrVal() +
"'");
assert(((unsigned)*Kind) <= Result.Max && "Expected valid nameTable kind");
Result.assign((unsigned)*Kind);
Lex.Lex();
return false;
}
template <>
bool LLParser::ParseMDField(LocTy Loc, StringRef Name,
DwarfAttEncodingField &Result) {
@ -4448,7 +4474,7 @@ bool LLParser::ParseDICompileUnit(MDNode *&Result, bool IsDistinct) {
OPTIONAL(dwoId, MDUnsignedField, ); \
OPTIONAL(splitDebugInlining, MDBoolField, = true); \
OPTIONAL(debugInfoForProfiling, MDBoolField, = false); \
OPTIONAL(gnuPubnames, MDBoolField, = false);
OPTIONAL(nameTableKind, NameTableKindField, );
PARSE_MD_FIELDS();
#undef VISIT_MD_FIELDS
@ -4456,7 +4482,7 @@ bool LLParser::ParseDICompileUnit(MDNode *&Result, bool IsDistinct) {
Context, language.Val, file.Val, producer.Val, isOptimized.Val, flags.Val,
runtimeVersion.Val, splitDebugFilename.Val, emissionKind.Val, enums.Val,
retainedTypes.Val, globals.Val, imports.Val, macros.Val, dwoId.Val,
splitDebugInlining.Val, debugInfoForProfiling.Val, gnuPubnames.Val);
splitDebugInlining.Val, debugInfoForProfiling.Val, nameTableKind.Val);
return false;
}

View File

@ -434,6 +434,7 @@ enum Kind {
DwarfLang, // DW_LANG_foo
DwarfCC, // DW_CC_foo
EmissionKind, // lineTablesOnly
NameTableKind, // GNU
DwarfOp, // DW_OP_foo
DIFlag, // DIFlagFoo
DwarfMacinfo, // DW_MACINFO_foo

View File

@ -1393,7 +1393,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
Record.size() <= 14 ? 0 : Record[14],
Record.size() <= 16 ? true : Record[16],
Record.size() <= 17 ? false : Record[17],
Record.size() <= 18 ? false : Record[18]);
Record.size() <= 18 ? 0 : Record[18]);
MetadataList.assignValue(CU, NextMetadataNo);
NextMetadataNo++;

View File

@ -1603,7 +1603,7 @@ void ModuleBitcodeWriter::writeDICompileUnit(const DICompileUnit *N,
Record.push_back(VE.getMetadataOrNullID(N->getMacros().get()));
Record.push_back(N->getSplitDebugInlining());
Record.push_back(N->getDebugInfoForProfiling());
Record.push_back(N->getGnuPubnames());
Record.push_back((unsigned)N->getNameTableKind());
Stream.EmitRecord(bitc::METADATA_COMPILE_UNIT, Record, Abbrev);
Record.clear();

View File

@ -23,6 +23,7 @@
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
#include <algorithm>
#include <cstddef>
#include <cstdint>
@ -554,12 +555,21 @@ void llvm::emitDWARF5AccelTable(
const DwarfDebug &DD, ArrayRef<std::unique_ptr<DwarfCompileUnit>> CUs) {
std::vector<MCSymbol *> CompUnits;
for (const auto &CU : enumerate(CUs)) {
if (CU.value()->getCUNode()->getNameTableKind() ==
DICompileUnit::DebugNameTableKind::None)
continue;
assert(CU.index() == CU.value()->getUniqueID());
const DwarfCompileUnit *MainCU =
DD.useSplitDwarf() ? CU.value()->getSkeleton() : CU.value().get();
CompUnits.push_back(MainCU->getLabelBegin());
}
if (CompUnits.empty())
return;
Asm->OutStreamer->SwitchSection(
Asm->getObjFileLowering().getDwarfDebugNamesSection());
Contents.finalize(Asm, "names");
Dwarf5AccelTableWriter<DWARF5AccelTableData>(
Asm, Contents, CompUnits,

View File

@ -249,13 +249,13 @@ DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE(
addLinkageName(*VariableDIE, GV->getLinkageName());
if (addToAccelTable) {
DD->addAccelName(GV->getName(), *VariableDIE);
DD->addAccelName(*CUNode, GV->getName(), *VariableDIE);
// If the linkage name is different than the name, go ahead and output
// that as well into the name table.
if (GV->getLinkageName() != "" && GV->getName() != GV->getLinkageName() &&
DD->useAllLinkageNames())
DD->addAccelName(GV->getLinkageName(), *VariableDIE);
DD->addAccelName(*CUNode, GV->getLinkageName(), *VariableDIE);
}
return VariableDIE;
@ -348,7 +348,7 @@ DIE &DwarfCompileUnit::updateSubprogramScopeDIE(const DISubprogram *SP) {
// Add name to the name table, we do this here because we're guaranteed
// to have concrete versions of our DW_TAG_subprogram nodes.
DD->addSubprogramNames(SP, *SPDie);
DD->addSubprogramNames(*CUNode, SP, *SPDie);
return *SPDie;
}
@ -486,7 +486,7 @@ DIE *DwarfCompileUnit::constructInlinedScopeDIE(LexicalScope *Scope) {
// Add name to the name table, we do this here because we're guaranteed
// to have concrete versions of our DW_TAG_inlined_subprogram nodes.
DD->addSubprogramNames(InlinedSP, *ScopeDIE);
DD->addSubprogramNames(*CUNode, InlinedSP, *ScopeDIE);
return ScopeDIE;
}
@ -883,13 +883,17 @@ void DwarfCompileUnit::emitHeader(bool UseOffsets) {
}
bool DwarfCompileUnit::hasDwarfPubSections() const {
// Opting in to GNU Pubnames/types overrides the default to ensure these are
// generated for things like Gold's gdb_index generation.
if (CUNode->getGnuPubnames())
switch (CUNode->getNameTableKind()) {
case DICompileUnit::DebugNameTableKind::None:
return false;
// Opting in to GNU Pubnames/types overrides the default to ensure these are
// generated for things like Gold's gdb_index generation.
case DICompileUnit::DebugNameTableKind::GNU:
return true;
return DD->tuneForGDB() && DD->usePubSections() &&
!includeMinimalInlineScopes() && !CUNode->isDebugDirectivesOnly();
case DICompileUnit::DebugNameTableKind::Default:
return DD->tuneForGDB() && DD->usePubSections() &&
!includeMinimalInlineScopes() && !CUNode->isDebugDirectivesOnly();
}
}
/// addGlobalName - Add a new global name to the compile unit.

View File

@ -421,30 +421,35 @@ static StringRef getObjCMethodName(StringRef In) {
}
// Add the various names to the Dwarf accelerator table names.
void DwarfDebug::addSubprogramNames(const DISubprogram *SP, DIE &Die) {
void DwarfDebug::addSubprogramNames(const DICompileUnit &CU,
const DISubprogram *SP, DIE &Die) {
if (getAccelTableKind() != AccelTableKind::Apple &&
CU.getNameTableKind() == DICompileUnit::DebugNameTableKind::None)
return;
if (!SP->isDefinition())
return;
if (SP->getName() != "")
addAccelName(SP->getName(), Die);
addAccelName(CU, SP->getName(), Die);
// If the linkage name is different than the name, go ahead and output that as
// well into the name table. Only do that if we are going to actually emit
// that name.
if (SP->getLinkageName() != "" && SP->getName() != SP->getLinkageName() &&
(useAllLinkageNames() || InfoHolder.getAbstractSPDies().lookup(SP)))
addAccelName(SP->getLinkageName(), Die);
addAccelName(CU, SP->getLinkageName(), Die);
// If this is an Objective-C selector name add it to the ObjC accelerator
// too.
if (isObjCClass(SP->getName())) {
StringRef Class, Category;
getObjCClassCategory(SP->getName(), Class, Category);
addAccelObjC(Class, Die);
addAccelObjC(CU, Class, Die);
if (Category != "")
addAccelObjC(Category, Die);
addAccelObjC(CU, Category, Die);
// Also add the base method name to the name table.
addAccelName(getObjCMethodName(SP->getName()), Die);
addAccelName(CU, getObjCMethodName(SP->getName()), Die);
}
}
@ -1537,8 +1542,6 @@ void DwarfDebug::emitAccelDebugNames() {
if (getUnits().empty())
return;
Asm->OutStreamer->SwitchSection(
Asm->getObjFileLowering().getDwarfDebugNamesSection());
emitDWARF5AccelTable(Asm, AccelDebugNames, *this, getUnits());
}
@ -1643,7 +1646,8 @@ void DwarfDebug::emitDebugPubSections() {
if (!TheU->hasDwarfPubSections())
continue;
bool GnuStyle = TheU->getCUNode()->getGnuPubnames();
bool GnuStyle = TheU->getCUNode()->getNameTableKind() ==
DICompileUnit::DebugNameTableKind::GNU;
Asm->OutStreamer->SwitchSection(
GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubNamesSection()
@ -2431,11 +2435,16 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
// AccelTableKind::Apple, we use the table we got as an argument). If
// accelerator tables are disabled, this function does nothing.
template <typename DataT>
void DwarfDebug::addAccelNameImpl(AccelTable<DataT> &AppleAccel, StringRef Name,
void DwarfDebug::addAccelNameImpl(const DICompileUnit &CU,
AccelTable<DataT> &AppleAccel, StringRef Name,
const DIE &Die) {
if (getAccelTableKind() == AccelTableKind::None)
return;
if (getAccelTableKind() != AccelTableKind::Apple &&
CU.getNameTableKind() == DICompileUnit::DebugNameTableKind::None)
return;
DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
DwarfStringPoolEntryRef Ref = Holder.getStringPool().getEntry(*Asm, Name);
@ -2453,22 +2462,26 @@ void DwarfDebug::addAccelNameImpl(AccelTable<DataT> &AppleAccel, StringRef Name,
}
}
void DwarfDebug::addAccelName(StringRef Name, const DIE &Die) {
addAccelNameImpl(AccelNames, Name, Die);
void DwarfDebug::addAccelName(const DICompileUnit &CU, StringRef Name,
const DIE &Die) {
addAccelNameImpl(CU, AccelNames, Name, Die);
}
void DwarfDebug::addAccelObjC(StringRef Name, const DIE &Die) {
void DwarfDebug::addAccelObjC(const DICompileUnit &CU, StringRef Name,
const DIE &Die) {
// ObjC names go only into the Apple accelerator tables.
if (getAccelTableKind() == AccelTableKind::Apple)
addAccelNameImpl(AccelObjC, Name, Die);
addAccelNameImpl(CU, AccelObjC, Name, Die);
}
void DwarfDebug::addAccelNamespace(StringRef Name, const DIE &Die) {
addAccelNameImpl(AccelNamespace, Name, Die);
void DwarfDebug::addAccelNamespace(const DICompileUnit &CU, StringRef Name,
const DIE &Die) {
addAccelNameImpl(CU, AccelNamespace, Name, Die);
}
void DwarfDebug::addAccelType(StringRef Name, const DIE &Die, char Flags) {
addAccelNameImpl(AccelTypes, Name, Die);
void DwarfDebug::addAccelType(const DICompileUnit &CU, StringRef Name,
const DIE &Die, char Flags) {
addAccelNameImpl(CU, AccelTypes, Name, Die);
}
uint16_t DwarfDebug::getDwarfVersion() const {

View File

@ -346,8 +346,8 @@ class DwarfDebug : public DebugHandlerBase {
void constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU, LexicalScope *Scope);
template <typename DataT>
void addAccelNameImpl(AccelTable<DataT> &AppleAccel, StringRef Name,
const DIE &Die);
void addAccelNameImpl(const DICompileUnit &CU, AccelTable<DataT> &AppleAccel,
StringRef Name, const DIE &Die);
void finishVariableDefinitions();
@ -608,17 +608,20 @@ public:
return Ref.resolve();
}
void addSubprogramNames(const DISubprogram *SP, DIE &Die);
void addSubprogramNames(const DICompileUnit &CU, const DISubprogram *SP,
DIE &Die);
AddressPool &getAddressPool() { return AddrPool; }
void addAccelName(StringRef Name, const DIE &Die);
void addAccelName(const DICompileUnit &CU, StringRef Name, const DIE &Die);
void addAccelObjC(StringRef Name, const DIE &Die);
void addAccelObjC(const DICompileUnit &CU, StringRef Name, const DIE &Die);
void addAccelNamespace(StringRef Name, const DIE &Die);
void addAccelNamespace(const DICompileUnit &CU, StringRef Name,
const DIE &Die);
void addAccelType(StringRef Name, const DIE &Die, char Flags);
void addAccelType(const DICompileUnit &CU, StringRef Name, const DIE &Die,
char Flags);
const MachineFunction *getCurrentFunction() const { return CurFn; }

View File

@ -795,7 +795,7 @@ void DwarfUnit::updateAcceleratorTables(const DIScope *Context,
IsImplementation = CT->getRuntimeLang() == 0 || CT->isObjcClassComplete();
}
unsigned Flags = IsImplementation ? dwarf::DW_FLAG_type_implementation : 0;
DD->addAccelType(Ty->getName(), TyDIE, Flags);
DD->addAccelType(*CUNode, Ty->getName(), TyDIE, Flags);
if (!Context || isa<DICompileUnit>(Context) || isa<DIFile>(Context) ||
isa<DINamespace>(Context))
@ -1168,7 +1168,7 @@ DIE *DwarfUnit::getOrCreateNameSpace(const DINamespace *NS) {
addString(NDie, dwarf::DW_AT_name, NS->getName());
else
Name = "(anonymous namespace)";
DD->addAccelNamespace(Name, NDie);
DD->addAccelNamespace(*CUNode, Name, NDie);
addGlobalName(Name, NDie, NS->getScope());
if (NS->getExportSymbols())
addFlag(NDie, dwarf::DW_AT_export_symbols);
@ -1417,7 +1417,7 @@ DIE *DwarfUnit::getIndexTyDie() {
addUInt(*IndexTyDie, dwarf::DW_AT_byte_size, None, sizeof(int64_t));
addUInt(*IndexTyDie, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
dwarf::DW_ATE_unsigned);
DD->addAccelType(Name, *IndexTyDie, /*Flags*/ 0);
DD->addAccelType(*CUNode, Name, *IndexTyDie, /*Flags*/ 0);
return IndexTyDie;
}

View File

@ -1604,6 +1604,8 @@ struct MDFieldPrinter {
void printDwarfEnum(StringRef Name, IntTy Value, Stringifier toString,
bool ShouldSkipZero = true);
void printEmissionKind(StringRef Name, DICompileUnit::DebugEmissionKind EK);
void printNameTableKind(StringRef Name,
DICompileUnit::DebugNameTableKind NTK);
};
} // end anonymous namespace
@ -1701,6 +1703,13 @@ void MDFieldPrinter::printEmissionKind(StringRef Name,
Out << FS << Name << ": " << DICompileUnit::emissionKindString(EK);
}
void MDFieldPrinter::printNameTableKind(StringRef Name,
DICompileUnit::DebugNameTableKind NTK) {
if (NTK == DICompileUnit::DebugNameTableKind::Default)
return;
Out << FS << Name << ": " << DICompileUnit::nameTableKindString(NTK);
}
template <class IntTy, class Stringifier>
void MDFieldPrinter::printDwarfEnum(StringRef Name, IntTy Value,
Stringifier toString, bool ShouldSkipZero) {
@ -1891,7 +1900,7 @@ static void writeDICompileUnit(raw_ostream &Out, const DICompileUnit *N,
Printer.printBool("splitDebugInlining", N->getSplitDebugInlining(), true);
Printer.printBool("debugInfoForProfiling", N->getDebugInfoForProfiling(),
false);
Printer.printBool("gnuPubnames", N->getGnuPubnames(), false);
Printer.printNameTableKind("nameTableKind", N->getNameTableKind());
Out << ")";
}

View File

@ -139,7 +139,8 @@ DICompileUnit *DIBuilder::createCompileUnit(
unsigned Lang, DIFile *File, StringRef Producer, bool isOptimized,
StringRef Flags, unsigned RunTimeVer, StringRef SplitName,
DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId,
bool SplitDebugInlining, bool DebugInfoForProfiling, bool GnuPubnames) {
bool SplitDebugInlining, bool DebugInfoForProfiling,
DICompileUnit::DebugNameTableKind NameTableKind) {
assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) ||
(Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) &&
@ -149,7 +150,7 @@ DICompileUnit *DIBuilder::createCompileUnit(
CUNode = DICompileUnit::getDistinct(
VMContext, Lang, File, Producer, isOptimized, Flags, RunTimeVer,
SplitName, Kind, nullptr, nullptr, nullptr, nullptr, nullptr, DWOId,
SplitDebugInlining, DebugInfoForProfiling, GnuPubnames);
SplitDebugInlining, DebugInfoForProfiling, NameTableKind);
// Create a named metadata so that it is easier to find cu in a module.
NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");

View File

@ -491,7 +491,7 @@ private:
CU->getSplitDebugFilename(), DICompileUnit::LineTablesOnly, EnumTypes,
RetainedTypes, GlobalVariables, ImportedEntities, CU->getMacros(),
CU->getDWOId(), CU->getSplitDebugInlining(),
CU->getDebugInfoForProfiling(), CU->getGnuPubnames());
CU->getDebugInfoForProfiling(), CU->getNameTableKind());
}
DILocation *getReplacementMDLocation(DILocation *MLD) {

View File

@ -450,7 +450,7 @@ DICompileUnit *DICompileUnit::getImpl(
unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
Metadata *GlobalVariables, Metadata *ImportedEntities, Metadata *Macros,
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
bool GnuPubnames, StorageType Storage, bool ShouldCreate) {
unsigned NameTableKind, StorageType Storage, bool ShouldCreate) {
assert(Storage != Uniqued && "Cannot unique DICompileUnit");
assert(isCanonical(Producer) && "Expected canonical MDString");
assert(isCanonical(Flags) && "Expected canonical MDString");
@ -463,7 +463,7 @@ DICompileUnit *DICompileUnit::getImpl(
return storeImpl(new (array_lengthof(Ops)) DICompileUnit(
Context, Storage, SourceLanguage, IsOptimized,
RuntimeVersion, EmissionKind, DWOId, SplitDebugInlining,
DebugInfoForProfiling, GnuPubnames, Ops),
DebugInfoForProfiling, NameTableKind, Ops),
Storage);
}
@ -477,6 +477,15 @@ DICompileUnit::getEmissionKind(StringRef Str) {
.Default(None);
}
Optional<DICompileUnit::DebugNameTableKind>
DICompileUnit::getNameTableKind(StringRef Str) {
return StringSwitch<Optional<DebugNameTableKind>>(Str)
.Case("Default", DebugNameTableKind::Default)
.Case("GNU", DebugNameTableKind::GNU)
.Case("None", DebugNameTableKind::None)
.Default(None);
}
const char *DICompileUnit::emissionKindString(DebugEmissionKind EK) {
switch (EK) {
case NoDebug: return "NoDebug";
@ -487,6 +496,18 @@ const char *DICompileUnit::emissionKindString(DebugEmissionKind EK) {
return nullptr;
}
const char *DICompileUnit::nameTableKindString(DebugNameTableKind NTK) {
switch (NTK) {
case DebugNameTableKind::Default:
return nullptr;
case DebugNameTableKind::GNU:
return "GNU";
case DebugNameTableKind::None:
return "None";
}
return nullptr;
}
DISubprogram *DILocalScope::getSubprogram() const {
if (auto *Block = dyn_cast<DILexicalBlockBase>(this))
return Block->getScope()->getSubprogram();

View File

@ -1,6 +1,6 @@
; RUN: llvm-as -disable-verify -o - %s | llvm-dis | FileCheck %s
!named = !{!0}
; CHECK: !DICompileUnit({{.*}}, gnuPubnames: true)
!0 = distinct !DICompileUnit(language: 12, file: !1, gnuPubnames: true)
; CHECK: !DICompileUnit({{.*}}, nameTableKind: GNU)
!0 = distinct !DICompileUnit(language: 12, file: !1, nameTableKind: GNU)
!1 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")

View File

@ -0,0 +1,29 @@
; REQUIRES: object-emission
; Verify that no DWARF v5 names section is emitted when all CUs disable name tables.
; RUN: llc -mtriple x86_64-pc-linux -filetype=obj < %s \
; RUN: | llvm-objdump -h - | FileCheck %s
; CHECK-NOT: debug_names
define dso_local i32 @main() !dbg !7 {
entry:
ret i32 0, !dbg !11
}
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4, !5}
!llvm.ident = !{!6}
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 8.0.0 (trunk 339438) (llvm/trunk 339448)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
!1 = !DIFile(filename: "foo.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch", checksumkind: CSK_MD5, checksum: "f881137628fc8dd673b761eb7a1e2432")
!2 = !{}
!3 = !{i32 2, !"Dwarf Version", i32 5}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = !{i32 1, !"wchar_size", i32 4}
!6 = !{!"clang version 8.0.0 (trunk 339438) (llvm/trunk 339448)"}
!7 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
!8 = !DISubroutineType(types: !9)
!9 = !{!10}
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!11 = !DILocation(line: 1, column: 13, scope: !7)

View File

@ -0,0 +1,46 @@
; REQUIRES: object-emission
; Verify that DWARF v5 debug_names omit names from CUs that opt-out.
; RUN: llc -mtriple x86_64-pc-linux -filetype=obj < %s \
; RUN: | llvm-dwarfdump -debug-names - | FileCheck %s
; CHECK: CU count: 1
; Check that the one CU that is indexed has a non-zero.
; Avoid checking for a specific offset to make the test more resilient.
; CHECK: Compilation Unit offsets [
; CHECK-NEXT: CU[0]: 0x{{[0-9]*[1-9][0-9]*}}
; CHECK-NEXT: ]
define dso_local i32 @main() !dbg !9 {
entry:
ret i32 0, !dbg !13
}
define dso_local void @_Z2f1v() !dbg !14 {
entry:
ret void, !dbg !17
}
!llvm.dbg.cu = !{!0, !3}
!llvm.ident = !{!5, !5}
!llvm.module.flags = !{!6, !7, !8}
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 8.0.0 (trunk 339438) (llvm/trunk 339448)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
!1 = !DIFile(filename: "foo.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch", checksumkind: CSK_MD5, checksum: "f881137628fc8dd673b761eb7a1e2432")
!2 = !{}
!3 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !4, producer: "clang version 8.0.0 (trunk 339438) (llvm/trunk 339448)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
!4 = !DIFile(filename: "bar.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch", checksumkind: CSK_MD5, checksum: "ba8dae3bceaf6ef87728337164565a87")
!5 = !{!"clang version 8.0.0 (trunk 339438) (llvm/trunk 339448)"}
!6 = !{i32 2, !"Dwarf Version", i32 5}
!7 = !{i32 2, !"Debug Info Version", i32 3}
!8 = !{i32 1, !"wchar_size", i32 4}
!9 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 1, type: !10, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
!10 = !DISubroutineType(types: !11)
!11 = !{!12}
!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!13 = !DILocation(line: 1, column: 13, scope: !9)
!14 = distinct !DISubprogram(name: "f1", linkageName: "_Z2f1v", scope: !4, file: !4, line: 1, type: !15, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !3, retainedNodes: !2)
!15 = !DISubroutineType(types: !16)
!16 = !{null}
!17 = !DILocation(line: 1, column: 12, scope: !14)

View File

@ -17,7 +17,7 @@
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4}
!0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.4 (trunk 191846) (llvm/trunk 191866)", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !5, globals: !2, imports: !2, gnuPubnames: true)
!0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.4 (trunk 191846) (llvm/trunk 191866)", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !5, globals: !2, imports: !2, nameTableKind: GNU)
!1 = !DIFile(filename: "foo.c", directory: "/usr/local/google/home/echristo/tmp")
!2 = !{}
!3 = !{i32 2, !"Dwarf Version", i32 4}

View File

@ -1,4 +1,4 @@
; RUN: sed -e 's/gnuPubnames: false/gnuPubnames: true/' %s | llc -mtriple=x86_64-pc-linux-gnu -filetype=obj | llvm-dwarfdump -v - | FileCheck --check-prefix=GPUB %s
; RUN: sed -e 's/nameTableKind: Default/nameTableKind: GNU/' %s | llc -mtriple=x86_64-pc-linux-gnu -filetype=obj | llvm-dwarfdump -v - | FileCheck --check-prefix=GPUB %s
; RUN: llc -mtriple=x86_64-pc-linux-gnu -filetype=obj < %s | llvm-dwarfdump -v - | FileCheck --check-prefix=NONE %s
; Generated from:
@ -46,7 +46,7 @@ attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-
!llvm.module.flags = !{!3, !4, !5}
!llvm.ident = !{!6}
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 5.0.0 (trunk 303768) (llvm/trunk 303774)", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2, gnuPubnames: false)
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 5.0.0 (trunk 303768) (llvm/trunk 303774)", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2, nameTableKind: Default)
!1 = !DIFile(filename: "gnu-public-names-gmlt.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
!2 = !{}
!3 = !{i32 2, !"Dwarf Version", i32 4}

View File

@ -23,4 +23,4 @@ target triple = "x86_64-unknown-linux-gnu"
!8 = !DIGlobalVariableExpression(var: !9, expr: !DIExpression())
!9 = !DIGlobalVariable(name: "b", scope: null, file: !2, line: 2, type: !3, isLocal: false, isDefinition: true)
!10 = !{!8}
!11 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !10, gnuPubnames: true)
!11 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !10, nameTableKind: GNU)

View File

@ -39,7 +39,7 @@
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
!1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 8, type: !6, isLocal: false, isDefinition: true)
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 5.0.0 (trunk 293904) (llvm/trunk 293908)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, gnuPubnames: true)
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 5.0.0 (trunk 293904) (llvm/trunk 293908)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: GNU)
!3 = !DIFile(filename: "type.cpp", directory: "/tmp/dbginfo")
!4 = !{}
!5 = !{!0}

View File

@ -302,7 +302,7 @@ attributes #1 = { nounwind readnone }
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
!1 = !DIGlobalVariable(name: "static_member_variable", linkageName: "_ZN1C22static_member_variableE", scope: !2, file: !3, line: 7, type: !9, isLocal: false, isDefinition: true, declaration: !8)
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 3.7.0 (trunk 234897) (llvm/trunk 234911)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !5, globals: !21, imports: !44, gnuPubnames: true)
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 3.7.0 (trunk 234897) (llvm/trunk 234911)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !5, globals: !21, imports: !44, nameTableKind: GNU)
!3 = !DIFile(filename: "gnu-public-names.cpp", directory: "/tmp/dbginfo")
!4 = !{}
!5 = !{!6, !17}

View File

@ -0,0 +1,28 @@
; RUN: llc -mtriple=x86_64-pc-linux-gnu -debugger-tune=gdb -filetype=asm < %s | FileCheck %s --check-prefix=DISABLED
; DISABLED-NOT: pub{{names|types}}
%struct.bar = type { %"struct.ns::foo" }
%"struct.ns::foo" = type { i8 }
@b = global %struct.bar zeroinitializer, align 1, !dbg !0
!llvm.dbg.cu = !{!2}
!llvm.module.flags = !{!11, !12}
!llvm.ident = !{!13}
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
!1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 8, type: !6, isLocal: false, isDefinition: true)
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: None)
!3 = !DIFile(filename: "type.cpp", directory: "/tmp/dbginfo")
!4 = !{}
!5 = !{!0}
!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "bar", file: !3, line: 5, size: 8, elements: !7, identifier: "_ZTS3bar")
!7 = !{!8}
!8 = !DIDerivedType(tag: DW_TAG_member, name: "f", scope: !6, file: !3, line: 6, baseType: !9, size: 8)
!9 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "foo", scope: !10, file: !3, line: 2, size: 8, elements: !4, identifier: "_ZTSN2ns3fooE")
!10 = !DINamespace(name: "ns", scope: null)
!11 = !{i32 2, !"Dwarf Version", i32 4}
!12 = !{i32 2, !"Debug Info Version", i32 3}
!13 = !{!"clang"}

View File

@ -16,7 +16,7 @@
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
!1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 8, type: !6, isLocal: false, isDefinition: true)
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, gnuPubnames: false)
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: Default)
!3 = !DIFile(filename: "type.cpp", directory: "/tmp/dbginfo")
!4 = !{}
!5 = !{!0}

View File

@ -95,7 +95,8 @@ protected:
return DICompileUnit::getDistinct(
Context, 1, getFile(), "clang", false, "-g", 2, "",
DICompileUnit::FullDebug, getTuple(), getTuple(), getTuple(),
getTuple(), getTuple(), 0, true, false, false);
getTuple(), getTuple(), 0, true, false,
DICompileUnit::DebugNameTableKind::Default);
}
DIType *getBasicType(StringRef Name) {
return DIBasicType::get(Context, dwarf::DW_TAG_unspecified_type, Name);
@ -1507,7 +1508,7 @@ TEST_F(DICompileUnitTest, get) {
Context, SourceLanguage, File, Producer, IsOptimized, Flags,
RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
RetainedTypes, GlobalVariables, ImportedEntities, Macros, DWOId, true,
false, false);
false, DICompileUnit::DebugNameTableKind::Default);
EXPECT_EQ(dwarf::DW_TAG_compile_unit, N->getTag());
EXPECT_EQ(SourceLanguage, N->getSourceLanguage());
@ -1565,7 +1566,7 @@ TEST_F(DICompileUnitTest, replaceArrays) {
Context, SourceLanguage, File, Producer, IsOptimized, Flags,
RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
RetainedTypes, nullptr, ImportedEntities, nullptr, DWOId, true, false,
false);
DICompileUnit::DebugNameTableKind::Default);
auto *GlobalVariables = MDTuple::getDistinct(Context, None);
EXPECT_EQ(nullptr, N->getGlobalVariables().get());