summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2010-12-06 19:08:48 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2010-12-06 19:08:48 +0000
commit179821ac1f282ef6f8d24d5ea346028aee8ba4c7 (patch)
tree25a5861add458a1bafe0a084a2cdc08827ffc48e
parentc76c59840b7a4491afdcd2f35483f8d6e5ab533a (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121028 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/MC/MCAsmLayout.h10
-rw-r--r--include/llvm/MC/MCAssembler.h3
-rw-r--r--include/llvm/Target/TargetAsmBackend.h3
-rw-r--r--lib/MC/MCAssembler.cpp136
-rw-r--r--lib/Target/ARM/ARMAsmBackend.cpp18
-rw-r--r--lib/Target/MBlaze/MBlazeAsmBackend.cpp10
-rw-r--r--lib/Target/PowerPC/PPCAsmBackend.cpp2
-rw-r--r--lib/Target/X86/X86AsmBackend.cpp6
8 files changed, 60 insertions, 128 deletions
diff --git a/include/llvm/MC/MCAsmLayout.h b/include/llvm/MC/MCAsmLayout.h
index cad7664c3a5..ce9692dcaff 100644
--- a/include/llvm/MC/MCAsmLayout.h
+++ b/include/llvm/MC/MCAsmLayout.h
@@ -58,16 +58,6 @@ public:
/// 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();
diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h
index 16c527ffc16..ba894369819 100644
--- a/include/llvm/MC/MCAssembler.h
+++ b/include/llvm/MC/MCAssembler.h
@@ -735,6 +735,9 @@ private:
/// 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.
diff --git a/include/llvm/Target/TargetAsmBackend.h b/include/llvm/Target/TargetAsmBackend.h
index 6faedf42568..ba344726906 100644
--- a/include/llvm/Target/TargetAsmBackend.h
+++ b/include/llvm/Target/TargetAsmBackend.h
@@ -13,7 +13,6 @@
#include "llvm/Support/DataTypes.h"
namespace llvm {
-class MCDataFragment;
class MCFixup;
class MCInst;
class MCObjectFormat;
@@ -87,7 +86,7 @@ public:
/// 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
diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp
index ac0f31f79eb..e13b3adea43 100644
--- a/lib/MC/MCAssembler.cpp
+++ b/lib/MC/MCAssembler.cpp
@@ -113,30 +113,6 @@ void MCAsmLayout::EnsureValid(const MCFragment *F) const {
}
}
-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 @@ static void WriteFragmentData(const MCAssembler &Asm, const MCAsmLayout &Layout,
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 @@ void MCAssembler::WriteSectionData(const MCSectionData *SD,
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 @@ void MCAssembler::Finish(MCObjectWriter *Writer) {
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 @@ bool MCAssembler::LayoutOnce(const MCObjectWriter &Writer,
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 @@ void MCAssembler::FinishLayout(MCAsmLayout &Layout) {
// 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
diff --git a/lib/Target/ARM/ARMAsmBackend.cpp b/lib/Target/ARM/ARMAsmBackend.cpp
index 392a6e6c033..536923e47bf 100644
--- a/lib/Target/ARM/ARMAsmBackend.cpp
+++ b/lib/Target/ARM/ARMAsmBackend.cpp
@@ -138,7 +138,7 @@ public:
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 @@ public:
};
// 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 @@ void ELFARMAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
// 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 @@ public:
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 @@ static unsigned getFixupKindNumBytes(unsigned Kind) {
}
}
-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
diff --git a/lib/Target/MBlaze/MBlazeAsmBackend.cpp b/lib/Target/MBlaze/MBlazeAsmBackend.cpp
index 56c04199cff..0d39d60a89c 100644
--- a/lib/Target/MBlaze/MBlazeAsmBackend.cpp
+++ b/lib/Target/MBlaze/MBlazeAsmBackend.cpp
@@ -110,7 +110,7 @@ public:
}
- 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 @@ public:
}
};
-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.");
diff --git a/lib/Target/PowerPC/PPCAsmBackend.cpp b/lib/Target/PowerPC/PPCAsmBackend.cpp
index de0ee4ebe9c..29598adfd43 100644
--- a/lib/Target/PowerPC/PPCAsmBackend.cpp
+++ b/lib/Target/PowerPC/PPCAsmBackend.cpp
@@ -64,7 +64,7 @@ namespace {
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");
}
diff --git a/lib/Target/X86/X86AsmBackend.cpp b/lib/Target/X86/X86AsmBackend.cpp
index 48467c89e5b..5626fd7afd3 100644
--- a/lib/Target/X86/X86AsmBackend.cpp
+++ b/lib/Target/X86/X86AsmBackend.cpp
@@ -49,14 +49,14 @@ public:
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;