Commit 658a338f authored by Michael Hudson-Doyle's avatar Michael Hudson-Doyle Committed by Ian Lance Taylor

cmd/internal/ld, runtime: halve tlsoffset on ELF/intel

For OSes that use elf on intel, 2*Ptrsize bytes are reserved for TLS.
But only one pointer (g) has been stored in the TLS for a while now.
So we can set it to just Ptrsize, which happily matches what happens
when externally linking.

Fixes #9913

Change-Id: Ic816369d3a55a8cdcc23be349b1a1791d53f5f81
Reviewed-on: https://go-review.googlesource.com/6584
Run-TryBot: Minux Ma <minux@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 5e49bfec
...@@ -107,7 +107,7 @@ func linknew(arch *LinkArch) *Link { ...@@ -107,7 +107,7 @@ func linknew(arch *LinkArch) *Link {
Hopenbsd, Hopenbsd,
Hdragonfly, Hdragonfly,
Hsolaris: Hsolaris:
ctxt.Tlsoffset = -2 * ctxt.Arch.Ptrsize ctxt.Tlsoffset = -1 * ctxt.Arch.Ptrsize
case Hnacl: case Hnacl:
switch ctxt.Arch.Thechar { switch ctxt.Arch.Thechar {
......
...@@ -170,7 +170,7 @@ func Linknew(arch *LinkArch) *Link { ...@@ -170,7 +170,7 @@ func Linknew(arch *LinkArch) *Link {
Hopenbsd, Hopenbsd,
Hdragonfly, Hdragonfly,
Hsolaris: Hsolaris:
ctxt.Tlsoffset = -2 * ctxt.Arch.Ptrsize ctxt.Tlsoffset = -1 * ctxt.Arch.Ptrsize
case Hnacl: case Hnacl:
switch ctxt.Arch.Thechar { switch ctxt.Arch.Thechar {
......
...@@ -295,9 +295,9 @@ TEXT runtime·setldt(SB),NOSPLIT,$4 ...@@ -295,9 +295,9 @@ TEXT runtime·setldt(SB),NOSPLIT,$4
RET RET
TEXT runtime·settls(SB),NOSPLIT,$24 TEXT runtime·settls(SB),NOSPLIT,$24
// adjust for ELF: wants to use -8(GS) and -4(GS) for g and m // adjust for ELF: wants to use -4(GS) for g
MOVL tlsbase+0(FP), CX MOVL tlsbase+0(FP), CX
ADDL $8, CX ADDL $4, CX
// Set up a struct tls_info - a size of -1 maps the whole address // Set up a struct tls_info - a size of -1 maps the whole address
// space and is required for direct-tls access of variable data // space and is required for direct-tls access of variable data
......
...@@ -272,7 +272,7 @@ TEXT runtime·usleep(SB),NOSPLIT,$16 ...@@ -272,7 +272,7 @@ TEXT runtime·usleep(SB),NOSPLIT,$16
// set tls base to DI // set tls base to DI
TEXT runtime·settls(SB),NOSPLIT,$16 TEXT runtime·settls(SB),NOSPLIT,$16
ADDQ $16, DI // adjust for ELF: wants to use -16(FS) and -8(FS) for g and m ADDQ $8, DI // adjust for ELF: wants to use -8(FS) for g
MOVQ DI, 0(SP) MOVQ DI, 0(SP)
MOVQ $16, 8(SP) MOVQ $16, 8(SP)
MOVQ $0, DI // arg 1 - which MOVQ $0, DI // arg 1 - which
......
...@@ -287,7 +287,7 @@ int i386_set_ldt(int, const union ldt_entry *, int); ...@@ -287,7 +287,7 @@ int i386_set_ldt(int, const union ldt_entry *, int);
TEXT runtime·setldt(SB),NOSPLIT,$32 TEXT runtime·setldt(SB),NOSPLIT,$32
MOVL address+4(FP), BX // aka base MOVL address+4(FP), BX // aka base
// see comment in sys_linux_386.s; freebsd is similar // see comment in sys_linux_386.s; freebsd is similar
ADDL $0x8, BX ADDL $0x4, BX
// set up data_desc // set up data_desc
LEAL 16(SP), AX // struct data_desc LEAL 16(SP), AX // struct data_desc
......
...@@ -262,7 +262,7 @@ TEXT runtime·usleep(SB),NOSPLIT,$16 ...@@ -262,7 +262,7 @@ TEXT runtime·usleep(SB),NOSPLIT,$16
// set tls base to DI // set tls base to DI
TEXT runtime·settls(SB),NOSPLIT,$8 TEXT runtime·settls(SB),NOSPLIT,$8
ADDQ $16, DI // adjust for ELF: wants to use -16(FS) and -8(FS) for g and m ADDQ $8, DI // adjust for ELF: wants to use -8(FS) for g and m
MOVQ DI, 0(SP) MOVQ DI, 0(SP)
MOVQ SP, SI MOVQ SP, SI
MOVQ $129, DI // AMD64_SET_FSBASE MOVQ $129, DI // AMD64_SET_FSBASE
......
...@@ -410,16 +410,16 @@ TEXT runtime·setldt(SB),NOSPLIT,$32 ...@@ -410,16 +410,16 @@ TEXT runtime·setldt(SB),NOSPLIT,$32
* When linking against the system libraries, * When linking against the system libraries,
* we use its pthread_create and let it set up %gs * we use its pthread_create and let it set up %gs
* for us. When we do that, the private storage * for us. When we do that, the private storage
* we get is not at 0(GS), 4(GS), but -8(GS), -4(GS). * we get is not at 0(GS), but -4(GS).
* To insulate the rest of the tool chain from this * To insulate the rest of the tool chain from this
* ugliness, 8l rewrites 0(TLS) into -8(GS) for us. * ugliness, 8l rewrites 0(TLS) into -4(GS) for us.
* To accommodate that rewrite, we translate * To accommodate that rewrite, we translate
* the address here and bump the limit to 0xffffffff (no limit) * the address here and bump the limit to 0xffffffff (no limit)
* so that -8(GS) maps to 0(address). * so that -4(GS) maps to 0(address).
* Also, the final 0(GS) (current 8(CX)) has to point * Also, the final 0(GS) (current 4(CX)) has to point
* to itself, to mimic ELF. * to itself, to mimic ELF.
*/ */
ADDL $0x8, CX // address ADDL $0x4, CX // address
MOVL CX, 0(CX) MOVL CX, 0(CX)
// set up user_desc // set up user_desc
......
...@@ -359,7 +359,7 @@ TEXT runtime·sigaltstack(SB),NOSPLIT,$-8 ...@@ -359,7 +359,7 @@ TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
// set tls base to DI // set tls base to DI
TEXT runtime·settls(SB),NOSPLIT,$32 TEXT runtime·settls(SB),NOSPLIT,$32
ADDQ $16, DI // ELF wants to use -16(FS), -8(FS) ADDQ $8, DI // ELF wants to use -8(FS)
MOVQ DI, SI MOVQ DI, SI
MOVQ $0x1002, DI // ARCH_SET_FS MOVQ $0x1002, DI // ARCH_SET_FS
......
...@@ -307,9 +307,9 @@ TEXT runtime·setldt(SB),NOSPLIT,$8 ...@@ -307,9 +307,9 @@ TEXT runtime·setldt(SB),NOSPLIT,$8
RET RET
TEXT runtime·settls(SB),NOSPLIT,$16 TEXT runtime·settls(SB),NOSPLIT,$16
// adjust for ELF: wants to use -8(GS) and -4(GS) for g and m // adjust for ELF: wants to use -4(GS) for g
MOVL base+0(FP), CX MOVL base+0(FP), CX
ADDL $8, CX ADDL $4, CX
MOVL $0, 0(SP) // syscall gap MOVL $0, 0(SP) // syscall gap
MOVL CX, 4(SP) // arg 1 - ptr MOVL CX, 4(SP) // arg 1 - ptr
MOVL $317, AX // sys__lwp_setprivate MOVL $317, AX // sys__lwp_setprivate
......
...@@ -307,8 +307,8 @@ TEXT runtime·sigaltstack(SB),NOSPLIT,$-8 ...@@ -307,8 +307,8 @@ TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
// set tls base to DI // set tls base to DI
TEXT runtime·settls(SB),NOSPLIT,$8 TEXT runtime·settls(SB),NOSPLIT,$8
// adjust for ELF: wants to use -16(FS) and -8(FS) for g and m // adjust for ELF: wants to use -8(FS) for g
ADDQ $16, DI // arg 1 - ptr ADDQ $8, DI // arg 1 - ptr
MOVQ $317, AX // sys__lwp_setprivate MOVQ $317, AX // sys__lwp_setprivate
SYSCALL SYSCALL
JCC 2(PC) JCC 2(PC)
......
...@@ -325,9 +325,9 @@ TEXT runtime·setldt(SB),NOSPLIT,$4 ...@@ -325,9 +325,9 @@ TEXT runtime·setldt(SB),NOSPLIT,$4
RET RET
TEXT runtime·settls(SB),NOSPLIT,$8 TEXT runtime·settls(SB),NOSPLIT,$8
// adjust for ELF: wants to use -8(GS) and -4(GS) for g and m // adjust for ELF: wants to use -4(GS) for g
MOVL tlsbase+0(FP), CX MOVL tlsbase+0(FP), CX
ADDL $8, CX ADDL $4, CX
MOVL $0, 0(SP) // syscall gap MOVL $0, 0(SP) // syscall gap
MOVL CX, 4(SP) // arg 1 - tcb MOVL CX, 4(SP) // arg 1 - tcb
MOVL $329, AX // sys___set_tcb MOVL $329, AX // sys___set_tcb
......
...@@ -298,7 +298,7 @@ TEXT runtime·sigaltstack(SB),NOSPLIT,$-8 ...@@ -298,7 +298,7 @@ TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
// set tls base to DI // set tls base to DI
TEXT runtime·settls(SB),NOSPLIT,$0 TEXT runtime·settls(SB),NOSPLIT,$0
// adjust for ELF: wants to use -16(FS) and -8(FS) for g and m // adjust for ELF: wants to use -16(FS) and -8(FS) for g and m
ADDQ $16, DI ADDQ $8, DI
MOVQ $329, AX // sys___settcb MOVQ $329, AX // sys___settcb
SYSCALL SYSCALL
JCC 2(PC) JCC 2(PC)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment