]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/ld, runtime: halve tlsoffset on ELF/intel
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Wed, 4 Mar 2015 03:28:45 +0000 (16:28 +1300)
committerIan Lance Taylor <iant@golang.org>
Thu, 5 Mar 2015 01:23:29 +0000 (01:23 +0000)
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: Ian Lance Taylor <iant@golang.org>
12 files changed:
src/cmd/internal/ld/sym.go
src/cmd/internal/obj/sym.go
src/runtime/sys_dragonfly_386.s
src/runtime/sys_dragonfly_amd64.s
src/runtime/sys_freebsd_386.s
src/runtime/sys_freebsd_amd64.s
src/runtime/sys_linux_386.s
src/runtime/sys_linux_amd64.s
src/runtime/sys_netbsd_386.s
src/runtime/sys_netbsd_amd64.s
src/runtime/sys_openbsd_386.s
src/runtime/sys_openbsd_amd64.s

index cbaa364a89936fdac65467bbea96a9ae1ae3f41b..fd02ed0285463956483b344ecae6e5bfcd4cde4e 100644 (file)
@@ -107,7 +107,7 @@ func linknew(arch *LinkArch) *Link {
                Hopenbsd,
                Hdragonfly,
                Hsolaris:
-               ctxt.Tlsoffset = -2 * ctxt.Arch.Ptrsize
+               ctxt.Tlsoffset = -1 * ctxt.Arch.Ptrsize
 
        case Hnacl:
                switch ctxt.Arch.Thechar {
index 80ef0bf64cbb89f7be6c741a65bab5619ca3831a..7dafb2de04214a1d596fff9567e0b1d852c2b071 100644 (file)
@@ -170,7 +170,7 @@ func Linknew(arch *LinkArch) *Link {
                Hopenbsd,
                Hdragonfly,
                Hsolaris:
-               ctxt.Tlsoffset = -2 * ctxt.Arch.Ptrsize
+               ctxt.Tlsoffset = -1 * ctxt.Arch.Ptrsize
 
        case Hnacl:
                switch ctxt.Arch.Thechar {
index fa215daf261cdca0fbdd50096a34d3df9092f37f..afb2ec1f5bac1eec2a9a5f81e6b4d0181a913b11 100644 (file)
@@ -295,9 +295,9 @@ TEXT runtime·setldt(SB),NOSPLIT,$4
        RET
 
 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
-       ADDL    $8, CX
+       ADDL    $4, CX
 
        // 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
index 9b4e057b62f4255077a60c0cbd6c224f9631941a..1227196cb7e01071274be9d0ee8b09de07b5addd 100644 (file)
@@ -272,7 +272,7 @@ TEXT runtime·usleep(SB),NOSPLIT,$16
 
 // set tls base to DI
 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    $16, 8(SP)
        MOVQ    $0, DI                  // arg 1 - which
index bd2cc9438f09ee955538bd8797097c8d67b95e56..eed6b8d691c15e186e6230e25412e9fb322c9fea 100644 (file)
@@ -287,7 +287,7 @@ int i386_set_ldt(int, const union ldt_entry *, int);
 TEXT runtime·setldt(SB),NOSPLIT,$32
        MOVL    address+4(FP), BX       // aka base
        // see comment in sys_linux_386.s; freebsd is similar
-       ADDL    $0x8, BX
+       ADDL    $0x4, BX
 
        // set up data_desc
        LEAL    16(SP), AX      // struct data_desc
index f2001f2560c04261679ccf4b8d763812ec571e7c..ecc40e3946f6edfd60588e251a1f6348671c464b 100644 (file)
@@ -262,7 +262,7 @@ TEXT runtime·usleep(SB),NOSPLIT,$16
 
 // set tls base to DI
 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    SP, SI
        MOVQ    $129, DI        // AMD64_SET_FSBASE
index 7d53aad59a8d93ef94e3673c3399ef7bdcfdaa4c..d4bd142134eaf7a8bb60195af82064339a3d2f6a 100644 (file)
@@ -410,16 +410,16 @@ TEXT runtime·setldt(SB),NOSPLIT,$32
         * When linking against the system libraries,
         * we use its pthread_create and let it set up %gs
         * 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
-        * 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
         * the address here and bump the limit to 0xffffffff (no limit)
-        * so that -8(GS) maps to 0(address).
-        * Also, the final 0(GS) (current 8(CX)) has to point
+        * so that -4(GS) maps to 0(address).
+        * Also, the final 0(GS) (current 4(CX)) has to point
         * to itself, to mimic ELF.
         */
-       ADDL    $0x8, CX        // address
+       ADDL    $0x4, CX        // address
        MOVL    CX, 0(CX)
 
        // set up user_desc
index 134d649b06b61fdcc70a754cf44a205f327c4eb7..75e1c4284ed0f9486b20df5c144a701527c41dc7 100644 (file)
@@ -359,7 +359,7 @@ TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
 
 // set tls base to DI
 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    $0x1002, DI     // ARCH_SET_FS
index e0fc926fb9779b87cd00a3c446e70f2bd3c61694..bfa7928df788c7fb49437f4bab552d204e263cb4 100644 (file)
@@ -307,9 +307,9 @@ TEXT runtime·setldt(SB),NOSPLIT,$8
        RET
 
 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
-       ADDL    $8, CX
+       ADDL    $4, CX
        MOVL    $0, 0(SP)               // syscall gap
        MOVL    CX, 4(SP)               // arg 1 - ptr
        MOVL    $317, AX                // sys__lwp_setprivate
index 88ca323aaf196066c0bf169c8dea57eefef9aff1..a138286d863d5ed03be2556aba082145d09ed89e 100644 (file)
@@ -307,8 +307,8 @@ TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
 
 // set tls base to DI
 TEXT runtime·settls(SB),NOSPLIT,$8
-       // adjust for ELF: wants to use -16(FS) and -8(FS) for g and m
-       ADDQ    $16, DI                 // arg 1 - ptr
+       // adjust for ELF: wants to use -8(FS) for g
+       ADDQ    $8, DI                  // arg 1 - ptr
        MOVQ    $317, AX                // sys__lwp_setprivate
        SYSCALL
        JCC     2(PC)
index 86774de0033d8f337532c6326c2459dfdabd425d..10877096d4330dd446fb3848ec914877a076a3c8 100644 (file)
@@ -325,9 +325,9 @@ TEXT runtime·setldt(SB),NOSPLIT,$4
        RET
 
 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
-       ADDL    $8, CX
+       ADDL    $4, CX
        MOVL    $0, 0(SP)               // syscall gap
        MOVL    CX, 4(SP)               // arg 1 - tcb
        MOVL    $329, AX                // sys___set_tcb
index 1e809b7e80e14a33c33e9e2eae654a0f119fb4dc..d05782c181db85302ac2e129ab06a98eb7c47ecd 100644 (file)
@@ -298,7 +298,7 @@ TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
 // set tls base to DI
 TEXT runtime·settls(SB),NOSPLIT,$0
        // 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
        SYSCALL
        JCC     2(PC)