[lld] r248303 - Fix the creation of Elf_Rel sections.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 22 10:49:38 PDT 2015


Author: rafael
Date: Tue Sep 22 12:49:38 2015
New Revision: 248303

URL: http://llvm.org/viewvc/llvm-project?rev=248303&view=rev
Log:
Fix the creation of Elf_Rel sections.

We were always incrementing the output buffer pointer by sizeof(Elf_Rela).

Modified:
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/test/elf2/shared.s

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=248303&r1=248302&r2=248303&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Tue Sep 22 12:49:38 2015
@@ -92,9 +92,12 @@ bool lld::elf2::relocNeedsGOT(uint32_t T
 }
 
 template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *Buf) {
-  auto *P = reinterpret_cast<Elf_Rela *>(Buf);
+  const unsigned EntrySize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
   bool IsMips64EL = Relocs[0].C.getFile()->getObj()->isMips64EL();
   for (const DynamicReloc<ELFT> &Rel : Relocs) {
+    auto *P = reinterpret_cast<Elf_Rel *>(Buf);
+    Buf += EntrySize;
+
     const InputSection<ELFT> &C = Rel.C;
     const Elf_Rel &RI = Rel.RI;
     OutputSection<ELFT> *Out = C.getOutputSection();
@@ -109,10 +112,9 @@ template <class ELFT> void RelocationSec
       P->r_offset = RI.r_offset + C.getOutputSectionOff() + Out->getVA();
       P->setSymbolAndType(Body->getDynamicSymbolTableIndex(), Type, IsMips64EL);
       if (IsRela)
-        P->r_addend = static_cast<const Elf_Rela &>(RI).r_addend;
+        static_cast<Elf_Rela *>(P)->r_addend =
+            static_cast<const Elf_Rela &>(RI).r_addend;
     }
-
-    ++P;
   }
 }
 

Modified: lld/trunk/test/elf2/shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/shared.s?rev=248303&r1=248302&r2=248303&view=diff
==============================================================================
--- lld/trunk/test/elf2/shared.s (original)
+++ lld/trunk/test/elf2/shared.s Tue Sep 22 12:49:38 2015
@@ -45,7 +45,7 @@
 // CHECK-NEXT:   ]
 // CHECK-NEXT:   Address: [[DYNSYMADDR:.*]]
 // CHECK-NEXT:   Offset: 0x201C
-// CHECK-NEXT:   Size: 48
+// CHECK-NEXT:   Size:
 // CHECK-NEXT:   Link: [[DYNSTR:.*]]
 // CHECK-NEXT:   Info: 1
 // CHECK-NEXT:   AddressAlignment: 4
@@ -54,6 +54,7 @@
 // CHECK-NEXT:     0000:
 // CHECK-NEXT:     0010:
 // CHECK-NEXT:     0020:
+// CHECK-NEXT:     0030:
 // CHECK-NEXT:   )
 // CHECK-NEXT: }
 // CHECK-NEXT: Section {
@@ -144,6 +145,15 @@
 // CHECK-NEXT:     Other: 0
 // CHECK-NEXT:     Section: Undefined
 // CHECK-NEXT:   }
+// CHECK-NEXT:   Symbol {
+// CHECK-NEXT:     Name: zed (62)
+// CHECK-NEXT:     Value: 0x0
+// CHECK-NEXT:     Size: 0
+// CHECK-NEXT:     Binding: Global (0x1)
+// CHECK-NEXT:     Type: None (0x0)
+// CHECK-NEXT:     Other: 0
+// CHECK-NEXT:     Section: Undefined (0x0)
+// CHECK-NEXT:   }
 // CHECK-NEXT: ]
 
 // CHECK:      DynamicSymbols [
@@ -174,6 +184,15 @@
 // CHECK-NEXT:     Other: 0
 // CHECK-NEXT:     Section: Undefined
 // CHECK-NEXT:   }
+// CHECK-NEXT:   Symbol {
+// CHECK-NEXT:     Name: zed@
+// CHECK-NEXT:     Value: 0x0
+// CHECK-NEXT:     Size: 0
+// CHECK-NEXT:     Binding: Global
+// CHECK-NEXT:     Type: None
+// CHECK-NEXT:     Other: 0
+// CHECK-NEXT:     Section: Undefined
+// CHECK-NEXT:   }
 // CHECK-NEXT: ]
 
 // CHECK:      DynamicSection [
@@ -216,12 +235,13 @@
 // CHECK-NEXT: }
 
 // CHECK:      HashTable {
-// CHECK-NEXT:   Num Buckets: 3
-// CHECK-NEXT:   Num Chains: 3
-// CHECK-NEXT:   Buckets: [2, 0, 1]
-// CHECK-NEXT:   Chains: [0, 0, 0]
+// CHECK-NEXT:   Num Buckets: 4
+// CHECK-NEXT:   Num Chains: 4
+// CHECK-NEXT:   Buckets: [3, 0, 2, 0]
+// CHECK-NEXT:   Chains: [0, 0, 0, 1]
 // CHECK-NEXT: }
 
 .global _start
 _start:
 .long bar
+.long zed




More information about the llvm-commits mailing list