[lld] r249150 - [ELF2] Fix mixed-Endian handling in DynamicSection<ELFT>::writeTo
Hal Finkel via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 2 09:21:30 PDT 2015
Author: hfinkel
Date: Fri Oct 2 11:21:30 2015
New Revision: 249150
URL: http://llvm.org/viewvc/llvm-project?rev=249150&view=rev
Log:
[ELF2] Fix mixed-Endian handling in DynamicSection<ELFT>::writeTo
Using the "raw" Elf64_Dyn or Elf32_Dyn structures in
DynamicSection<ELFT>::writeTo does not correctly handle mixed-Endian
situations. Instead, use the corresponding llvm::object::* structures which
have Endian-converting members (like the rest of the code).
This fixes all currently-failing elf2 tests when running on big-Endian
PPC64/Linux (I've added a big-Endian test case which should fail on
little-Endian machines in the same way that test/elf2/shared.s failed on
big-Endian machines prior to this change).
Added:
lld/trunk/test/elf2/shared-be.s
Modified:
lld/trunk/ELF/OutputSections.cpp
lld/trunk/ELF/OutputSections.h
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=249150&r1=249149&r2=249150&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Fri Oct 2 11:21:30 2015
@@ -223,8 +223,6 @@ template <class ELFT> void DynamicSectio
}
template <class ELFT> void DynamicSection<ELFT>::writeTo(uint8_t *Buf) {
- typedef typename std::conditional<ELFT::Is64Bits, Elf64_Dyn, Elf32_Dyn>::type
- Elf_Dyn;
auto *P = reinterpret_cast<Elf_Dyn *>(Buf);
auto WritePtr = [&](int32_t Tag, uint64_t Val) {
Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=249150&r1=249149&r2=249150&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Fri Oct 2 11:21:30 2015
@@ -316,6 +316,7 @@ class DynamicSection final : public Outp
typedef typename llvm::object::ELFFile<ELFT>::Elf_Rel Elf_Rel;
typedef typename llvm::object::ELFFile<ELFT>::Elf_Rela Elf_Rela;
typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
+ typedef typename llvm::object::ELFFile<ELFT>::Elf_Dyn Elf_Dyn;
public:
DynamicSection(SymbolTable &SymTab, HashTableSection<ELFT> &HashSec,
Added: lld/trunk/test/elf2/shared-be.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/shared-be.s?rev=249150&view=auto
==============================================================================
--- lld/trunk/test/elf2/shared-be.s (added)
+++ lld/trunk/test/elf2/shared-be.s Fri Oct 2 11:21:30 2015
@@ -0,0 +1,35 @@
+// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
+// RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %p/Inputs/shared.s -o %t2.o
+// RUN: lld -flavor gnu2 -shared %t2.o -o %t2.so
+// RUN: lld -flavor gnu2 -dynamic-linker /lib64/ld64.so.1 -rpath foo -rpath bar --export-dynamic %t.o %t2.so -o %t
+// RUN: llvm-readobj --program-headers --dynamic-table -t -s -dyn-symbols -section-data -hash-table %t | FileCheck %s
+// REQUIRES: ppc
+
+// CHECK: Name: .rela.dyn
+// CHECK-NEXT: Type: SHT_REL
+// CHECK-NEXT: Flags [
+// CHECK-NEXT: SHF_ALLOC
+// CHECK-NEXT: ]
+// CHECK-NEXT: Address: [[RELADDR:.*]]
+// CHECK-NEXT: Offset:
+// CHECK-NEXT: Size: [[RELSIZE:.*]]
+// CHECK-NEXT: Link:
+// CHECK-NEXT: Info:
+// CHECK-NEXT: AddressAlignment:
+// CHECK-NEXT: EntrySize: [[RELENT:.*]]
+
+// CHECK: DynamicSection [
+// CHECK-NEXT: Tag Type Name/Value
+// CHECK-NEXT: 0x0000000000000007 RELA [[RELADDR]]
+// CHECK-NEXT: 0x0000000000000008 RELASZ [[RELSIZE]] (bytes)
+// CHECK-NEXT: 0x0000000000000009 RELAENT [[RELENT]] (bytes)
+// CHECK: 0x000000000000001D RUNPATH foo:bar
+// CHECK-NEXT: 0x0000000000000001 NEEDED SharedLibrary ({{.*}}2.so)
+// CHECK-NEXT: 0x0000000000000000 NULL 0x0
+// CHECK-NEXT: ]
+
+.global _start
+_start:
+.long bar
+.long zed
+
More information about the llvm-commits
mailing list