diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2010-09-09 18:01:29 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2010-09-09 18:01:29 +0000 |
commit | 6c3c349b2ba195609b74b92e3da600d130036a59 (patch) | |
tree | 86f0d49f08a0f10c22a071d20b8426cc49039d67 | |
parent | 3b727f55aa10712fc51be4d9719b294dc5444a28 (diff) | |
download | bcm5719-llvm-6c3c349b2ba195609b74b92e3da600d130036a59.tar.gz bcm5719-llvm-6c3c349b2ba195609b74b92e3da600d130036a59.zip |
MCELF: Write relocation fragments in the right endian.
- This code is gross, but does the job for now.
llvm-svn: 113509
-rw-r--r-- | llvm/lib/MC/ELFObjectWriter.cpp | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index b12491e1d99..feabd6008bf 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/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); + } + } } } |