[llvm-commits] [llvm] r113509 - /llvm/trunk/lib/MC/ELFObjectWriter.cpp

Benjamin Kramer benny.kra at googlemail.com
Thu Sep 9 11:01:29 PDT 2010


Author: d0k
Date: Thu Sep  9 13:01:29 2010
New Revision: 113509

URL: http://llvm.org/viewvc/llvm-project?rev=113509&view=rev
Log:
MCELF: Write relocation fragments in the right endian.

- This code is gross, but does the job for now.

Modified:
    llvm/trunk/lib/MC/ELFObjectWriter.cpp

Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=113509&r1=113508&r2=113509&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Thu Sep  9 13:01:29 2010
@@ -745,12 +745,33 @@
   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);
+      }
+    }
   }
 }
 





More information about the llvm-commits mailing list