[lld] r275301 - Add GotEntrySize/GotPltEntrySize to ELF target.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 13 11:55:14 PDT 2016


Author: ruiu
Date: Wed Jul 13 13:55:14 2016
New Revision: 275301

URL: http://llvm.org/viewvc/llvm-project?rev=275301&view=rev
Log:
Add GotEntrySize/GotPltEntrySize to ELF target.

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

Modified:
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/ELF/Target.cpp
    lld/trunk/ELF/Target.h

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=275301&r1=275300&r2=275301&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Wed Jul 13 13:55:14 2016
@@ -47,7 +47,7 @@ void OutputSectionBase<ELFT>::writeHeade
 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
 }
 
 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>

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=275301&r1=275300&r2=275301&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Wed Jul 13 13:55:14 2016
@@ -165,7 +165,7 @@ template <class ELFT> typename ELFT::uin
 }
 
 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::uin
 }
 
 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 {

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=275301&r1=275300&r2=275301&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Wed Jul 13 13:55:14 2016
@@ -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<E
   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
 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::getImplicitAdden
 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;

Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=275301&r1=275300&r2=275301&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Wed Jul 13 13:55:14 2016
@@ -81,6 +81,8 @@ public:
   uint32_t TlsGotRel;
   uint32_t TlsModuleIndexRel;
   uint32_t TlsOffsetRel;
+  unsigned GotEntrySize;
+  unsigned GotPltEntrySize;
   unsigned PltEntrySize;
   unsigned PltHeaderSize;
 




More information about the llvm-commits mailing list