[ELF][X86] Fix R_RELAX_TLS_GD_TO_LE_NEG and R_NEG_TLS after D62059

After D62059, we don't align p_memsz of PT_TLS to p_align. The
getRelocTargetVA formula should align it instead.

It becomes clear that R_NEG_TLS and R_TLS are opposite from each other.

In i386-tls-le-align.s, I put ret after call ___tls_get_addr@plt as
otherwise ld.bfd would reject the relaxation:
TLS transition from R_386_TLS_GD to R_386_TLS_LE_32 against `a' at 0x3 in section `.text' failed

llvm-svn: 361088
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 72a2c29..1fcc3db 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -752,7 +752,7 @@
     return Sym.getVA(A) + getTlsTpOffset();
   case R_RELAX_TLS_GD_TO_LE_NEG:
   case R_NEG_TLS:
-    return Out::TlsPhdr->p_memsz - Sym.getVA(A);
+    return -(Sym.getVA(A) + getTlsTpOffset());
   case R_SIZE:
     return Sym.getSize() + A;
   case R_TLSDESC:
diff --git a/lld/test/ELF/i386-tls-le-align.s b/lld/test/ELF/i386-tls-le-align.s
index 3faa3b2..20ee1ec 100644
--- a/lld/test/ELF/i386-tls-le-align.s
+++ b/lld/test/ELF/i386-tls-le-align.s
@@ -5,10 +5,23 @@
 
 # -alignTo(p_memsz, p_align) = -alignTo(4, 64) = -64
 
-# CHECK: movl %gs:0xffffffc0, %eax
-
+# CHECK:      movl %gs:0xffffffc0, %eax
   movl %gs:a@NTPOFF, %eax
 
+# CHECK-NEXT: subl $0x40, %edx
+  subl $a@tpoff, %edx
+
+# GD to LE relaxation.
+# CHECK-NEXT: movl %gs:0x0, %eax
+# CHECK-NEXT: subl $0x40, %eax
+  leal a@tlsgd(,%ebx,1), %eax
+  call ___tls_get_addr@plt
+  ret
+
+.globl ___tls_get_addr
+.type ___tls_get_addr,@function
+___tls_get_addr:
+
 .section .tbss,"awT"
 .align 64
 a: