diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h b/llvm/include/llvm/CodeGen/AsmPrinter.h index 282d2f1b0b9c..070261a4cfc0 100644 --- a/llvm/include/llvm/CodeGen/AsmPrinter.h +++ b/llvm/include/llvm/CodeGen/AsmPrinter.h @@ -19,6 +19,7 @@ #include "llvm/ADT/MapVector.h" #include "llvm/ADT/Twine.h" #include "llvm/CodeGen/MachineFunctionPass.h" +#include "llvm/CodeGen/DwarfStringPoolEntry.h" #include "llvm/IR/InlineAsm.h" #include "llvm/Support/DataTypes.h" #include "llvm/Support/ErrorHandling.h" @@ -422,6 +423,13 @@ public: /// or by emitting it as an offset from a label at the start of the section. void emitSectionOffset(const MCSymbol *Label) const; + /// Emit the 4-byte offset of a string from the start of its section. + /// + /// When possible, emit a DwarfStringPool section offset without any + /// relocations, and without using the symbol. Otherwise, defers to \a + /// emitSectionOffset(). + void emitDwarfStringOffset(DwarfStringPoolEntryRef S) const; + /// Get the value for DW_AT_APPLE_isa. Zero if no isa encoding specified. virtual unsigned getISAEncoding() { return 0; } diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp index 6f48767c1df4..3258961bfb11 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp @@ -181,6 +181,16 @@ void AsmPrinter::emitSectionOffset(const MCSymbol *Label) const { EmitLabelDifference(Label, Label->getSection().getBeginSymbol(), 4); } +void AsmPrinter::emitDwarfStringOffset(DwarfStringPoolEntryRef S) const { + if (MAI->doesDwarfUseRelocationsAcrossSections()) { + emitSectionOffset(S.getSymbol()); + return; + } + + // Just emit the offset directly; no need for symbol math. + EmitInt32(S.getOffset()); +} + /// EmitDwarfRegOp - Emit dwarf register operation. void AsmPrinter::EmitDwarfRegOp(ByteStreamer &Streamer, const MachineLocation &MLoc) const { diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp index ca953b982c28..58b406b788fb 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfAccelTable.cpp @@ -216,7 +216,7 @@ void DwarfAccelTable::EmitData(AsmPrinter *Asm, DwarfDebug *D) { // Remember to emit the label for our offset. Asm->OutStreamer->EmitLabel((*HI)->Sym); Asm->OutStreamer->AddComment((*HI)->Str); - Asm->emitSectionOffset((*HI)->Data.Name.getSymbol()); + Asm->emitDwarfStringOffset((*HI)->Data.Name); Asm->OutStreamer->AddComment("Num DIEs"); Asm->EmitInt32((*HI)->Data.Values.size()); for (HashDataContents *HD : (*HI)->Data.Values) {