aboutsummaryrefslogtreecommitdiff
path: root/lib/MC/MCAssembler.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-02-13 09:28:54 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-02-13 09:28:54 +0000
commit2be2fd073003c0988723d2894dfb117ad90be11b (patch)
tree474d12cad56fc69fa8a413a9f486093ab47f7a2b /lib/MC/MCAssembler.cpp
parent0bcf074867d4d366f7988a219c7a53265fcb4f23 (diff)
MCAssembler: Switch MCAsmFixup to storing MCFixupKind instead of just a size.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96094 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/MCAssembler.cpp')
-rw-r--r--lib/MC/MCAssembler.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp
index 2875730dd3..b2c4112f48 100644
--- a/lib/MC/MCAssembler.cpp
+++ b/lib/MC/MCAssembler.cpp
@@ -47,6 +47,16 @@ static bool isVirtualSection(const MCSection &Section) {
return (Type == MCSectionMachO::S_ZEROFILL);
}
+static unsigned getFixupKindLog2Size(MCFixupKind Kind) {
+ switch (Kind) {
+ default: llvm_unreachable("invalid fixup kind!");
+ case FK_Data_1: return 0;
+ case FK_Data_2: return 1;
+ case FK_Data_4: return 2;
+ case FK_Data_8: return 3;
+ }
+}
+
class MachObjectWriter {
// See <mach-o/loader.h>.
enum {
@@ -426,8 +436,7 @@ public:
Value2 = SD->getFragment()->getAddress() + SD->getOffset();
}
- unsigned Log2Size = Log2_32(Fixup.Size);
- assert((1U << Log2Size) == Fixup.Size && "Invalid fixup size!");
+ unsigned Log2Size = getFixupKindLog2Size(Fixup.Kind);
// The value which goes in the fixup is current value of the expression.
Fixup.FixedValue = Value - Value2 + Target.getConstant();
@@ -512,8 +521,7 @@ public:
// The value which goes in the fixup is current value of the expression.
Fixup.FixedValue = Value + Target.getConstant();
- unsigned Log2Size = Log2_32(Fixup.Size);
- assert((1U << Log2Size) == Fixup.Size && "Invalid fixup size!");
+ unsigned Log2Size = getFixupKindLog2Size(Fixup.Kind);
// struct relocation_info (8 bytes)
MachRelocationEntry MRE;
@@ -880,8 +888,12 @@ public:
}
void ApplyFixup(const MCAsmFixup &Fixup, MCDataFragment &DF) {
+ unsigned Size = 1 << getFixupKindLog2Size(Fixup.Kind);
+
// FIXME: Endianness assumption.
- for (unsigned i = 0; i != Fixup.Size; ++i)
+ assert(Fixup.Offset + Size <= DF.getContents().size() &&
+ "Invalid fixup offset!");
+ for (unsigned i = 0; i != Size; ++i)
DF.getContents()[Fixup.Offset + i] = uint8_t(Fixup.FixedValue >> (i * 8));
}
};
@@ -1186,8 +1198,8 @@ void MCAssembler::Finish() {
namespace llvm {
raw_ostream &operator<<(raw_ostream &OS, const MCAsmFixup &AF) {
- OS << "<MCAsmFixup" << " Offset:" << AF.Offset << " Value:" << AF.Value
- << " Size:" << AF.Size << ">";
+ OS << "<MCAsmFixup" << " Offset:" << AF.Offset << " Value:" << *AF.Value
+ << " Kind:" << AF.Kind << ">";
return OS;
}
@@ -1224,7 +1236,7 @@ void MCDataFragment::dump() {
if (i) OS << ",";
OS << hexdigit((Contents[i] >> 4) & 0xF) << hexdigit(Contents[i] & 0xF);
}
- OS << "]";
+ OS << "] (" << getContents().size() << " bytes)";
if (!getFixups().empty()) {
OS << ",\n ";