svn commit: r343315 - in projects/clang800-import/contrib/llvm/tools/lld: ELF ELF/Arch docs

Dimitry Andric dim at FreeBSD.org
Tue Jan 22 20:16:00 UTC 2019


Author: dim
Date: Tue Jan 22 20:15:58 2019
New Revision: 343315
URL: https://svnweb.freebsd.org/changeset/base/343315

Log:
  Merge lld release_80 branch r351543, and resolve conflicts.

Modified:
  projects/clang800-import/contrib/llvm/tools/lld/ELF/Arch/X86_64.cpp
  projects/clang800-import/contrib/llvm/tools/lld/ELF/Config.h
  projects/clang800-import/contrib/llvm/tools/lld/ELF/Driver.cpp
  projects/clang800-import/contrib/llvm/tools/lld/ELF/Options.td
  projects/clang800-import/contrib/llvm/tools/lld/ELF/Relocations.cpp
  projects/clang800-import/contrib/llvm/tools/lld/ELF/Thunks.cpp
  projects/clang800-import/contrib/llvm/tools/lld/docs/ld.lld.1
Directory Properties:
  projects/clang800-import/contrib/llvm/tools/lld/   (props changed)

Modified: projects/clang800-import/contrib/llvm/tools/lld/ELF/Arch/X86_64.cpp
==============================================================================
--- projects/clang800-import/contrib/llvm/tools/lld/ELF/Arch/X86_64.cpp	Tue Jan 22 20:15:01 2019	(r343314)
+++ projects/clang800-import/contrib/llvm/tools/lld/ELF/Arch/X86_64.cpp	Tue Jan 22 20:15:58 2019	(r343315)
@@ -264,15 +264,6 @@ void X86_64<ELFT>::relaxTlsIeToLe(uint8_t *Loc, RelTyp
 template <class ELFT>
 void X86_64<ELFT>::relaxTlsLdToLe(uint8_t *Loc, RelType Type,
                                   uint64_t Val) const {
-  // Convert
-  //   leaq bar at tlsld(%rip), %rdi
-  //   callq __tls_get_addr at PLT
-  //   leaq bar at dtpoff(%rax), %rcx
-  // to
-  //   .word 0x6666
-  //   .byte 0x66
-  //   mov %fs:0,%rax
-  //   leaq bar at tpoff(%rax), %rcx
   if (Type == R_X86_64_DTPOFF64) {
     write64le(Loc, Val);
     return;
@@ -287,7 +278,37 @@ void X86_64<ELFT>::relaxTlsLdToLe(uint8_t *Loc, RelTyp
       0x66,                                                 // .byte 0x66
       0x64, 0x48, 0x8b, 0x04, 0x25, 0x00, 0x00, 0x00, 0x00, // mov %fs:0,%rax
   };
-  memcpy(Loc - 3, Inst, sizeof(Inst));
+
+  if (Loc[4] == 0xe8) {
+    // Convert
+    //   leaq bar at tlsld(%rip), %rdi           # 48 8d 3d <Loc>
+    //   callq __tls_get_addr at PLT             # e8 <disp32>
+    //   leaq bar at dtpoff(%rax), %rcx
+    // to
+    //   .word 0x6666
+    //   .byte 0x66
+    //   mov %fs:0,%rax
+    //   leaq bar at tpoff(%rax), %rcx
+    memcpy(Loc - 3, Inst, sizeof(Inst));
+    return;
+  }
+
+  if (Loc[4] == 0xff && Loc[5] == 0x15) {
+    // Convert
+    //   leaq  x at tlsld(%rip),%rdi               # 48 8d 3d <Loc>
+    //   call *__tls_get_addr at GOTPCREL(%rip)    # ff 15 <disp32>
+    // to
+    //   .long  0x66666666
+    //   movq   %fs:0,%rax
+    // See "Table 11.9: LD -> LE Code Transition (LP64)" in
+    // https://raw.githubusercontent.com/wiki/hjl-tools/x86-psABI/x86-64-psABI-1.0.pdf
+    Loc[-3] = 0x66;
+    memcpy(Loc - 2, Inst, sizeof(Inst));
+    return;
+  }
+
+  error(getErrorLocation(Loc - 3) +
+        "expected R_X86_64_PLT32 or R_X86_64_GOTPCRELX after R_X86_64_TLSLD");
 }
 
 template <class ELFT>

Modified: projects/clang800-import/contrib/llvm/tools/lld/ELF/Config.h
==============================================================================
--- projects/clang800-import/contrib/llvm/tools/lld/ELF/Config.h	Tue Jan 22 20:15:01 2019	(r343314)
+++ projects/clang800-import/contrib/llvm/tools/lld/ELF/Config.h	Tue Jan 22 20:15:58 2019	(r343315)
@@ -159,6 +159,7 @@ struct Configuration {
   bool OFormatBinary;
   bool Omagic;
   bool OptRemarksWithHotness;
+  bool PicThunk;
   bool Pie;
   bool PrintGcSections;
   bool PrintIcfSections;

Modified: projects/clang800-import/contrib/llvm/tools/lld/ELF/Driver.cpp
==============================================================================
--- projects/clang800-import/contrib/llvm/tools/lld/ELF/Driver.cpp	Tue Jan 22 20:15:01 2019	(r343314)
+++ projects/clang800-import/contrib/llvm/tools/lld/ELF/Driver.cpp	Tue Jan 22 20:15:58 2019	(r343315)
@@ -1008,6 +1008,7 @@ static void setConfigs(opt::InputArgList &Args) {
   Config->Endianness = Config->IsLE ? endianness::little : endianness::big;
   Config->IsMips64EL = (K == ELF64LEKind && M == EM_MIPS);
   Config->Pic = Config->Pie || Config->Shared;
+  Config->PicThunk = Args.hasArg(OPT_pic_veneer, Config->Pic);
   Config->Wordsize = Config->Is64 ? 8 : 4;
 
   // ELF defines two different ways to store relocation addends as shown below:

Modified: projects/clang800-import/contrib/llvm/tools/lld/ELF/Options.td
==============================================================================
--- projects/clang800-import/contrib/llvm/tools/lld/ELF/Options.td	Tue Jan 22 20:15:01 2019	(r343314)
+++ projects/clang800-import/contrib/llvm/tools/lld/ELF/Options.td	Tue Jan 22 20:15:58 2019	(r343315)
@@ -255,6 +255,9 @@ defm use_android_relr_tags: B<"use-android-relr-tags",
     "Use SHT_ANDROID_RELR / DT_ANDROID_RELR* tags instead of SHT_RELR / DT_RELR*",
     "Use SHT_RELR / DT_RELR* tags (default)">;
 
+def pic_veneer: F<"pic-veneer">,
+  HelpText<"Always generate position independent thunks (veneers)">;
+
 defm pie: B<"pie",
     "Create a position independent executable",
     "Do not create a position independent executable (default)">;

Modified: projects/clang800-import/contrib/llvm/tools/lld/ELF/Relocations.cpp
==============================================================================
--- projects/clang800-import/contrib/llvm/tools/lld/ELF/Relocations.cpp	Tue Jan 22 20:15:01 2019	(r343314)
+++ projects/clang800-import/contrib/llvm/tools/lld/ELF/Relocations.cpp	Tue Jan 22 20:15:58 2019	(r343315)
@@ -356,7 +356,7 @@ static bool needsGot(RelExpr Expr) {
 static bool isRelExpr(RelExpr Expr) {
   return isRelExprOneOf<R_PC, R_GOTREL, R_GOTREL_FROM_END, R_MIPS_GOTREL,
                         R_PPC_CALL, R_PPC_CALL_PLT, R_AARCH64_PAGE_PC,
-                        R_RELAX_GOT_PC>(Expr);
+                        R_AARCH64_PLT_PAGE_PC, R_RELAX_GOT_PC>(Expr);
 }
 
 // Returns true if a given relocation can be computed at link-time.

Modified: projects/clang800-import/contrib/llvm/tools/lld/ELF/Thunks.cpp
==============================================================================
--- projects/clang800-import/contrib/llvm/tools/lld/ELF/Thunks.cpp	Tue Jan 22 20:15:01 2019	(r343314)
+++ projects/clang800-import/contrib/llvm/tools/lld/ELF/Thunks.cpp	Tue Jan 22 20:15:58 2019	(r343315)
@@ -722,7 +722,7 @@ Thunk::~Thunk() = default;
 static Thunk *addThunkAArch64(RelType Type, Symbol &S) {
   if (Type != R_AARCH64_CALL26 && Type != R_AARCH64_JUMP26)
     fatal("unrecognized relocation type");
-  if (Config->Pic)
+  if (Config->PicThunk)
     return make<AArch64ADRPThunk>(S);
   return make<AArch64ABSLongThunk>(S);
 }
@@ -739,7 +739,7 @@ static Thunk *addThunkPreArmv7(RelType Reloc, Symbol &
   case R_ARM_JUMP24:
   case R_ARM_CALL:
   case R_ARM_THM_CALL:
-    if (Config->Pic)
+    if (Config->PicThunk)
       return make<ARMV5PILongThunk>(S);
     return make<ARMV5ABSLongThunk>(S);
   }
@@ -794,13 +794,13 @@ static Thunk *addThunkArm(RelType Reloc, Symbol &S) {
   case R_ARM_PLT32:
   case R_ARM_JUMP24:
   case R_ARM_CALL:
-    if (Config->Pic)
+    if (Config->PicThunk)
       return make<ARMV7PILongThunk>(S);
     return make<ARMV7ABSLongThunk>(S);
   case R_ARM_THM_JUMP19:
   case R_ARM_THM_JUMP24:
   case R_ARM_THM_CALL:
-    if (Config->Pic)
+    if (Config->PicThunk)
       return make<ThumbV7PILongThunk>(S);
     return make<ThumbV7ABSLongThunk>(S);
   }
@@ -820,7 +820,7 @@ static Thunk *addThunkPPC64(RelType Type, Symbol &S) {
   if (S.isInPlt())
     return make<PPC64PltCallStub>(S);
 
-  if (Config->Pic)
+  if (Config->PicThunk)
     return make<PPC64PILongBranchThunk>(S);
 
   return make<PPC64PDLongBranchThunk>(S);

Modified: projects/clang800-import/contrib/llvm/tools/lld/docs/ld.lld.1
==============================================================================
--- projects/clang800-import/contrib/llvm/tools/lld/docs/ld.lld.1	Tue Jan 22 20:15:01 2019	(r343314)
+++ projects/clang800-import/contrib/llvm/tools/lld/docs/ld.lld.1	Tue Jan 22 20:15:58 2019	(r343315)
@@ -322,6 +322,8 @@ Write optimization remarks in YAML format to
 .Ar file .
 .It Fl -opt-remarks-with-hotness
 Include hotness information in the optimization remarks file.
+.It Fl -pic-veneer
+Always generate position independent thunks.
 .It Fl -pie
 Create a position independent executable.
 .It Fl -print-gc-sections


More information about the svn-src-projects mailing list