[lld] r273246 - Refactor X86TargetInfo::relaxTlsIeToLe.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 20 22:44:14 PDT 2016


Author: ruiu
Date: Tue Jun 21 00:44:14 2016
New Revision: 273246

URL: http://llvm.org/viewvc/llvm-project?rev=273246&view=rev
Log:
Refactor X86TargetInfo::relaxTlsIeToLe.

`Inst` and `Op` variables are removed since they are not always
point to an instruction nor an operand. For 5-byte MOV instruction,
Op points to an instruction, which is confusing.

Modified:
    lld/trunk/ELF/Target.cpp

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=273246&r1=273245&r2=273246&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Tue Jun 21 00:44:14 2016
@@ -475,34 +475,34 @@ void X86TargetInfo::relaxTlsIeToLe(uint8
   // be used with MOVL or ADDL instructions.
   // @indntpoff is similar to @gotntpoff, but for use in
   // position dependent code.
-  uint8_t *Inst = Loc - 2;
-  uint8_t *Op = Loc - 1;
   uint8_t Reg = (Loc[-1] >> 3) & 7;
-  bool IsMov = *Inst == 0x8b;
+
   if (Type == R_386_TLS_IE) {
-    // For R_386_TLS_IE relocation we perform the next transformations:
-    // MOVL foo at INDNTPOFF,%EAX is transformed to MOVL $foo,%EAX
-    // MOVL foo at INDNTPOFF,%REG is transformed to MOVL $foo,%REG
-    // ADDL foo at INDNTPOFF,%REG is transformed to ADDL $foo,%REG
-    // First one is special because when EAX is used the sequence is 5 bytes
-    // long, otherwise it is 6 bytes.
-    if (*Op == 0xa1) {
-      *Op = 0xb8;
+    if (Loc[-1] == 0xa1) {
+      // "movl foo at indntpoff,%eax" -> "movl $foo,%eax"
+      // This case is different from the generic case below because
+      // this is a 5 byte instruction while below is 6 bytes.
+      Loc[-1] = 0xb8;
+    } else if (Loc[-2] == 0x8b) {
+      // "movl foo at indntpoff,%reg" -> "movl $foo,%reg"
+      Loc[-2] = 0xc7;
+      Loc[-1] = 0xc0 | Reg;
     } else {
-      *Inst = IsMov ? 0xc7 : 0x81;
-      *Op = 0xc0 | ((*Op >> 3) & 7);
+      // "addl foo at indntpoff,%reg" -> "addl $foo,%reg"
+      Loc[-2] = 0x81;
+      Loc[-1] = 0xc0 | Reg;
     }
   } else {
-    // R_386_TLS_GOTIE relocation can be optimized to
-    // R_386_TLS_LE so that it does not use GOT.
-    // "MOVL foo at GOTTPOFF(%RIP), %REG" is transformed to "MOVL $foo, %REG".
-    // "ADDL foo at GOTNTPOFF(%RIP), %REG" is transformed to "LEAL foo(%REG), %REG"
-    // Note: gold converts to ADDL instead of LEAL.
-    *Inst = IsMov ? 0xc7 : 0x8d;
-    if (IsMov)
-      *Op = 0xc0 | ((*Op >> 3) & 7);
-    else
-      *Op = 0x80 | Reg | (Reg << 3);
+    assert(Type == R_386_TLS_GOTIE);
+    if (Loc[-2] == 0x8b) {
+      // "movl foo at gottpoff(%rip),%reg" -> "movl $foo,%reg"
+      Loc[-2] = 0xc7;
+      Loc[-1] = 0xc0 | Reg;
+    } else {
+      // "addl foo at gotntpoff(%rip),%reg" -> "leal foo(%reg),%reg"
+      Loc[-2] = 0x8d;
+      Loc[-1] = 0x80 | (Reg << 3) | Reg;
+    }
   }
   relocateOne(Loc, R_386_TLS_LE, Val);
 }




More information about the llvm-commits mailing list