aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/ARM/ARMAsmBackend.cpp
diff options
context:
space:
mode:
authorJim Grosbach <grosbach@apple.com>2010-11-09 01:37:15 +0000
committerJim Grosbach <grosbach@apple.com>2010-11-09 01:37:15 +0000
commit679cbd3b215b1769a6035e334f9009aeeb940ddd (patch)
treeb59f0008e5392f003e3d8e3298d1ac5eae2dd404 /lib/Target/ARM/ARMAsmBackend.cpp
parent71365d3774a6c02f3f198fbf08a56e4b6346bbcc (diff)
Add support for a few simple fixups to the ARM Darwin asm backend. This allows
constant pool references and global variable refernces to resolve properly for object file generation. For example, int x; void foo(unsigned a, unsigned *p) { p[a] = x; } can now be successfully compiled directly to an (ARM mode) object file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118469 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/ARM/ARMAsmBackend.cpp')
-rw-r--r--lib/Target/ARM/ARMAsmBackend.cpp36
1 files changed, 34 insertions, 2 deletions
diff --git a/lib/Target/ARM/ARMAsmBackend.cpp b/lib/Target/ARM/ARMAsmBackend.cpp
index ac258fafd8..c475d5cfef 100644
--- a/lib/Target/ARM/ARMAsmBackend.cpp
+++ b/lib/Target/ARM/ARMAsmBackend.cpp
@@ -9,7 +9,7 @@
#include "llvm/Target/TargetAsmBackend.h"
#include "ARM.h"
-//FIXME: add #include "ARMFixupKinds.h"
+#include "ARMFixupKinds.h"
#include "llvm/ADT/Twine.h"
#include "llvm/MC/ELFObjectWriter.h"
#include "llvm/MC/MCAssembler.h"
@@ -138,9 +138,41 @@ public:
}
};
+static unsigned getFixupKindLog2Size(unsigned Kind) {
+ switch (Kind) {
+ default: llvm_unreachable("Unknown fixup kind!");
+ case FK_Data_4: return 2;
+ case ARM::fixup_arm_pcrel_12: return 2;
+ case ARM::fixup_arm_vfp_pcrel_12: return 1;
+ }
+}
+
+static unsigned adjustFixupValue(unsigned Kind, uint64_t Value) {
+ switch (Kind) {
+ default:
+ llvm_unreachable("Unknown fixup kind!");
+ case FK_Data_4:
+ case ARM::fixup_arm_pcrel_12:
+ // ARM PC-relative values are offset by 8.
+ return Value - 8;
+ case ARM::fixup_arm_vfp_pcrel_12:
+ // The VFP ld/st immediate value doesn't encode the low two bits since
+ // they're always zero. Offset by 8 just as above.
+ return (Value - 8) >> 2;
+ }
+}
+
void DarwinARMAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
uint64_t Value) const {
- assert(0 && "DarwinARMAsmBackend::ApplyFixup() unimplemented");
+ unsigned NumBytes = getFixupKindLog2Size(Fixup.getKind());
+ Value = adjustFixupValue(Fixup.getKind(), Value);
+
+ assert(Fixup.getOffset() + NumBytes <= DF.getContents().size() &&
+ "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));
}
} // end anonymous namespace