[llvm-commits] [llvm] r126425 - in /llvm/trunk: include/llvm/MC/ lib/CodeGen/AsmPrinter/ lib/MC/ lib/Target/PTX/ lib/Target/X86/
Devang Patel
dpatel at apple.com
Thu Feb 24 13:04:00 PST 2011
Author: dpatel
Date: Thu Feb 24 15:04:00 2011
New Revision: 126425
URL: http://llvm.org/viewvc/llvm-project?rev=126425&view=rev
Log:
Enable DebugInfo support for COFF object files.
Patch by Nathan Jeffords!
Modified:
llvm/trunk/include/llvm/MC/MCStreamer.h
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
llvm/trunk/lib/MC/MCAsmInfoCOFF.cpp
llvm/trunk/lib/MC/MCAsmStreamer.cpp
llvm/trunk/lib/MC/MCELFStreamer.cpp
llvm/trunk/lib/MC/MCLoggingStreamer.cpp
llvm/trunk/lib/MC/MCMachOStreamer.cpp
llvm/trunk/lib/MC/MCNullStreamer.cpp
llvm/trunk/lib/MC/MCPureStreamer.cpp
llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
llvm/trunk/lib/MC/WinCOFFStreamer.cpp
llvm/trunk/lib/Target/PTX/PTXMCAsmStreamer.cpp
llvm/trunk/lib/Target/X86/X86AsmBackend.cpp
llvm/trunk/lib/Target/X86/X86FixupKinds.h
llvm/trunk/lib/Target/X86/X86MCAsmInfo.cpp
Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=126425&r1=126424&r2=126425&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Thu Feb 24 15:04:00 2011
@@ -239,6 +239,11 @@
/// EndCOFFSymbolDef - Marks the end of the symbol definition.
virtual void EndCOFFSymbolDef() = 0;
+ /// EmitCOFFSecRel32 - Emits a COFF section relative relocation.
+ ///
+ /// @param Symbol - Symbol the section relative realocation should point to.
+ virtual void EmitCOFFSecRel32(MCSymbol const *Symbol) = 0;
+
/// EmitELFSize - Emit an ELF .size directive.
///
/// This corresponds to an assembler statement such as:
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp?rev=126425&r1=126424&r2=126425&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp Thu Feb 24 15:04:00 2011
@@ -178,8 +178,7 @@
const MCSymbol *SectionLabel) const {
// On COFF targets, we have to emit the special .secrel32 directive.
if (const char *SecOffDir = MAI->getDwarfSectionOffsetDirective()) {
- // FIXME: MCize.
- OutStreamer.EmitRawText(SecOffDir + Twine(Label->getName()));
+ OutStreamer.EmitCOFFSecRel32(Label);
return;
}
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp?rev=126425&r1=126424&r2=126425&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp Thu Feb 24 15:04:00 2011
@@ -277,6 +277,29 @@
#endif
//===----------------------------------------------------------------------===//
+// DIESectionOffset Implementation
+//===----------------------------------------------------------------------===//
+
+/// EmitValue - Emit label value.
+///
+void DIESectionOffset::EmitValue(AsmPrinter *AP, unsigned Form) const {
+ AP->EmitSectionOffset (Label, Label);
+}
+
+/// SizeOf - Determine size of label value in bytes.
+///
+unsigned DIESectionOffset::SizeOf(AsmPrinter *AP, unsigned Form) const {
+ if (Form == dwarf::DW_FORM_data4) return 4;
+ return AP->getTargetData().getPointerSize();
+}
+
+#ifndef NDEBUG
+void DIESectionOffset::print(raw_ostream &O) {
+ O << "SecRelLbl: " << Label->getName();
+}
+#endif
+
+//===----------------------------------------------------------------------===//
// DIEDelta Implementation
//===----------------------------------------------------------------------===//
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h?rev=126425&r1=126424&r2=126425&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DIE.h Thu Feb 24 15:04:00 2011
@@ -333,6 +333,36 @@
};
//===--------------------------------------------------------------------===//
+ /// DIESectionOffset - A section relative label expression DIE.
+ //
+ class DIESectionOffset : public DIEValue {
+ const MCSymbol *Label;
+ public:
+ explicit DIESectionOffset(const MCSymbol *L) : DIEValue(isSectionOffset),
+ Label(L) {}
+
+ /// EmitValue - Emit label value.
+ ///
+ virtual void EmitValue(AsmPrinter *AP, unsigned Form) const;
+
+ /// getValue - Get MCSymbol.
+ ///
+ const MCSymbol *getValue() const { return Label; }
+
+ /// SizeOf - Determine size of label value in bytes.
+ ///
+ virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const;
+
+ // Implement isa/cast/dyncast.
+ static bool classof(const DIELabel *) { return true; }
+ static bool classof(const DIEValue *L) { return L->getType() == isSectionOffset; }
+
+#ifndef NDEBUG
+ virtual void print(raw_ostream &O);
+#endif
+ };
+
+ //===--------------------------------------------------------------------===//
/// DIEDelta - A simple label difference DIE.
///
class DIEDelta : public DIEValue {
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=126425&r1=126424&r2=126425&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Thu Feb 24 15:04:00 2011
@@ -481,6 +481,15 @@
Die->addValue(Attribute, Form, Value);
}
+/// addSectionOffset - Add a Dwarf section relative label attribute data and
+/// value.
+///
+void DwarfDebug::addSectionOffset(DIE *Die, unsigned Attribute, unsigned Form,
+ const MCSymbol *Label) {
+ DIEValue *Value = new (DIEValueAllocator) DIESectionOffset(Label);
+ Die->addValue(Attribute, Form, Value);
+}
+
/// addDelta - Add a label delta attribute data and value.
///
void DwarfDebug::addDelta(DIE *Die, unsigned Attribute, unsigned Form,
@@ -1904,8 +1913,8 @@
// DW_AT_stmt_list is a offset of line number information for this
// compile unit in debug_line section.
if (Asm->MAI->doesDwarfUsesAbsoluteLabelForStmtList())
- addLabel(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_addr,
- Asm->GetTempSymbol("section_line"));
+ addSectionOffset(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_addr,
+ Asm->GetTempSymbol("section_line"));
else
addUInt(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4, 0);
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=126425&r1=126424&r2=126425&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Thu Feb 24 15:04:00 2011
@@ -280,6 +280,12 @@
void addLabel(DIE *Die, unsigned Attribute, unsigned Form,
const MCSymbol *Label);
+ /// addSectionOffset - Add a Dwarf section relative label attribute data and
+ /// value.
+ ///
+ void addSectionOffset(DIE *Die, unsigned Attribute, unsigned Form,
+ const MCSymbol *Label);
+
/// addDelta - Add a label delta attribute data and value.
///
void addDelta(DIE *Die, unsigned Attribute, unsigned Form,
Modified: llvm/trunk/lib/MC/MCAsmInfoCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmInfoCOFF.cpp?rev=126425&r1=126424&r2=126425&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmInfoCOFF.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmInfoCOFF.cpp Thu Feb 24 15:04:00 2011
@@ -33,5 +33,6 @@
HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
SupportsDebugInformation = true;
DwarfSectionOffsetDirective = "\t.secrel32\t";
+ DwarfUsesAbsoluteLabelForStmtList = false;
HasMicrosoftFastStdCallMangling = true;
}
Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=126425&r1=126424&r2=126425&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Thu Feb 24 15:04:00 2011
@@ -135,6 +135,7 @@
virtual void EmitCOFFSymbolStorageClass(int StorageClass);
virtual void EmitCOFFSymbolType(int Type);
virtual void EndCOFFSymbolDef();
+ virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment);
@@ -384,6 +385,11 @@
EmitEOL();
}
+void MCAsmStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {
+ OS << "\t.secrel32\t" << *Symbol << '\n';
+ EmitEOL();
+}
+
void MCAsmStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
assert(MAI.hasDotTypeDotSizeDirective());
OS << "\t.size\t" << *Symbol << ", " << *Value << '\n';
Modified: llvm/trunk/lib/MC/MCELFStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCELFStreamer.cpp?rev=126425&r1=126424&r2=126425&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCELFStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCELFStreamer.cpp Thu Feb 24 15:04:00 2011
@@ -108,6 +108,10 @@
assert(0 && "ELF doesn't support this directive");
}
+ virtual void EmitCOFFSecRel32(MCSymbol const *Symbol) {
+ assert(0 && "ELF doesn't support this directive");
+ }
+
virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
SD.setSize(Value);
Modified: llvm/trunk/lib/MC/MCLoggingStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCLoggingStreamer.cpp?rev=126425&r1=126424&r2=126425&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCLoggingStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCLoggingStreamer.cpp Thu Feb 24 15:04:00 2011
@@ -120,6 +120,11 @@
return Child->EndCOFFSymbolDef();
}
+ virtual void EmitCOFFSecRel32(MCSymbol const *Symbol) {
+ LogCall("EndCOFFSymbolDef");
+ return Child->EmitCOFFSecRel32(Symbol);
+ }
+
virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
LogCall("EmitELFSize");
return Child->EmitELFSize(Symbol, Value);
Modified: llvm/trunk/lib/MC/MCMachOStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCMachOStreamer.cpp?rev=126425&r1=126424&r2=126425&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCMachOStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCMachOStreamer.cpp Thu Feb 24 15:04:00 2011
@@ -63,6 +63,9 @@
virtual void EndCOFFSymbolDef() {
assert(0 && "macho doesn't support this directive");
}
+ virtual void EmitCOFFSecRel32(MCSymbol const *Symbol) {
+ assert(0 && "macho doesn't support this directive");
+ }
virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
assert(0 && "macho doesn't support this directive");
}
Modified: llvm/trunk/lib/MC/MCNullStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCNullStreamer.cpp?rev=126425&r1=126424&r2=126425&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCNullStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCNullStreamer.cpp Thu Feb 24 15:04:00 2011
@@ -54,6 +54,7 @@
virtual void EmitCOFFSymbolStorageClass(int StorageClass) {}
virtual void EmitCOFFSymbolType(int Type) {}
virtual void EndCOFFSymbolDef() {}
+ virtual void EmitCOFFSecRel32(MCSymbol const *Symbol) {}
virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {}
virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Modified: llvm/trunk/lib/MC/MCPureStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCPureStreamer.cpp?rev=126425&r1=126424&r2=126425&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCPureStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCPureStreamer.cpp Thu Feb 24 15:04:00 2011
@@ -83,6 +83,9 @@
virtual void EndCOFFSymbolDef() {
report_fatal_error("unsupported directive in pure streamer");
}
+ virtual void EmitCOFFSecRel32(MCSymbol const *Symbol) {
+ report_fatal_error("unsupported directive in pure streamer");
+ }
virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
report_fatal_error("unsupported directive in pure streamer");
}
Modified: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp?rev=126425&r1=126424&r2=126425&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Thu Feb 24 15:04:00 2011
@@ -705,6 +705,10 @@
else
llvm_unreachable("unsupported relocation type");
break;
+ case X86::reloc_coff_secrel32:
+ Reloc.Data.Type = Is64Bit ? COFF::IMAGE_REL_AMD64_SREL32
+ : COFF::IMAGE_REL_I386_SECREL;
+ break;
default:
llvm_unreachable("unsupported relocation type");
}
Modified: llvm/trunk/lib/MC/WinCOFFStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFStreamer.cpp?rev=126425&r1=126424&r2=126425&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFStreamer.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFStreamer.cpp Thu Feb 24 15:04:00 2011
@@ -31,6 +31,9 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
+
+#include "../Target/X86/X86FixupKinds.h"
+
using namespace llvm;
namespace {
@@ -59,6 +62,7 @@
virtual void EmitCOFFSymbolStorageClass(int StorageClass);
virtual void EmitCOFFSymbolType(int Type);
virtual void EndCOFFSymbolDef();
+ virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment);
@@ -290,6 +294,16 @@
CurSymbol = NULL;
}
+void WinCOFFStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol)
+{
+ MCDataFragment *DF = getOrCreateDataFragment();
+
+ DF->addFixup(MCFixup::Create(DF->getContents().size(),
+ MCSymbolRefExpr::Create (Symbol, getContext ()),
+ (MCFixupKind)X86::reloc_coff_secrel32));
+ DF->getContents().resize(DF->getContents().size() + 4, 0);
+}
+
void WinCOFFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
llvm_unreachable("not implemented");
}
@@ -368,6 +382,10 @@
getCurrentSectionData()->setHasInstructions(true);
+ // Now that a machine instruction has been assembled into this section, make
+ // a line entry for any .loc directive that has been seen.
+ MCLineEntry::Make(this, getCurrentSection());
+
MCInstFragment *Fragment =
new MCInstFragment(Instruction, getCurrentSectionData());
Modified: llvm/trunk/lib/Target/PTX/PTXMCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PTX/PTXMCAsmStreamer.cpp?rev=126425&r1=126424&r2=126425&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PTX/PTXMCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/Target/PTX/PTXMCAsmStreamer.cpp Thu Feb 24 15:04:00 2011
@@ -124,6 +124,7 @@
virtual void EmitCOFFSymbolStorageClass(int StorageClass);
virtual void EmitCOFFSymbolType(int Type);
virtual void EndCOFFSymbolDef();
+ virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment);
@@ -277,6 +278,8 @@
void PTXMCAsmStreamer::EndCOFFSymbolDef() {}
+void PTXMCAsmStreamer::EmitCOFFSecRel32(MCSymbol const *Symbol) {}
+
void PTXMCAsmStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {}
void PTXMCAsmStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
Modified: llvm/trunk/lib/Target/X86/X86AsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86AsmBackend.cpp?rev=126425&r1=126424&r2=126425&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86AsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86AsmBackend.cpp Thu Feb 24 15:04:00 2011
@@ -40,6 +40,7 @@
case X86::reloc_riprel_4byte_movq_load:
case X86::reloc_signed_4byte:
case X86::reloc_global_offset_table:
+ case X86::reloc_coff_secrel32:
case FK_Data_4: return 2;
case FK_PCRel_8:
case FK_Data_8: return 3;
@@ -69,7 +70,8 @@
{ "reloc_riprel_4byte", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel },
{ "reloc_riprel_4byte_movq_load", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel},
{ "reloc_signed_4byte", 0, 4 * 8, 0},
- { "reloc_global_offset_table", 0, 4 * 8, 0}
+ { "reloc_global_offset_table", 0, 4 * 8, 0},
+ { "reloc_coff_secrel32", 0, 4 * 8, 0}
};
if (Kind < FirstTargetFixupKind)
Modified: llvm/trunk/lib/Target/X86/X86FixupKinds.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86FixupKinds.h?rev=126425&r1=126424&r2=126425&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FixupKinds.h (original)
+++ llvm/trunk/lib/Target/X86/X86FixupKinds.h Thu Feb 24 15:04:00 2011
@@ -23,6 +23,8 @@
reloc_global_offset_table, // 32-bit, relative to the start
// of the instruction. Used only
// for _GLOBAL_OFFSET_TABLE_.
+ reloc_coff_secrel32, // PE-COFF section relative 32
+ // (only valid for win32 COFF)
// Marker
LastTargetFixupKind,
NumTargetFixupKinds = LastTargetFixupKind - FirstTargetFixupKind
Modified: llvm/trunk/lib/Target/X86/X86MCAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86MCAsmInfo.cpp?rev=126425&r1=126424&r2=126425&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86MCAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86MCAsmInfo.cpp Thu Feb 24 15:04:00 2011
@@ -113,4 +113,7 @@
AssemblerDialect = AsmWriterFlavor;
TextAlignFillValue = 0x90;
+
+ // Debug Information
+ SupportsDebugInformation = true;
}
More information about the llvm-commits
mailing list