Skip to content

Commit a5cb762

Browse files
committed
cmd/internal/obj, cmd/link, runtime: lots of TLS cleanup
It's particularly nice to get rid of the android special cases in the linker. Change-Id: I516363af7ce8a6b2f196fe49cb8887ac787a6dad Reviewed-on: https://go-review.googlesource.com/14197 Run-TryBot: Michael Hudson-Doyle <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 1ef9b5a commit a5cb762

15 files changed

Lines changed: 27 additions & 132 deletions

File tree

src/cmd/internal/obj/arm/asm5.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,6 @@ func span5(ctxt *obj.Link, cursym *obj.LSym) {
739739
* code references to be relocated too, and then
740740
* perhaps we'd be able to parallelize the span loop above.
741741
*/
742-
if ctxt.Tlsg == nil {
743-
ctxt.Tlsg = obj.Linklookup(ctxt, "runtime.tlsg", 0)
744-
}
745742

746743
p = cursym.Text
747744
ctxt.Autosize = int32(p.To.Offset + 4)
@@ -1646,19 +1643,7 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) {
16461643
rel.Sym = p.To.Sym
16471644
rel.Add = p.To.Offset
16481645

1649-
// runtime.tlsg is special.
1650-
// Its "address" is the offset from the TLS thread pointer
1651-
// to the thread-local g and m pointers.
1652-
// Emit a TLS relocation instead of a standard one if its
1653-
// type is not explicitly set by runtime. This assumes that
1654-
// all references to runtime.tlsg should be accompanied with
1655-
// its type declaration if necessary.
1656-
if rel.Sym == ctxt.Tlsg && ctxt.Tlsg.Type == 0 {
1657-
rel.Type = obj.R_TLS
1658-
if ctxt.Flag_shared != 0 {
1659-
rel.Add += ctxt.Pc - p.Rel.Pc - 8 - int64(rel.Siz)
1660-
}
1661-
} else if ctxt.Flag_shared != 0 {
1646+
if ctxt.Flag_shared != 0 {
16621647
rel.Type = obj.R_PCREL
16631648
rel.Add += ctxt.Pc - p.Rel.Pc - 8
16641649
} else {

src/cmd/internal/obj/arm/obj5.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -129,24 +129,6 @@ func progedit(ctxt *obj.Link, p *obj.Prog) {
129129
p.From.Offset = 0
130130
}
131131
}
132-
133-
if ctxt.Flag_shared != 0 {
134-
// Shared libraries use R_ARM_TLS_IE32 instead of
135-
// R_ARM_TLS_LE32, replacing the link time constant TLS offset in
136-
// runtime.tlsg with an address to a GOT entry containing the
137-
// offset. Rewrite $runtime.tlsg(SB) to runtime.tlsg(SB) to
138-
// compensate.
139-
if ctxt.Tlsg == nil {
140-
ctxt.Tlsg = obj.Linklookup(ctxt, "runtime.tlsg", 0)
141-
}
142-
143-
if p.From.Type == obj.TYPE_ADDR && p.From.Name == obj.NAME_EXTERN && p.From.Sym == ctxt.Tlsg {
144-
p.From.Type = obj.TYPE_MEM
145-
}
146-
if p.To.Type == obj.TYPE_ADDR && p.To.Name == obj.NAME_EXTERN && p.To.Sym == ctxt.Tlsg {
147-
p.To.Type = obj.TYPE_MEM
148-
}
149-
}
150132
}
151133

152134
// Prog.mark

src/cmd/internal/obj/arm64/asm7.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,6 @@ func span7(ctxt *obj.Link, cursym *obj.LSym) {
631631
/*
632632
* lay out the code, emitting code and data relocations.
633633
*/
634-
if ctxt.Tlsg == nil {
635-
ctxt.Tlsg = obj.Linklookup(ctxt, "runtime.tlsg", 0)
636-
}
637634
obj.Symgrow(ctxt, cursym, cursym.Size)
638635
bp := cursym.P
639636
psz := int32(0)

src/cmd/internal/obj/link.go

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -414,23 +414,16 @@ const (
414414
R_CALLPOWER
415415
R_CONST
416416
R_PCREL
417-
// R_TLS (only used on arm currently, and not on android and darwin where tlsg is
418-
// a regular variable) resolves to data needed to access the thread-local g. It is
419-
// interpreted differently depending on toolchain flags to implement either the
420-
// "local exec" or "inital exec" model for tls access.
421-
// TODO(mwhudson): change to use R_TLS_LE or R_TLS_IE as appropriate, not having
422-
// R_TLS do double duty.
423-
R_TLS
424-
// R_TLS_LE (only used on 386 and amd64 currently) resolves to the offset of the
425-
// thread-local g from the thread local base and is used to implement the "local
426-
// exec" model for tls access (r.Sym is not set by the compiler for this case but
427-
// is set to Tlsg in the linker when externally linking).
417+
// R_TLS_LE, used on 386, amd64, and ARM, resolves to the offset of the
418+
// thread-local symbol from the thread local base and is used to implement the
419+
// "local exec" model for tls access (r.Sym is not set on intel platforms but is
420+
// set to a TLS symbol -- runtime.tlsg -- in the linker when externally linking).
428421
R_TLS_LE
429-
// R_TLS_IE (only used on 386 and amd64 currently) resolves to the PC-relative
430-
// offset to a GOT slot containing the offset the thread-local g from the thread
431-
// local base and is used to implemented the "initial exec" model for tls access
432-
// (r.Sym is not set by the compiler for this case but is set to Tlsg in the
433-
// linker when externally linking).
422+
// R_TLS_IE, used 386, amd64, and ARM resolves to the PC-relative offset to a GOT
423+
// slot containing the offset from the thread-local symbol from the thread local
424+
// base and is used to implemented the "initial exec" model for tls access (r.Sym
425+
// is not set on intel platforms but is set to a TLS symbol -- runtime.tlsg -- in
426+
// the linker when externally linking).
434427
R_TLS_IE
435428
R_GOTOFF
436429
R_PLT0
@@ -505,7 +498,6 @@ type Link struct {
505498
Sym_divu *LSym
506499
Sym_mod *LSym
507500
Sym_modu *LSym
508-
Tlsg *LSym
509501
Plan9privates *LSym
510502
Curp *Prog
511503
Printp *Prog

src/cmd/internal/obj/mips/asm0.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,6 @@ func span9(ctxt *obj.Link, cursym *obj.LSym) {
504504
/*
505505
* lay out the code, emitting code and data relocations.
506506
*/
507-
if ctxt.Tlsg == nil {
508-
ctxt.Tlsg = obj.Linklookup(ctxt, "runtime.tlsg", 0)
509-
}
510507

511508
obj.Symgrow(ctxt, cursym, cursym.Size)
512509

src/cmd/internal/obj/ppc64/asm9.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,6 @@ func span9(ctxt *obj.Link, cursym *obj.LSym) {
504504
/*
505505
* lay out the code, emitting code and data relocations.
506506
*/
507-
if ctxt.Tlsg == nil {
508-
ctxt.Tlsg = obj.Linklookup(ctxt, "runtime.tlsg", 0)
509-
}
510507

511508
obj.Symgrow(ctxt, cursym, cursym.Size)
512509

src/cmd/internal/obj/x86/obj6.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,6 @@ func nacladdr(ctxt *obj.Link, p *obj.Prog, a *obj.Addr) {
435435
}
436436

437437
func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
438-
if ctxt.Tlsg == nil {
439-
ctxt.Tlsg = obj.Linklookup(ctxt, "runtime.tlsg", 0)
440-
}
441-
442438
if ctxt.Headtype == obj.Hplan9 && ctxt.Plan9privates == nil {
443439
ctxt.Plan9privates = obj.Linklookup(ctxt, "_privates", 0)
444440
}

src/cmd/link/internal/arm/asm.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,6 @@ func elfreloc1(r *ld.Reloc, sectoff int64) int {
223223
return -1
224224
}
225225

226-
case obj.R_TLS:
227-
if r.Siz == 4 {
228-
if ld.Buildmode == ld.BuildmodeCShared {
229-
ld.Thearch.Lput(ld.R_ARM_TLS_IE32 | uint32(elfsym)<<8)
230-
} else {
231-
ld.Thearch.Lput(ld.R_ARM_TLS_LE32 | uint32(elfsym)<<8)
232-
}
233-
} else {
234-
return -1
235-
}
236-
237226
case obj.R_TLS_LE:
238227
ld.Thearch.Lput(ld.R_ARM_TLS_LE32 | uint32(elfsym)<<8)
239228

@@ -345,7 +334,7 @@ func archreloc(r *ld.Reloc, s *ld.LSym, val *int64) int {
345334
rs = rs.Outer
346335
}
347336

348-
if rs.Type != obj.SHOSTOBJ && rs.Sect == nil {
337+
if rs.Type != obj.SHOSTOBJ && rs.Type != obj.SDYNIMPORT && rs.Sect == nil {
349338
ld.Diag("missing section for %s", rs.Name)
350339
}
351340
r.Xsym = rs

src/cmd/link/internal/ld/data.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,6 @@ func relocsym(s *LSym) {
362362
Diag("unreachable sym in relocation: %s %s", s.Name, r.Sym.Name)
363363
}
364364

365-
// Android emulates runtime.tlsg as a regular variable.
366-
if r.Type == obj.R_TLS && goos == "android" {
367-
r.Type = obj.R_ADDR
368-
}
369-
370365
switch r.Type {
371366
default:
372367
switch siz {
@@ -385,26 +380,6 @@ func relocsym(s *LSym) {
385380
Diag("unknown reloc %d", r.Type)
386381
}
387382

388-
case obj.R_TLS:
389-
if Linkmode == LinkExternal && Iself && HEADTYPE != obj.Hopenbsd {
390-
r.Done = 0
391-
r.Sym = Ctxt.Tlsg
392-
r.Xsym = Ctxt.Tlsg
393-
r.Xadd = r.Add
394-
o = r.Add
395-
break
396-
}
397-
if Linkmode == LinkInternal && Iself && Thearch.Thechar == '5' {
398-
panic("should no longer get here")
399-
break
400-
}
401-
402-
r.Done = 0
403-
o = 0
404-
if Thearch.Thechar != '6' {
405-
o = r.Add
406-
}
407-
408383
case obj.R_TLS_LE:
409384
if Linkmode == LinkExternal && Iself && HEADTYPE != obj.Hopenbsd {
410385
r.Done = 0

src/cmd/link/internal/ld/elf.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,9 +1506,7 @@ func elfshbits(sect *Section) *ElfShdr {
15061506
sh.flags |= SHF_WRITE
15071507
}
15081508
if sect.Name == ".tbss" {
1509-
if goos != "android" {
1510-
sh.flags |= SHF_TLS // no TLS on android
1511-
}
1509+
sh.flags |= SHF_TLS
15121510
sh.type_ = SHT_NOBITS
15131511
}
15141512

@@ -1517,7 +1515,7 @@ func elfshbits(sect *Section) *ElfShdr {
15171515
}
15181516
sh.addralign = uint64(sect.Align)
15191517
sh.size = sect.Length
1520-
if sect.Name != ".tbss" || goos == "android" {
1518+
if sect.Name != ".tbss" {
15211519
sh.off = sect.Seg.Fileoff + sect.Vaddr - sect.Seg.Vaddr
15221520
}
15231521

0 commit comments

Comments
 (0)