From: Chris Lattner Date: Sun, 4 Apr 2010 23:22:29 +0000 (+0000) Subject: eliminate the magic AbsoluteDebugSectionOffsets MAI hook, X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=3d2251361171b1a41bdb2ac71882e69d48617f49;p=oota-llvm.git eliminate the magic AbsoluteDebugSectionOffsets MAI hook, which is really a property of the section being referenced. Add a predicate to MCSection to replace it. Yay for reduction in magic. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100367 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/MC/MCAsmInfo.h b/include/llvm/MC/MCAsmInfo.h index d190ea4568f..33def861899 100644 --- a/include/llvm/MC/MCAsmInfo.h +++ b/include/llvm/MC/MCAsmInfo.h @@ -223,10 +223,6 @@ namespace llvm { //===--- Dwarf Emission Directives -----------------------------------===// - /// AbsoluteDebugSectionOffsets - True if we should emit abolute section - /// offsets for debug information. - bool AbsoluteDebugSectionOffsets; // Defaults to false. - /// HasLEB128 - True if target asm supports leb128 directives. bool HasLEB128; // Defaults to false. @@ -385,9 +381,6 @@ namespace llvm { MCSymbolAttr getProtectedVisibilityAttr() const { return ProtectedVisibilityAttr; } - bool isAbsoluteDebugSectionOffsets() const { - return AbsoluteDebugSectionOffsets; - } bool hasLEB128() const { return HasLEB128; } diff --git a/include/llvm/MC/MCSection.h b/include/llvm/MC/MCSection.h index 4a1c46ccb92..e9c19fce20a 100644 --- a/include/llvm/MC/MCSection.h +++ b/include/llvm/MC/MCSection.h @@ -39,6 +39,14 @@ namespace llvm { virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS) const = 0; + + /// isBaseAddressKnownZero - Return true if we know that this section will + /// get a base address of zero. In cases where we know that this is true we + /// can emit section offsets as direct references to avoid a subtraction + /// from the base of the section, saving a relocation. + virtual bool isBaseAddressKnownZero() const { + return false; + } }; class MCSectionCOFF : public MCSection { diff --git a/include/llvm/MC/MCSectionELF.h b/include/llvm/MC/MCSectionELF.h index cdd2f73b348..e550cd2c111 100644 --- a/include/llvm/MC/MCSectionELF.h +++ b/include/llvm/MC/MCSectionELF.h @@ -172,6 +172,11 @@ public: virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS) const; + /// isBaseAddressKnownZero - We know that non-allocatable sections (like + /// debug info) have a base of zero. + virtual bool isBaseAddressKnownZero() const { + return (getFlags() & SHF_ALLOC) == 0; + } /// PrintTargetSpecificSectionFlags - Targets that define their own /// MCSectionELF subclasses with target specific section flags should diff --git a/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp b/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp index 7de61099671..84d47ec4496 100644 --- a/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfPrinter.cpp @@ -20,6 +20,7 @@ #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCExpr.h" +#include "llvm/MC/MCSection.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbol.h" #include "llvm/Target/TargetData.h" @@ -61,15 +62,16 @@ void DwarfPrinter::EmitSectionOffset(const MCSymbol *Label, // If Label has already been emitted, verify that it is in the same section as // section label for sanity. assert((!Label->isInSection() || &Label->getSection() == &Section) && - "Section offset using wrong section base for label"); (void)Section; + "Section offset using wrong section base for label"); // If the section in question will end up with an address of 0 anyway, we can // just emit an absolute reference to save a relocation. - if (MAI->isAbsoluteDebugSectionOffsets()) { + if (Section.isBaseAddressKnownZero()) { Asm->OutStreamer.EmitSymbolValue(Label, 4, 0/*AddrSpace*/); return; } + // Otherwise, emit it as a label difference from the start of the section. Asm->EmitLabelDifference(Label, SectionLabel, 4); } diff --git a/lib/MC/MCAsmInfo.cpp b/lib/MC/MCAsmInfo.cpp index 0306dec363f..f0da694a19e 100644 --- a/lib/MC/MCAsmInfo.cpp +++ b/lib/MC/MCAsmInfo.cpp @@ -60,7 +60,6 @@ MCAsmInfo::MCAsmInfo() { LinkOnceDirective = 0; HiddenVisibilityAttr = MCSA_Hidden; ProtectedVisibilityAttr = MCSA_Protected; - AbsoluteDebugSectionOffsets = false; HasLEB128 = false; HasDotLocAndDotFile = false; SupportsDebugInformation = false; diff --git a/lib/MC/MCAsmInfoCOFF.cpp b/lib/MC/MCAsmInfoCOFF.cpp index e9bc8fa9c3e..7fc7d7abb23 100644 --- a/lib/MC/MCAsmInfoCOFF.cpp +++ b/lib/MC/MCAsmInfoCOFF.cpp @@ -31,7 +31,6 @@ MCAsmInfoCOFF::MCAsmInfoCOFF() { // Set up DWARF directives HasLEB128 = true; // Target asm supports leb128 directives (little-endian) - AbsoluteDebugSectionOffsets = true; SupportsDebugInformation = true; DwarfSectionOffsetDirective = "\t.secrel32\t"; HasMicrosoftFastStdCallMangling = true; diff --git a/lib/Target/ARM/ARMMCAsmInfo.cpp b/lib/Target/ARM/ARMMCAsmInfo.cpp index 20197e487d3..53edfcad930 100644 --- a/lib/Target/ARM/ARMMCAsmInfo.cpp +++ b/lib/Target/ARM/ARMMCAsmInfo.cpp @@ -58,7 +58,6 @@ ARMELFMCAsmInfo::ARMELFMCAsmInfo() { CommentString = "@"; HasLEB128 = true; - AbsoluteDebugSectionOffsets = true; PrivateGlobalPrefix = ".L"; WeakRefDirective = "\t.weak\t"; HasLCOMMDirective = true; diff --git a/lib/Target/PowerPC/PPCMCAsmInfo.cpp b/lib/Target/PowerPC/PPCMCAsmInfo.cpp index 0be1fa4d94f..3644c79d041 100644 --- a/lib/Target/PowerPC/PPCMCAsmInfo.cpp +++ b/lib/Target/PowerPC/PPCMCAsmInfo.cpp @@ -38,7 +38,6 @@ PPCLinuxMCAsmInfo::PPCLinuxMCAsmInfo(bool is64Bit) { UsesELFSectionDirectiveForBSS = true; // Debug Information - AbsoluteDebugSectionOffsets = true; SupportsDebugInformation = true; PCSymbol = "."; diff --git a/lib/Target/Sparc/SparcMCAsmInfo.cpp b/lib/Target/Sparc/SparcMCAsmInfo.cpp index 53a9bde9252..535c6f7c8a2 100644 --- a/lib/Target/Sparc/SparcMCAsmInfo.cpp +++ b/lib/Target/Sparc/SparcMCAsmInfo.cpp @@ -22,7 +22,6 @@ SparcELFMCAsmInfo::SparcELFMCAsmInfo(const Target &T, const StringRef &TT) { ZeroDirective = "\t.skip\t"; CommentString = "!"; HasLEB128 = true; - AbsoluteDebugSectionOffsets = true; SupportsDebugInformation = true; SunStyleELFSectionSwitchSyntax = true; diff --git a/lib/Target/X86/X86MCAsmInfo.cpp b/lib/Target/X86/X86MCAsmInfo.cpp index 1afabc9d9c1..d257ee38c5c 100644 --- a/lib/Target/X86/X86MCAsmInfo.cpp +++ b/lib/Target/X86/X86MCAsmInfo.cpp @@ -84,7 +84,6 @@ X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) { HasLEB128 = true; // Target asm supports leb128 directives (little-endian) // Debug Information - AbsoluteDebugSectionOffsets = true; SupportsDebugInformation = true; // Exceptions handling diff --git a/lib/Target/XCore/XCoreMCAsmInfo.cpp b/lib/Target/XCore/XCoreMCAsmInfo.cpp index bf785755db4..5f6feae3723 100644 --- a/lib/Target/XCore/XCoreMCAsmInfo.cpp +++ b/lib/Target/XCore/XCoreMCAsmInfo.cpp @@ -25,6 +25,5 @@ XCoreMCAsmInfo::XCoreMCAsmInfo(const Target &T, const StringRef &TT) { // Debug HasLEB128 = true; - AbsoluteDebugSectionOffsets = true; }