eliminate the magic AbsoluteDebugSectionOffsets MAI hook,
authorChris Lattner <sabre@nondot.org>
Sun, 4 Apr 2010 23:22:29 +0000 (23:22 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 4 Apr 2010 23:22:29 +0000 (23:22 +0000)
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

include/llvm/MC/MCAsmInfo.h
include/llvm/MC/MCSection.h
include/llvm/MC/MCSectionELF.h
lib/CodeGen/AsmPrinter/DwarfPrinter.cpp
lib/MC/MCAsmInfo.cpp
lib/MC/MCAsmInfoCOFF.cpp
lib/Target/ARM/ARMMCAsmInfo.cpp
lib/Target/PowerPC/PPCMCAsmInfo.cpp
lib/Target/Sparc/SparcMCAsmInfo.cpp
lib/Target/X86/X86MCAsmInfo.cpp
lib/Target/XCore/XCoreMCAsmInfo.cpp

index d190ea4568f00e4687333cf0a84b9bee2d257afe..33def8618990fec56d0cf0c0e3e3cd1b3d1ebd1d 100644 (file)
@@ -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;
     }
index 4a1c46ccb926f83093272f58c064d3f25f0103e6..e9c19fce20aab0277a59fa7d96175bc30b9cec75 100644 (file)
@@ -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 {
index cdd2f73b3484bbc741d312d2e165ce96d889c871..e550cd2c11111ea89c32078d658b5427b5d43a43 100644 (file)
@@ -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
index 7de6109967142adf6ff93463499efa0a5ccce2bc..84d47ec4496c4a91ffe871a77466d1c4fbc19391 100644 (file)
@@ -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);
 }
 
index 0306dec363f6978273722ee679757a32a977fbc7..f0da694a19e510b9368a18ffd7060ac00c3701ae 100644 (file)
@@ -60,7 +60,6 @@ MCAsmInfo::MCAsmInfo() {
   LinkOnceDirective = 0;
   HiddenVisibilityAttr = MCSA_Hidden;
   ProtectedVisibilityAttr = MCSA_Protected;
-  AbsoluteDebugSectionOffsets = false;
   HasLEB128 = false;
   HasDotLocAndDotFile = false;
   SupportsDebugInformation = false;
index e9bc8fa9c3e47ea086bd46f09958d31c88cde03e..7fc7d7abb232c8283ce663fe7dbfb1d60b68a4f8 100644 (file)
@@ -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;
index 20197e487d316a253148ce9ac8ea28b2d4a63769..53edfcad930847627bfa73c289e56b9eae72fcef 100644 (file)
@@ -58,7 +58,6 @@ ARMELFMCAsmInfo::ARMELFMCAsmInfo() {
   CommentString = "@";
 
   HasLEB128 = true;
-  AbsoluteDebugSectionOffsets = true;
   PrivateGlobalPrefix = ".L";
   WeakRefDirective = "\t.weak\t";
   HasLCOMMDirective = true;
index 0be1fa4d94f7a9e0799b170fd7fbbe6b75b96c42..3644c79d04101be2d3c7cde5923957b14247d25f 100644 (file)
@@ -38,7 +38,6 @@ PPCLinuxMCAsmInfo::PPCLinuxMCAsmInfo(bool is64Bit) {
   UsesELFSectionDirectiveForBSS = true;  
 
   // Debug Information
-  AbsoluteDebugSectionOffsets = true;
   SupportsDebugInformation = true;
 
   PCSymbol = ".";
index 53a9bde9252679945f4f3e871ca7fa404eb1d3c3..535c6f7c8a27ee504ca3c68f43658cc1980cfde4 100644 (file)
@@ -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;
index 1afabc9d9c15b64cf5b615454cbd5a2033dc1f4c..d257ee38c5c786e5b5bd36ea35987373e562a3bd 100644 (file)
@@ -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
index bf785755db4e5235975ccc11c0134a66d48e0144..5f6feae372352b60a9e2087b5c7d3bd4cc8cd131 100644 (file)
@@ -25,6 +25,5 @@ XCoreMCAsmInfo::XCoreMCAsmInfo(const Target &T, const StringRef &TT) {
 
   // Debug
   HasLEB128 = true;
-  AbsoluteDebugSectionOffsets = true;
 }