aboutsummaryrefslogtreecommitdiff
path: root/lib/MC/ELFObjectWriter.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2010-09-09 18:01:29 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2010-09-09 18:01:29 +0000
commit5e492e8d42fa1f2940165a937d3d613c61b57708 (patch)
treeff3fc6de0dc0671d4fac2f8a9b7af5e77f058c95 /lib/MC/ELFObjectWriter.cpp
parent5baf79edc067a4b17d024cc10324ac88c17e3e43 (diff)
MCELF: Write relocation fragments in the right endian.
- This code is gross, but does the job for now. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113509 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/ELFObjectWriter.cpp')
-rw-r--r--lib/MC/ELFObjectWriter.cpp31
1 files changed, 26 insertions, 5 deletions
diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp
index b12491e1d9..feabd6008b 100644
--- a/lib/MC/ELFObjectWriter.cpp
+++ b/lib/MC/ELFObjectWriter.cpp
@@ -745,12 +745,33 @@ void ELFObjectWriterImpl::WriteRelocationsFragment(const MCAssembler &Asm,
for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {
ELFRelocationEntry entry = Relocs[e - i - 1];
- unsigned WordSize = Is64Bit ? 8 : 4;
- F->getContents() += StringRef((const char *)&entry.r_offset, WordSize);
- F->getContents() += StringRef((const char *)&entry.r_info, WordSize);
+ if (Is64Bit) {
+ char buf[8];
- if (HasRelocationAddend)
- F->getContents() += StringRef((const char *)&entry.r_addend, WordSize);
+ String64(buf, entry.r_offset);
+ F->getContents() += StringRef(buf, 8);
+
+ String64(buf, entry.r_info);
+ F->getContents() += StringRef(buf, 8);
+
+ if (HasRelocationAddend) {
+ String64(buf, entry.r_addend);
+ F->getContents() += StringRef(buf, 8);
+ }
+ } else {
+ char buf[4];
+
+ String32(buf, entry.r_offset);
+ F->getContents() += StringRef(buf, 4);
+
+ String32(buf, entry.r_info);
+ F->getContents() += StringRef(buf, 4);
+
+ if (HasRelocationAddend) {
+ String32(buf, entry.r_addend);
+ F->getContents() += StringRef(buf, 4);
+ }
+ }
}
}