[llvm-commits] [llvm] r121028 - in /llvm/trunk: include/llvm/MC/MCAsmLayout.h include/llvm/MC/MCAssembler.h include/llvm/Target/TargetAsmBackend.h lib/MC/MCAssembler.cpp lib/Target/ARM/ARMAsmBackend.cpp lib/Target/MBlaze/MBlazeAsmBackend.cpp lib/Target/PowerPC/PPCAsmBackend.cpp lib/Target/X86/X86AsmBackend.cpp

Rafael Espindola rafael.espindola at gmail.com
Mon Dec 6 11:08:48 PST 2010


Author: rafael
Date: Mon Dec  6 13:08:48 2010
New Revision: 121028

URL: http://llvm.org/viewvc/llvm-project?rev=121028&view=rev
Log:
Remove the instruction fragment to data fragment lowering since it was causing
freed data to be read. I will open a bug to track it being reenabled.

Modified:
    llvm/trunk/include/llvm/MC/MCAsmLayout.h
    llvm/trunk/include/llvm/MC/MCAssembler.h
    llvm/trunk/include/llvm/Target/TargetAsmBackend.h
    llvm/trunk/lib/MC/MCAssembler.cpp
    llvm/trunk/lib/Target/ARM/ARMAsmBackend.cpp
    llvm/trunk/lib/Target/MBlaze/MBlazeAsmBackend.cpp
    llvm/trunk/lib/Target/PowerPC/PPCAsmBackend.cpp
    llvm/trunk/lib/Target/X86/X86AsmBackend.cpp

Modified: llvm/trunk/include/llvm/MC/MCAsmLayout.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmLayout.h?rev=121028&r1=121027&r2=121028&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAsmLayout.h (original)
+++ llvm/trunk/include/llvm/MC/MCAsmLayout.h Mon Dec  6 13:08:48 2010
@@ -58,16 +58,6 @@
   /// fragments size should have already been updated.
   void Invalidate(MCFragment *F);
 
-  /// \brief Update the layout, replacing Src with Dst. The contents
-  /// of Src and Dst are not modified, and must be copied by the caller.
-  /// Src will be removed from the layout, but not deleted.
-  void ReplaceFragment(MCFragment *Src, MCFragment *Dst);
-
-  /// \brief Update the layout to coalesce Src into Dst. The contents
-  /// of Src and Dst are not modified, and must be coalesced by the caller.
-  /// Src will be removed from the layout, but not deleted.
-  void CoalesceFragments(MCFragment *Src, MCFragment *Dst);
-
   /// \brief Perform a full layout.
   void LayoutFile();
 

Modified: llvm/trunk/include/llvm/MC/MCAssembler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAssembler.h?rev=121028&r1=121027&r2=121028&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAssembler.h (original)
+++ llvm/trunk/include/llvm/MC/MCAssembler.h Mon Dec  6 13:08:48 2010
@@ -735,6 +735,9 @@
   /// FinishLayout - Finalize a layout, including fragment lowering.
   void FinishLayout(MCAsmLayout &Layout);
 
+  uint64_t HandleFixup(MCObjectWriter &Writer, const MCAsmLayout &Layout,
+                       MCFragment &F, const MCFixup &Fixup);
+
 public:
   /// Find the symbol which defines the atom containing the given symbol, or
   /// null if there is no such symbol.

Modified: llvm/trunk/include/llvm/Target/TargetAsmBackend.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetAsmBackend.h?rev=121028&r1=121027&r2=121028&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmBackend.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmBackend.h Mon Dec  6 13:08:48 2010
@@ -13,7 +13,6 @@
 #include "llvm/Support/DataTypes.h"
 
 namespace llvm {
-class MCDataFragment;
 class MCFixup;
 class MCInst;
 class MCObjectFormat;
@@ -87,7 +86,7 @@
   /// ApplyFixup - Apply the \arg Value for given \arg Fixup into the provided
   /// data fragment, at the offset specified by the fixup and following the
   /// fixup kind as appropriate.
-  virtual void ApplyFixup(const MCFixup &Fixup, MCDataFragment &Fragment,
+  virtual void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
                           uint64_t Value) const = 0;
 
   /// MayNeedRelaxation - Check whether the given instruction may need

Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=121028&r1=121027&r2=121028&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Mon Dec  6 13:08:48 2010
@@ -113,30 +113,6 @@
   }
 }
 
-void MCAsmLayout::ReplaceFragment(MCFragment *Src, MCFragment *Dst) {
-  MCSectionData *SD = Src->getParent();
-
-  // Insert Dst immediately before Src
-  SD->getFragmentList().insert(Src, Dst);
-
-  // Set the data fragment's layout data.
-  Dst->setParent(Src->getParent());
-  Dst->setAtom(Src->getAtom());
-
-  Dst->Offset = Src->Offset;
-  Dst->EffectiveSize = Src->EffectiveSize;
-
-  // Remove Src, but don't delete it yet.
-  SD->getFragmentList().remove(Src);
-}
-
-void MCAsmLayout::CoalesceFragments(MCFragment *Src, MCFragment *Dst) {
-  assert(Src->getPrevNode() == Dst);
-  Dst->EffectiveSize += Src->EffectiveSize;
-  // Remove Src, but don't delete it yet.
-  Src->getParent()->getFragmentList().remove(Src);
-}
-
 uint64_t MCAsmLayout::getFragmentAddress(const MCFragment *F) const {
   assert(F->getParent() && "Missing section()!");
   return getSectionAddress(F->getParent()) + getFragmentOffset(F);
@@ -510,9 +486,11 @@
     break;
   }
 
-  case MCFragment::FT_Inst:
-    llvm_unreachable("unexpected inst fragment after lowering");
+  case MCFragment::FT_Inst: {
+    MCInstFragment &IF = cast<MCInstFragment>(F);
+    OW->WriteBytes(StringRef(IF.getCode().begin(), IF.getCode().size()));
     break;
+  }
 
   case MCFragment::FT_LEB: {
     MCLEBFragment &LF = cast<MCLEBFragment>(F);
@@ -591,6 +569,23 @@
   assert(OW->getStream().tell() - Start == Layout.getSectionFileSize(SD));
 }
 
+
+uint64_t MCAssembler::HandleFixup(MCObjectWriter &Writer,
+                              const MCAsmLayout &Layout,
+                              MCFragment &F,
+                              const MCFixup &Fixup) {
+   // Evaluate the fixup.
+   MCValue Target;
+   uint64_t FixedValue;
+   if (!EvaluateFixup(Writer, Layout, Fixup, &F, Target, FixedValue)) {
+     // The fixup was unresolved, we need a relocation. Inform the object
+     // writer of the relocation, and give it an opportunity to adjust the
+     // fixup value if need be.
+     Writer.RecordRelocation(*this, Layout, &F, Fixup, Target, FixedValue);
+   }
+   return FixedValue;
+ }
+
 void MCAssembler::Finish(MCObjectWriter *Writer) {
   DEBUG_WITH_TYPE("mc-dump", {
       llvm::errs() << "assembler backend - pre-layout\n--\n";
@@ -680,24 +675,24 @@
     for (MCSectionData::iterator it2 = it->begin(),
            ie2 = it->end(); it2 != ie2; ++it2) {
       MCDataFragment *DF = dyn_cast<MCDataFragment>(it2);
-      if (!DF)
-        continue;
-
-      for (MCDataFragment::fixup_iterator it3 = DF->fixup_begin(),
-             ie3 = DF->fixup_end(); it3 != ie3; ++it3) {
-        MCFixup &Fixup = *it3;
-
-        // Evaluate the fixup.
-        MCValue Target;
-        uint64_t FixedValue;
-        if (!EvaluateFixup(*Writer, Layout, Fixup, DF, Target, FixedValue)) {
-          // The fixup was unresolved, we need a relocation. Inform the object
-          // writer of the relocation, and give it an opportunity to adjust the
-          // fixup value if need be.
-          Writer->RecordRelocation(*this, Layout, DF, Fixup, Target,FixedValue);
+      if (DF) {
+        for (MCDataFragment::fixup_iterator it3 = DF->fixup_begin(),
+               ie3 = DF->fixup_end(); it3 != ie3; ++it3) {
+          MCFixup &Fixup = *it3;
+          uint64_t FixedValue = HandleFixup(*Writer, Layout, *DF, Fixup);
+          getBackend().ApplyFixup(Fixup, DF->getContents().data(),
+                                  DF->getContents().size(), FixedValue);
+        }
+      }
+      MCInstFragment *IF = dyn_cast<MCInstFragment>(it2);
+      if (IF) {
+        for (MCInstFragment::fixup_iterator it3 = IF->fixup_begin(),
+               ie3 = IF->fixup_end(); it3 != ie3; ++it3) {
+          MCFixup &Fixup = *it3;
+          uint64_t FixedValue = HandleFixup(*Writer, Layout, *IF, Fixup);
+          getBackend().ApplyFixup(Fixup, IF->getCode().data(),
+                                  IF->getCode().size(), FixedValue);
         }
-
-        getBackend().ApplyFixup(Fixup, *DF, FixedValue);
       }
     }
   }
@@ -877,22 +872,6 @@
   return WasRelaxed;
 }
 
-static void LowerInstFragment(MCInstFragment *IF,
-                              MCDataFragment *DF) {
-
-  uint64_t DataOffset = DF->getContents().size();
-
-  // Copy in the data
-  DF->getContents().append(IF->getCode().begin(), IF->getCode().end());
-
-  // Adjust the fixup offsets and add them to the data fragment.
-  for (unsigned i = 0, e = IF->getFixups().size(); i != e; ++i) {
-    MCFixup &F = IF->getFixups()[i];
-    F.setOffset(DataOffset + F.getOffset());
-    DF->getFixups().push_back(F);
-  }
-}
-
 void MCAssembler::FinishLayout(MCAsmLayout &Layout) {
   // Lower out any instruction fragments, to simplify the fixup application and
   // output.
@@ -904,45 +883,6 @@
 
   // The layout is done. Mark every fragment as valid.
   Layout.getFragmentOffset(&*Layout.getSectionOrder().back()->rbegin());
-
-  unsigned FragmentIndex = 0;
-  for (unsigned i = 0, e = Layout.getSectionOrder().size(); i != e; ++i) {
-    MCSectionData &SD = *Layout.getSectionOrder()[i];
-    MCDataFragment *CurDF = NULL;
-
-    for (MCSectionData::iterator it2 = SD.begin(),
-           ie2 = SD.end(); it2 != ie2; ++it2) {
-      switch (it2->getKind()) {
-      default:
-        CurDF = NULL;
-        break;
-      case MCFragment::FT_Data:
-        CurDF = cast<MCDataFragment>(it2);
-        break;
-      case MCFragment::FT_Inst: {
-        MCInstFragment *IF = cast<MCInstFragment>(it2);
-        // Use the existing data fragment if possible.
-        if (CurDF && CurDF->getAtom() == IF->getAtom()) {
-          Layout.CoalesceFragments(IF, CurDF);
-        } else {
-          // Otherwise, create a new data fragment.
-          CurDF = new MCDataFragment();
-          Layout.ReplaceFragment(IF, CurDF);
-        }
-
-        // Lower the Instruction Fragment
-        LowerInstFragment(IF, CurDF);
-
-        // Delete the instruction fragment and update the iterator.
-        delete IF;
-        it2 = CurDF;
-        break;
-      }
-      }
-      // Since we may have merged fragments, fix the layout order.
-      it2->setLayoutOrder(FragmentIndex++);
-    }
-  }
 }
 
 // Debugging methods

Modified: llvm/trunk/lib/Target/ARM/ARMAsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMAsmBackend.cpp?rev=121028&r1=121027&r2=121028&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMAsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMAsmBackend.cpp Mon Dec  6 13:08:48 2010
@@ -138,7 +138,7 @@
     return Format;
   }
 
-  void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
+  void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
                   uint64_t Value) const;
 
   MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
@@ -150,8 +150,8 @@
 };
 
 // Fixme: Raise this to share code between Darwin and ELF.
-void ELFARMAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
-                                  uint64_t Value) const {
+void ELFARMAsmBackend::ApplyFixup(const MCFixup &Fixup, char *Data,
+                                  unsigned DataSize, uint64_t Value) const {
   // Fixme: 2 for Thumb
   unsigned NumBytes = 4;
   Value = adjustFixupValue(Fixup.getKind(), Value);
@@ -162,7 +162,7 @@
   // bits from the fixup value.
   // The Value has been "split up" into the appropriate bitfields above.
   for (unsigned i = 0; i != NumBytes; ++i) {
-    DF.getContents()[Fixup.getOffset() + i] |= uint8_t(Value >> (i * 8));
+    Data[Fixup.getOffset() + i] |= uint8_t(Value >> (i * 8));
   }
 }
 
@@ -179,7 +179,7 @@
     return Format;
   }
 
-  void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
+  void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
                   uint64_t Value) const;
 
   MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
@@ -207,17 +207,17 @@
   }
 }
 
-void DarwinARMAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
-                                     uint64_t Value) const {
+void DarwinARMAsmBackend::ApplyFixup(const MCFixup &Fixup, char *Data,
+                                     unsigned DataSize, uint64_t Value) const {
   unsigned NumBytes = getFixupKindNumBytes(Fixup.getKind());
   Value = adjustFixupValue(Fixup.getKind(), Value);
 
-  assert(Fixup.getOffset() + NumBytes <= DF.getContents().size() &&
+  assert(Fixup.getOffset() + NumBytes <= DataSize &&
          "Invalid fixup offset!");
   // For each byte of the fragment that the fixup touches, mask in the
   // bits from the fixup value.
   for (unsigned i = 0; i != NumBytes; ++i)
-    DF.getContents()[Fixup.getOffset() + i] |= uint8_t(Value >> (i * 8));
+    Data[Fixup.getOffset() + i] |= uint8_t(Value >> (i * 8));
 }
 } // end anonymous namespace
 

Modified: llvm/trunk/lib/Target/MBlaze/MBlazeAsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MBlaze/MBlazeAsmBackend.cpp?rev=121028&r1=121027&r2=121028&view=diff
==============================================================================
--- llvm/trunk/lib/Target/MBlaze/MBlazeAsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/MBlaze/MBlazeAsmBackend.cpp Mon Dec  6 13:08:48 2010
@@ -110,7 +110,7 @@
   }
 
 
-  void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
+  void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
                   uint64_t Value) const;
 
   MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
@@ -121,14 +121,14 @@
   }
 };
 
-void ELFMBlazeAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
-                                     uint64_t Value) const {
+void ELFMBlazeAsmBackend::ApplyFixup(const MCFixup &Fixup, char *Data,
+                                     unsigned DataSize, uint64_t Value) const {
   unsigned Size = getFixupKindSize(Fixup.getKind());
 
-  assert(Fixup.getOffset() + Size <= DF.getContents().size() &&
+  assert(Fixup.getOffset() + Size <= DataSize &&
          "Invalid fixup offset!");
 
-  char *data = DF.getContents().data() + Fixup.getOffset();
+  char *data = Data + Fixup.getOffset();
   switch (Size) {
   default: llvm_unreachable("Cannot fixup unknown value.");
   case 1:  llvm_unreachable("Cannot fixup 1 byte value.");

Modified: llvm/trunk/lib/Target/PowerPC/PPCAsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCAsmBackend.cpp?rev=121028&r1=121027&r2=121028&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCAsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCAsmBackend.cpp Mon Dec  6 13:08:48 2010
@@ -64,7 +64,7 @@
       return Format;
     }
     
-    void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
+    void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
                     uint64_t Value) const {
       assert(0 && "UNIMP");
     }

Modified: llvm/trunk/lib/Target/X86/X86AsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86AsmBackend.cpp?rev=121028&r1=121027&r2=121028&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86AsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86AsmBackend.cpp Mon Dec  6 13:08:48 2010
@@ -49,14 +49,14 @@
   X86AsmBackend(const Target &T)
     : TargetAsmBackend() {}
 
-  void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
+  void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
                   uint64_t Value) const {
     unsigned Size = 1 << getFixupKindLog2Size(Fixup.getKind());
 
-    assert(Fixup.getOffset() + Size <= DF.getContents().size() &&
+    assert(Fixup.getOffset() + Size <= DataSize &&
            "Invalid fixup offset!");
     for (unsigned i = 0; i != Size; ++i)
-      DF.getContents()[Fixup.getOffset() + i] = uint8_t(Value >> (i * 8));
+      Data[Fixup.getOffset() + i] = uint8_t(Value >> (i * 8));
   }
 
   bool MayNeedRelaxation(const MCInst &Inst) const;





More information about the llvm-commits mailing list