Add GotEntrySize/GotPltEntrySize to ELF target.
authorRui Ueyama <ruiu@google.com>
Wed, 13 Jul 2016 18:55:14 +0000 (18:55 +0000)
committerRui Ueyama <ruiu@google.com>
Wed, 13 Jul 2016 18:55:14 +0000 (18:55 +0000)
Patch by H.J Lu.

For x86-64 psABI, the entry size of .got and .got.plt sections is 8
bytes for both LP64 and ILP32.  Add GotEntrySize and GotPltEntrySize
to ELF target instead of using size of ELFT::uint.  Now we can generate
a simple working x32 executable.

Differential Revision: http://reviews.llvm.org/D22288

llvm-svn: 275301

lld/ELF/OutputSections.cpp
lld/ELF/Symbols.cpp
lld/ELF/Target.cpp
lld/ELF/Target.h

index a3d228c..7c7ec0a 100644 (file)
@@ -47,7 +47,7 @@ void OutputSectionBase<ELFT>::writeHeaderTo(Elf_Shdr *Shdr) {
 template <class ELFT>
 GotPltSection<ELFT>::GotPltSection()
     : OutputSectionBase<ELFT>(".got.plt", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE) {
-  this->Header.sh_addralign = sizeof(uintX_t);
+  this->Header.sh_addralign = Target->GotPltEntrySize;
 }
 
 template <class ELFT> void GotPltSection<ELFT>::addEntry(SymbolBody &Sym) {
@@ -60,13 +60,13 @@ template <class ELFT> bool GotPltSection<ELFT>::empty() const {
 }
 
 template <class ELFT> void GotPltSection<ELFT>::finalize() {
-  this->Header.sh_size =
-      (Target->GotPltHeaderEntriesNum + Entries.size()) * sizeof(uintX_t);
+  this->Header.sh_size = (Target->GotPltHeaderEntriesNum + Entries.size()) *
+                         Target->GotPltEntrySize;
 }
 
 template <class ELFT> void GotPltSection<ELFT>::writeTo(uint8_t *Buf) {
   Target->writeGotPltHeader(Buf);
-  Buf += Target->GotPltHeaderEntriesNum * sizeof(uintX_t);
+  Buf += Target->GotPltHeaderEntriesNum * Target->GotPltEntrySize;
   for (const SymbolBody *B : Entries) {
     Target->writeGotPlt(Buf, *B);
     Buf += sizeof(uintX_t);
@@ -78,7 +78,7 @@ GotSection<ELFT>::GotSection()
     : OutputSectionBase<ELFT>(".got", SHT_PROGBITS, SHF_ALLOC | SHF_WRITE) {
   if (Config->EMachine == EM_MIPS)
     this->Header.sh_flags |= SHF_MIPS_GPREL;
-  this->Header.sh_addralign = sizeof(uintX_t);
+  this->Header.sh_addralign = Target->GotEntrySize;
 }
 
 template <class ELFT>
index 85c71e3..0c3a116 100644 (file)
@@ -165,7 +165,7 @@ template <class ELFT> typename ELFT::uint SymbolBody::getGotVA() const {
 }
 
 template <class ELFT> typename ELFT::uint SymbolBody::getGotOffset() const {
-  return GotIndex * sizeof(typename ELFT::uint);
+  return GotIndex * Target->GotEntrySize;
 }
 
 template <class ELFT> typename ELFT::uint SymbolBody::getGotPltVA() const {
@@ -173,7 +173,7 @@ template <class ELFT> typename ELFT::uint SymbolBody::getGotPltVA() const {
 }
 
 template <class ELFT> typename ELFT::uint SymbolBody::getGotPltOffset() const {
-  return GotPltIndex * sizeof(typename ELFT::uint);
+  return GotPltIndex * Target->GotPltEntrySize;
 }
 
 template <class ELFT> typename ELFT::uint SymbolBody::getPltVA() const {
index 8e520fb..6908d8f 100644 (file)
@@ -308,6 +308,8 @@ X86TargetInfo::X86TargetInfo() {
   TlsGotRel = R_386_TLS_TPOFF;
   TlsModuleIndexRel = R_386_TLS_DTPMOD32;
   TlsOffsetRel = R_386_TLS_DTPOFF32;
+  GotEntrySize = 4;
+  GotPltEntrySize = 4;
   PltEntrySize = 16;
   PltHeaderSize = 16;
   TlsGdRelaxSkip = 2;
@@ -551,6 +553,8 @@ template <class ELFT> X86_64TargetInfo<ELFT>::X86_64TargetInfo() {
   TlsGotRel = R_X86_64_TPOFF64;
   TlsModuleIndexRel = R_X86_64_DTPMOD64;
   TlsOffsetRel = R_X86_64_DTPOFF64;
+  GotEntrySize = 8;
+  GotPltEntrySize = 8;
   PltEntrySize = 16;
   PltHeaderSize = 16;
   TlsGdRelaxSkip = 2;
@@ -976,6 +980,8 @@ RelExpr PPCTargetInfo::getRelExpr(uint32_t Type, const SymbolBody &S) const {
 PPC64TargetInfo::PPC64TargetInfo() {
   PltRel = GotRel = R_PPC64_GLOB_DAT;
   RelativeRel = R_PPC64_RELATIVE;
+  GotEntrySize = 8;
+  GotPltEntrySize = 8;
   PltEntrySize = 32;
   PltHeaderSize = 0;
 
@@ -1140,6 +1146,8 @@ AArch64TargetInfo::AArch64TargetInfo() {
   PltRel = R_AARCH64_JUMP_SLOT;
   TlsDescRel = R_AARCH64_TLSDESC;
   TlsGotRel = R_AARCH64_TLS_TPREL64;
+  GotEntrySize = 8;
+  GotPltEntrySize = 8;
   PltEntrySize = 16;
   PltHeaderSize = 32;
 
@@ -1480,6 +1488,8 @@ ARMTargetInfo::ARMTargetInfo() {
   TlsGotRel = R_ARM_TLS_TPOFF32;
   TlsModuleIndexRel = R_ARM_TLS_DTPMOD32;
   TlsOffsetRel = R_ARM_TLS_DTPOFF32;
+  GotEntrySize = 4;
+  GotPltEntrySize = 4;
   PltEntrySize = 16;
   PltHeaderSize = 20;
 }
@@ -1787,6 +1797,8 @@ uint64_t ARMTargetInfo::getImplicitAddend(const uint8_t *Buf,
 template <class ELFT> MipsTargetInfo<ELFT>::MipsTargetInfo() {
   GotPltHeaderEntriesNum = 2;
   PageSize = 65536;
+  GotEntrySize = sizeof(typename ELFT::uint);
+  GotPltEntrySize = sizeof(typename ELFT::uint);
   PltEntrySize = 16;
   PltHeaderSize = 32;
   CopyRel = R_MIPS_COPY;
index c1efb20..df4ceb1 100644 (file)
@@ -81,6 +81,8 @@ public:
   uint32_t TlsGotRel;
   uint32_t TlsModuleIndexRel;
   uint32_t TlsOffsetRel;
+  unsigned GotEntrySize;
+  unsigned GotPltEntrySize;
   unsigned PltEntrySize;
   unsigned PltHeaderSize;