<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 22, 2016 at 6:10 PM, Rui Ueyama via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ruiu<br>
Date: Fri Apr 22 20:10:15 2016<br>
New Revision: 267261<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=267261&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=267261&view=rev</a><br>
Log:<br>
Add a file comment about the Ulrich's document and don't repeat it in other comments.<br>
<br>
Modified:<br>
lld/trunk/ELF/Target.cpp<br>
<br>
Modified: lld/trunk/ELF/Target.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=267261&r1=267260&r2=267261&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=267261&r1=267260&r2=267261&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Target.cpp (original)<br>
+++ lld/trunk/ELF/Target.cpp Fri Apr 22 20:10:15 2016<br>
@@ -13,6 +13,15 @@<br>
// Refer the ELF spec for the single letter varaibles, S, A or P, used<br>
// in this file.<br>
//<br>
+// Some functions defined in this file has "relaxTls" as part of their names.<br>
+// They do peephole optimization for TLS variables by rewriting instructions.<br>
+// They are not part of the ABI but optional optimization, so you can skip<br>
+// them if you are not interested in how TLS variables are optimized.<br>
+// See the following paper for the details.<br>
+//<br>
+// Ulrich Drepper, ELF Handling For Thread-Local Storage<br>
+// <a href="http://www.akkadia.org/drepper/tls.pdf" rel="noreferrer" target="_blank">http://www.akkadia.org/drepper/tls.pdf</a><br>
+//<br>
//===----------------------------------------------------------------------===//<br>
<br>
#include "Target.h"<br>
@@ -430,15 +439,12 @@ void X86TargetInfo::relocateOne(uint8_t<br>
<br>
void X86TargetInfo::relaxTlsGdToLe(uint8_t *Loc, uint32_t Type,<br>
uint64_t Val) const {<br>
- // GD can be optimized to LE:<br>
+ // Convert<br>
// leal x@tlsgd(, %ebx, 1),<br>
// call __tls_get_addr@plt<br>
- // Can be converted to:<br>
+ // to<br>
// movl %gs:0,%eax<br>
- // addl $x@ntpoff,%eax<br>
- // But gold emits subl $foo@tpoff,%eax instead of addl.<br>
- // These instructions are completely equal in behavior.<br>
- // This method generates subl to be consistent with gold.<br>
+ // subl $x@ntpoff,%eax<br>
const uint8_t Inst[] = {<br>
0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, // movl %gs:0, %eax<br>
0x81, 0xe8, 0x00, 0x00, 0x00, 0x00 // subl 0(%ebx), %eax<br>
@@ -447,16 +453,14 @@ void X86TargetInfo::relaxTlsGdToLe(uint8<br>
relocateOne(Loc + 5, R_386_32, Out<ELF32LE>::TlsPhdr->p_memsz - Val);<br>
}<br>
<br>
-// "Ulrich Drepper, ELF Handling For Thread-Local Storage" (5.1<br>
-// IA-32 Linker Optimizations, <a href="http://www.akkadia.org/drepper/tls.pdf" rel="noreferrer" target="_blank">http://www.akkadia.org/drepper/tls.pdf</a>) shows<br>
-// how GD can be optimized to IE:<br>
-// leal x@tlsgd(, %ebx, 1),<br>
-// call __tls_get_addr@plt<br>
-// Is converted to:<br>
-// movl %gs:0, %eax<br>
-// addl x@gotntpoff(%ebx), %eax<br>
void X86TargetInfo::relaxTlsGdToIe(uint8_t *Loc, uint32_t Type,<br>
uint64_t Val) const {<br>
+ // Convert<br>
+ // leal x@tlsgd(, %ebx, 1),<br>
+ // call __tls_get_addr@plt<br>
+ // to<br>
+ // movl %gs:0, %eax<br>
+ // addl x@gotntpoff(%ebx), %eax<br>
const uint8_t Inst[] = {<br>
0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, // movl %gs:0, %eax<br>
0x03, 0x83, 0x00, 0x00, 0x00, 0x00 // addl 0(%ebx), %eax<br>
@@ -468,9 +472,6 @@ void X86TargetInfo::relaxTlsGdToIe(uint8<br>
<br>
// In some conditions, relocations can be optimized to avoid using GOT.<br>
// This function does that for Initial Exec to Local Exec case.<br>
-// Read "ELF Handling For Thread-Local Storage, 5.1<br>
-// IA-32 Linker Optimizations" (<a href="http://www.akkadia.org/drepper/tls.pdf" rel="noreferrer" target="_blank">http://www.akkadia.org/drepper/tls.pdf</a>)<br>
-// by Ulrich Drepper for details.<br>
void X86TargetInfo::relaxTlsIeToLe(uint8_t *Loc, uint32_t Type,<br>
uint64_t Val) const {<br>
// Ulrich's document section 6.2 says that @gotntpoff can<br>
@@ -516,10 +517,10 @@ void X86TargetInfo::relaxTlsLdToLe(uint8<br>
return;<br>
}<br>
<br>
- // LD can be optimized to LE:<br>
+ // Convert<br>
// leal foo(%reg),%eax<br>
// call ___tls_get_addr<br>
- // Is converted to:<br>
+ // to<br>
// movl %gs:0,%eax<br>
// nop<br>
// leal 0(%esi,1),%esi<br>
@@ -660,19 +661,17 @@ bool X86_64TargetInfo::isRelRelative(uin<br>
}<br>
}<br>
<br>
-// "Ulrich Drepper, ELF Handling For Thread-Local Storage" (5.5<br>
-// x86-x64 linker optimizations, <a href="http://www.akkadia.org/drepper/tls.pdf" rel="noreferrer" target="_blank">http://www.akkadia.org/drepper/tls.pdf</a>) shows<br>
-// how GD can be optimized to LE:<br>
-// .byte 0x66<br>
-// leaq x@tlsgd(%rip), %rdi<br>
-// .word 0x6666<br>
-// rex64<br>
-// call __tls_get_addr@plt<br>
-// Is converted to:<br>
-// mov %fs:0x0,%rax<br>
-// lea x@tpoff,%rax<br>
void X86_64TargetInfo::relaxTlsGdToLe(uint8_t *Loc, uint32_t Type,<br>
uint64_t Val) const {<br>
+ // Convert<br>
+ // .byte 0x66<br>
+ // leaq x@tlsgd(%rip), %rdi<br>
+ // .word 0x6666<br>
+ // rex64<br>
+ // call __tls_get_addr@plt<br>
+ // to<br>
+ // mov %fs:0x0,%rax<br>
+ // lea x@tpoff,%rax<br>
const uint8_t Inst[] = {<br>
0x64, 0x48, 0x8b, 0x04, 0x25, 0x00, 0x00, 0x00, 0x00, // mov %fs:0x0,%rax<br>
0x48, 0x8d, 0x80, 0x00, 0x00, 0x00, 0x00 // lea x@tpoff,%rax<br>
@@ -682,19 +681,17 @@ void X86_64TargetInfo::relaxTlsGdToLe(ui<br>
Val + 4 - Out<ELF64LE>::TlsPhdr->p_memsz);<br>
}<br>
<br>
-// "Ulrich Drepper, ELF Handling For Thread-Local Storage" (5.5<br>
-// x86-x64 linker optimizations, <a href="http://www.akkadia.org/drepper/tls.pdf" rel="noreferrer" target="_blank">http://www.akkadia.org/drepper/tls.pdf</a>) shows<br></blockquote><div><br></div><div>Can you keep the section references please?</div><div><br></div><div>-- Sean Silva</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
-// how GD can be optimized to IE:<br>
-// .byte 0x66<br>
-// leaq x@tlsgd(%rip), %rdi<br>
-// .word 0x6666<br>
-// rex64<br>
-// call __tls_get_addr@plt<br>
-// Is converted to:<br>
-// mov %fs:0x0,%rax<br>
-// addq x@tpoff,%rax<br>
void X86_64TargetInfo::relaxTlsGdToIe(uint8_t *Loc, uint32_t Type,<br>
uint64_t Val) const {<br>
+ // Convert<br>
+ // .byte 0x66<br>
+ // leaq x@tlsgd(%rip), %rdi<br>
+ // .word 0x6666<br>
+ // rex64<br>
+ // call __tls_get_addr@plt<br>
+ // to<br>
+ // mov %fs:0x0,%rax<br>
+ // addq x@tpoff,%rax<br>
const uint8_t Inst[] = {<br>
0x64, 0x48, 0x8b, 0x04, 0x25, 0x00, 0x00, 0x00, 0x00, // mov %fs:0x0,%rax<br>
0x48, 0x03, 0x05, 0x00, 0x00, 0x00, 0x00 // addq x@tpoff,%rax<br>
@@ -705,9 +702,6 @@ void X86_64TargetInfo::relaxTlsGdToIe(ui<br>
<br>
// In some conditions, R_X86_64_GOTTPOFF relocation can be optimized to<br>
// R_X86_64_TPOFF32 so that it does not use GOT.<br>
-// This function does that. Read "ELF Handling For Thread-Local Storage,<br>
-// 5.5 x86-x64 linker optimizations" (<a href="http://www.akkadia.org/drepper/tls.pdf" rel="noreferrer" target="_blank">http://www.akkadia.org/drepper/tls.pdf</a>)<br>
-// by Ulrich Drepper for details.<br>
void X86_64TargetInfo::relaxTlsIeToLe(uint8_t *Loc, uint32_t Type,<br>
uint64_t Val) const {<br>
// Ulrich's document section 6.5 says that @gottpoff(%rip) must be<br>
@@ -722,6 +716,7 @@ void X86_64TargetInfo::relaxTlsIeToLe(ui<br>
uint8_t Reg = Loc[-1] >> 3;<br>
bool IsMov = *Inst == 0x8b;<br>
bool RspAdd = !IsMov && Reg == 4;<br>
+<br>
// r12 and rsp registers requires special handling.<br>
// Problem is that for other registers, for example leaq 0xXXXXXXXX(%r11),%r11<br>
// result out is 7 bytes: 4d 8d 9b XX XX XX XX,<br>
@@ -738,19 +733,17 @@ void X86_64TargetInfo::relaxTlsIeToLe(ui<br>
relocateOne(Loc, R_X86_64_TPOFF32, Val + 4 - Out<ELF64LE>::TlsPhdr->p_memsz);<br>
}<br>
<br>
-// "Ulrich Drepper, ELF Handling For Thread-Local Storage" (5.5<br>
-// x86-x64 linker optimizations, <a href="http://www.akkadia.org/drepper/tls.pdf" rel="noreferrer" target="_blank">http://www.akkadia.org/drepper/tls.pdf</a>) shows<br>
-// how LD can be optimized to LE:<br>
-// leaq bar@tlsld(%rip), %rdi<br>
-// callq __tls_get_addr@PLT<br>
-// leaq bar@dtpoff(%rax), %rcx<br>
-// Is converted to:<br>
-// .word 0x6666<br>
-// .byte 0x66<br>
-// mov %fs:0,%rax<br>
-// leaq bar@tpoff(%rax), %rcx<br>
void X86_64TargetInfo::relaxTlsLdToLe(uint8_t *Loc, uint32_t Type,<br>
uint64_t Val) const {<br>
+ // Convert<br>
+ // leaq bar@tlsld(%rip), %rdi<br>
+ // callq __tls_get_addr@PLT<br>
+ // leaq bar@dtpoff(%rax), %rcx<br>
+ // to<br>
+ // .word 0x6666<br>
+ // .byte 0x66<br>
+ // mov %fs:0,%rax<br>
+ // leaq bar@tpoff(%rax), %rcx<br>
if (Type == R_X86_64_DTPOFF64) {<br>
write64le(Loc, Val - Out<ELF64LE>::TlsPhdr->p_memsz);<br>
return;<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>