Skip to content

Commit

Permalink
IR: Represent -ggnu-pubnames with a flag on the DICompileUnit.
Browse files Browse the repository at this point in the history
This allows the flag to be persisted through to LTO.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313078 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
pcc committed Sep 12, 2017
1 parent bfd98b8 commit 76221cb
Show file tree
Hide file tree
Showing 20 changed files with 178 additions and 166 deletions.
5 changes: 4 additions & 1 deletion include/llvm/IR/DIBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,17 @@ 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.
DICompileUnit *
createCompileUnit(unsigned Lang, DIFile *File, StringRef Producer,
bool isOptimized, StringRef Flags, unsigned RV,
StringRef SplitName = StringRef(),
DICompileUnit::DebugEmissionKind Kind =
DICompileUnit::DebugEmissionKind::FullDebug,
uint64_t DWOId = 0, bool SplitDebugInlining = true,
bool DebugInfoForProfiling = false);
bool DebugInfoForProfiling = false,
bool GnuPubnames = false);

/// Create a file descriptor to hold debugging information for a file.
/// \param Filename File name.
Expand Down
36 changes: 19 additions & 17 deletions include/llvm/IR/DebugInfoMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -1068,16 +1068,17 @@ class DICompileUnit : public DIScope {
uint64_t DWOId;
bool SplitDebugInlining;
bool DebugInfoForProfiling;
bool GnuPubnames;

DICompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
bool IsOptimized, unsigned RuntimeVersion,
unsigned EmissionKind, uint64_t DWOId, bool SplitDebugInlining,
bool DebugInfoForProfiling, ArrayRef<Metadata *> Ops)
bool DebugInfoForProfiling, bool GnuPubnames, 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) {
DebugInfoForProfiling(DebugInfoForProfiling), GnuPubnames(GnuPubnames) {
assert(Storage != Uniqued);
}
~DICompileUnit() = default;
Expand All @@ -1091,15 +1092,14 @@ class DICompileUnit : public DIScope {
DIGlobalVariableExpressionArray GlobalVariables,
DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
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, Storage,
ShouldCreate);
bool GnuPubnames, 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);
}
static DICompileUnit *
getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
Expand All @@ -1108,7 +1108,7 @@ class DICompileUnit : public DIScope {
unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes,
Metadata *GlobalVariables, Metadata *ImportedEntities,
Metadata *Macros, uint64_t DWOId, bool SplitDebugInlining,
bool DebugInfoForProfiling, StorageType Storage,
bool DebugInfoForProfiling, bool GnuPubnames, StorageType Storage,
bool ShouldCreate = true);

TempDICompileUnit cloneImpl() const {
Expand All @@ -1118,7 +1118,7 @@ class DICompileUnit : public DIScope {
getEmissionKind(), getEnumTypes(), getRetainedTypes(),
getGlobalVariables(), getImportedEntities(),
getMacros(), DWOId, getSplitDebugInlining(),
getDebugInfoForProfiling());
getDebugInfoForProfiling(), getGnuPubnames());
}

public:
Expand All @@ -1133,23 +1133,24 @@ class DICompileUnit : public DIScope {
DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes,
DIGlobalVariableExpressionArray GlobalVariables,
DIImportedEntityArray ImportedEntities, DIMacroNodeArray Macros,
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling),
uint64_t DWOId, bool SplitDebugInlining, bool DebugInfoForProfiling,
bool GnuPubnames),
(SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
DebugInfoForProfiling))
DebugInfoForProfiling, GnuPubnames))
DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(
DICompileUnit,
(unsigned SourceLanguage, Metadata *File, MDString *Producer,
bool IsOptimized, MDString *Flags, unsigned RuntimeVersion,
MDString *SplitDebugFilename, unsigned EmissionKind, Metadata *EnumTypes,
Metadata *RetainedTypes, Metadata *GlobalVariables,
Metadata *ImportedEntities, Metadata *Macros, uint64_t DWOId,
bool SplitDebugInlining, bool DebugInfoForProfiling),
bool SplitDebugInlining, bool DebugInfoForProfiling, bool GnuPubnames),
(SourceLanguage, File, Producer, IsOptimized, Flags, RuntimeVersion,
SplitDebugFilename, EmissionKind, EnumTypes, RetainedTypes,
GlobalVariables, ImportedEntities, Macros, DWOId, SplitDebugInlining,
DebugInfoForProfiling))
DebugInfoForProfiling, GnuPubnames))

TempDICompileUnit clone() const { return cloneImpl(); }

Expand All @@ -1160,6 +1161,7 @@ class DICompileUnit : public DIScope {
return (DebugEmissionKind)EmissionKind;
}
bool getDebugInfoForProfiling() const { return DebugInfoForProfiling; }
bool getGnuPubnames() const { return GnuPubnames; }
StringRef getProducer() const { return getStringOperand(1); }
StringRef getFlags() const { return getStringOperand(2); }
StringRef getSplitDebugFilename() const { return getStringOperand(3); }
Expand Down
5 changes: 3 additions & 2 deletions lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4099,15 +4099,16 @@ bool LLParser::ParseDICompileUnit(MDNode *&Result, bool IsDistinct) {
OPTIONAL(macros, MDField, ); \
OPTIONAL(dwoId, MDUnsignedField, ); \
OPTIONAL(splitDebugInlining, MDBoolField, = true); \
OPTIONAL(debugInfoForProfiling, MDBoolField, = false);
OPTIONAL(debugInfoForProfiling, MDBoolField, = false); \
OPTIONAL(gnuPubnames, MDBoolField, = false);
PARSE_MD_FIELDS();
#undef VISIT_MD_FIELDS

Result = DICompileUnit::getDistinct(
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);
splitDebugInlining.Val, debugInfoForProfiling.Val, gnuPubnames.Val);
return false;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/Bitcode/Reader/MetadataLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
break;
}
case bitc::METADATA_COMPILE_UNIT: {
if (Record.size() < 14 || Record.size() > 18)
if (Record.size() < 14 || Record.size() > 19)
return error("Invalid record");

// Ignore Record[0], which indicates whether this compile unit is
Expand All @@ -1369,7 +1369,8 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
Record.size() <= 15 ? nullptr : getMDOrNull(Record[15]),
Record.size() <= 14 ? 0 : Record[14],
Record.size() <= 16 ? true : Record[16],
Record.size() <= 17 ? false : Record[17]);
Record.size() <= 17 ? false : Record[17],
Record.size() <= 18 ? false : Record[18]);

MetadataList.assignValue(CU, NextMetadataNo);
NextMetadataNo++;
Expand Down
1 change: 1 addition & 0 deletions lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,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());

Stream.EmitRecord(bitc::METADATA_COMPILE_UNIT, Record, Abbrev);
Record.clear();
Expand Down
30 changes: 26 additions & 4 deletions lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@

using namespace llvm;

enum DefaultOnOff { Default, Enable, Disable };

static cl::opt<DefaultOnOff>
DwarfPubSections("generate-dwarf-pub-sections", cl::Hidden,
cl::desc("Generate DWARF pubnames and pubtypes sections"),
cl::values(clEnumVal(Default, "Default for platform"),
clEnumVal(Enable, "Enabled"),
clEnumVal(Disable, "Disabled")),
cl::init(Default));

DwarfCompileUnit::DwarfCompileUnit(unsigned UID, const DICompileUnit *Node,
AsmPrinter *A, DwarfDebug *DW,
DwarfFile *DWU)
Expand Down Expand Up @@ -755,18 +765,30 @@ void DwarfCompileUnit::emitHeader(bool UseOffsets) {
DwarfUnit::emitCommonHeader(UseOffsets, UT);
}

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())
return true;

if (DwarfPubSections == Default)
return DD->tuneForGDB() && !includeMinimalInlineScopes();

return DwarfPubSections == Enable;
}

/// addGlobalName - Add a new global name to the compile unit.
void DwarfCompileUnit::addGlobalName(StringRef Name, const DIE &Die,
const DIScope *Context) {
if (!DD->hasDwarfPubSections(includeMinimalInlineScopes()))
if (!hasDwarfPubSections())
return;
std::string FullName = getParentContextString(Context) + Name.str();
GlobalNames[FullName] = &Die;
}

void DwarfCompileUnit::addGlobalNameForTypeUnit(StringRef Name,
const DIScope *Context) {
if (!DD->hasDwarfPubSections(includeMinimalInlineScopes()))
if (!hasDwarfPubSections())
return;
std::string FullName = getParentContextString(Context) + Name.str();
// Insert, allowing the entry to remain as-is if it's already present
Expand All @@ -779,15 +801,15 @@ void DwarfCompileUnit::addGlobalNameForTypeUnit(StringRef Name,
/// Add a new global type to the unit.
void DwarfCompileUnit::addGlobalType(const DIType *Ty, const DIE &Die,
const DIScope *Context) {
if (!DD->hasDwarfPubSections(includeMinimalInlineScopes()))
if (!hasDwarfPubSections())
return;
std::string FullName = getParentContextString(Context) + Ty->getName().str();
GlobalTypes[FullName] = &Die;
}

void DwarfCompileUnit::addGlobalTypeUnitType(const DIType *Ty,
const DIScope *Context) {
if (!DD->hasDwarfPubSections(includeMinimalInlineScopes()))
if (!hasDwarfPubSections())
return;
std::string FullName = getParentContextString(Context) + Ty->getName().str();
// Insert, allowing the entry to remain as-is if it's already present
Expand Down
2 changes: 2 additions & 0 deletions lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ class DwarfCompileUnit final : public DwarfUnit {

void setBaseAddress(const MCSymbol *Base) { BaseAddress = Base; }
const MCSymbol *getBaseAddress() const { return BaseAddress; }

bool hasDwarfPubSections() const;
};

} // end namespace llvm
Expand Down
Loading

0 comments on commit 76221cb

Please sign in to comment.