Skip to content

Commit

Permalink
[ELF][X86] Fix R_RELAX_TLS_GD_TO_LE_NEG and R_NEG_TLS after D62059
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MaskRay authored and MrSidims committed May 24, 2019
1 parent 806fb44 commit d6a4952
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lld/ELF/InputSection.cpp
Expand Up @@ -752,7 +752,7 @@ static uint64_t getRelocTargetVA(const InputFile *File, RelType Type, int64_t A,
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:
Expand Down
17 changes: 15 additions & 2 deletions lld/test/ELF/i386-tls-le-align.s
Expand Up @@ -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:
Expand Down

0 comments on commit d6a4952

Please sign in to comment.