mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd: add new common architecture representation
Information about CPU architectures (e.g., name, family, byte ordering, pointer and register size) is currently redundantly scattered around the source tree. Instead consolidate the basic information into a single new package cmd/internal/sys. Also, introduce new sys.I386, sys.AMD64, etc. names for the constants '8', '6', etc. and replace most uses of the latter. The notable exceptions are a couple of error messages that still refer to the old char-based toolchain names and function reltype in cmd/link. Passes toolstash/buildall. Change-Id: I8a6f0cbd49577ec1672a98addebc45f767e36461 Reviewed-on: https://go-review.googlesource.com/21623 Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
31cf1c1779
commit
c6e11fe037
67 changed files with 639 additions and 743 deletions
|
|
@ -34,6 +34,7 @@ package ld
|
|||
import (
|
||||
"cmd/internal/gcprog"
|
||||
"cmd/internal/obj"
|
||||
"cmd/internal/sys"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
|
@ -121,7 +122,7 @@ func Adduint64(ctxt *Link, s *LSym, v uint64) int64 {
|
|||
}
|
||||
|
||||
func adduint(ctxt *Link, s *LSym, v uint64) int64 {
|
||||
return adduintxx(ctxt, s, v, Thearch.Intsize)
|
||||
return adduintxx(ctxt, s, v, SysArch.IntSize)
|
||||
}
|
||||
|
||||
func setuint8(ctxt *Link, s *LSym, r int64, v uint8) int64 {
|
||||
|
|
@ -138,12 +139,12 @@ func Addaddrplus(ctxt *Link, s *LSym, t *LSym, add int64) int64 {
|
|||
}
|
||||
s.Attr |= AttrReachable
|
||||
i := s.Size
|
||||
s.Size += int64(ctxt.Arch.Ptrsize)
|
||||
s.Size += int64(ctxt.Arch.PtrSize)
|
||||
Symgrow(ctxt, s, s.Size)
|
||||
r := Addrel(s)
|
||||
r.Sym = t
|
||||
r.Off = int32(i)
|
||||
r.Siz = uint8(ctxt.Arch.Ptrsize)
|
||||
r.Siz = uint8(ctxt.Arch.PtrSize)
|
||||
r.Type = obj.R_ADDR
|
||||
r.Add = add
|
||||
return i + int64(r.Siz)
|
||||
|
|
@ -163,7 +164,7 @@ func Addpcrelplus(ctxt *Link, s *LSym, t *LSym, add int64) int64 {
|
|||
r.Add = add
|
||||
r.Type = obj.R_PCREL
|
||||
r.Siz = 4
|
||||
if Thearch.Thechar == 'z' {
|
||||
if SysArch.Family == sys.S390X {
|
||||
r.Variant = RV_390_DBL
|
||||
}
|
||||
return i + int64(r.Siz)
|
||||
|
|
@ -178,15 +179,15 @@ func setaddrplus(ctxt *Link, s *LSym, off int64, t *LSym, add int64) int64 {
|
|||
s.Type = obj.SDATA
|
||||
}
|
||||
s.Attr |= AttrReachable
|
||||
if off+int64(ctxt.Arch.Ptrsize) > s.Size {
|
||||
s.Size = off + int64(ctxt.Arch.Ptrsize)
|
||||
if off+int64(ctxt.Arch.PtrSize) > s.Size {
|
||||
s.Size = off + int64(ctxt.Arch.PtrSize)
|
||||
Symgrow(ctxt, s, s.Size)
|
||||
}
|
||||
|
||||
r := Addrel(s)
|
||||
r.Sym = t
|
||||
r.Off = int32(off)
|
||||
r.Siz = uint8(ctxt.Arch.Ptrsize)
|
||||
r.Siz = uint8(ctxt.Arch.PtrSize)
|
||||
r.Type = obj.R_ADDR
|
||||
r.Add = add
|
||||
return off + int64(r.Siz)
|
||||
|
|
@ -202,12 +203,12 @@ func addsize(ctxt *Link, s *LSym, t *LSym) int64 {
|
|||
}
|
||||
s.Attr |= AttrReachable
|
||||
i := s.Size
|
||||
s.Size += int64(ctxt.Arch.Ptrsize)
|
||||
s.Size += int64(ctxt.Arch.PtrSize)
|
||||
Symgrow(ctxt, s, s.Size)
|
||||
r := Addrel(s)
|
||||
r.Sym = t
|
||||
r.Off = int32(i)
|
||||
r.Siz = uint8(ctxt.Arch.Ptrsize)
|
||||
r.Siz = uint8(ctxt.Arch.PtrSize)
|
||||
r.Type = obj.R_SIZE
|
||||
return i + int64(r.Siz)
|
||||
}
|
||||
|
|
@ -356,7 +357,7 @@ func relocsym(s *LSym) {
|
|||
// We need to be able to reference dynimport symbols when linking against
|
||||
// shared libraries, and Solaris needs it always
|
||||
if HEADTYPE != obj.Hsolaris && r.Sym != nil && r.Sym.Type == obj.SDYNIMPORT && !DynlinkingGo() {
|
||||
if !(Thearch.Thechar == '9' && Linkmode == LinkExternal && r.Sym.Name == ".TOC.") {
|
||||
if !(SysArch.Family == sys.PPC64 && Linkmode == LinkExternal && r.Sym.Name == ".TOC.") {
|
||||
Diag("unhandled relocation for %s (type %d rtype %d)", r.Sym.Name, r.Sym.Type, r.Type)
|
||||
}
|
||||
}
|
||||
|
|
@ -365,7 +366,7 @@ func relocsym(s *LSym) {
|
|||
}
|
||||
|
||||
// TODO(mundaym): remove this special case - see issue 14218.
|
||||
if Thearch.Thechar == 'z' {
|
||||
if SysArch.Family == sys.S390X {
|
||||
switch r.Type {
|
||||
case obj.R_PCRELDBL:
|
||||
r.Type = obj.R_PCREL
|
||||
|
|
@ -394,7 +395,7 @@ func relocsym(s *LSym) {
|
|||
}
|
||||
|
||||
case obj.R_TLS_LE:
|
||||
isAndroidX86 := goos == "android" && (Thearch.Thechar == '6' || Thearch.Thechar == '8')
|
||||
isAndroidX86 := goos == "android" && (SysArch.InFamily(sys.AMD64, sys.I386))
|
||||
|
||||
if Linkmode == LinkExternal && Iself && HEADTYPE != obj.Hopenbsd && !isAndroidX86 {
|
||||
r.Done = 0
|
||||
|
|
@ -404,13 +405,13 @@ func relocsym(s *LSym) {
|
|||
r.Xsym = r.Sym
|
||||
r.Xadd = r.Add
|
||||
o = 0
|
||||
if Thearch.Thechar != '6' {
|
||||
if SysArch.Family != sys.AMD64 {
|
||||
o = r.Add
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if Iself && Thearch.Thechar == '5' {
|
||||
if Iself && SysArch.Family == sys.ARM {
|
||||
// On ELF ARM, the thread pointer is 8 bytes before
|
||||
// the start of the thread-local data block, so add 8
|
||||
// to the actual TLS offset (r->sym->value).
|
||||
|
|
@ -428,7 +429,7 @@ func relocsym(s *LSym) {
|
|||
}
|
||||
|
||||
case obj.R_TLS_IE:
|
||||
isAndroidX86 := goos == "android" && (Thearch.Thechar == '6' || Thearch.Thechar == '8')
|
||||
isAndroidX86 := goos == "android" && (SysArch.InFamily(sys.AMD64, sys.I386))
|
||||
|
||||
if Linkmode == LinkExternal && Iself && HEADTYPE != obj.Hopenbsd && !isAndroidX86 {
|
||||
r.Done = 0
|
||||
|
|
@ -438,7 +439,7 @@ func relocsym(s *LSym) {
|
|||
r.Xsym = r.Sym
|
||||
r.Xadd = r.Add
|
||||
o = 0
|
||||
if Thearch.Thechar != '6' {
|
||||
if SysArch.Family != sys.AMD64 {
|
||||
o = r.Add
|
||||
}
|
||||
break
|
||||
|
|
@ -465,7 +466,7 @@ func relocsym(s *LSym) {
|
|||
|
||||
o = r.Xadd
|
||||
if Iself {
|
||||
if Thearch.Thechar == '6' {
|
||||
if SysArch.Family == sys.AMD64 {
|
||||
o = 0
|
||||
}
|
||||
} else if HEADTYPE == obj.Hdarwin {
|
||||
|
|
@ -475,10 +476,10 @@ func relocsym(s *LSym) {
|
|||
// The workaround is that on arm64 don't ever add symaddr to o and always use
|
||||
// extern relocation by requiring rs->dynid >= 0.
|
||||
if rs.Type != obj.SHOSTOBJ {
|
||||
if Thearch.Thechar == '7' && rs.Dynid < 0 {
|
||||
if SysArch.Family == sys.ARM64 && rs.Dynid < 0 {
|
||||
Diag("R_ADDR reloc to %s+%d is not supported on darwin/arm64", rs.Name, o)
|
||||
}
|
||||
if Thearch.Thechar != '7' {
|
||||
if SysArch.Family != sys.ARM64 {
|
||||
o += Symaddr(rs)
|
||||
}
|
||||
}
|
||||
|
|
@ -498,7 +499,7 @@ func relocsym(s *LSym) {
|
|||
// fail at runtime. See https://golang.org/issue/7980.
|
||||
// Instead of special casing only amd64, we treat this as an error on all
|
||||
// 64-bit architectures so as to be future-proof.
|
||||
if int32(o) < 0 && Thearch.Ptrsize > 4 && siz == 4 {
|
||||
if int32(o) < 0 && SysArch.PtrSize > 4 && siz == 4 {
|
||||
Diag("non-pc-relative relocation address is too big: %#x (%#x + %#x)", uint64(o), Symaddr(r.Sym), r.Add)
|
||||
errorexit()
|
||||
}
|
||||
|
|
@ -515,7 +516,7 @@ func relocsym(s *LSym) {
|
|||
r.Xadd = r.Add + Symaddr(r.Sym) - int64(r.Sym.Sect.Vaddr)
|
||||
o = r.Xadd
|
||||
rs = r.Xsym
|
||||
if Iself && Thearch.Thechar == '6' {
|
||||
if Iself && SysArch.Family == sys.AMD64 {
|
||||
o = 0
|
||||
}
|
||||
break
|
||||
|
|
@ -544,7 +545,7 @@ func relocsym(s *LSym) {
|
|||
|
||||
o = r.Xadd
|
||||
if Iself {
|
||||
if Thearch.Thechar == '6' {
|
||||
if SysArch.Family == sys.AMD64 {
|
||||
o = 0
|
||||
}
|
||||
} else if HEADTYPE == obj.Hdarwin {
|
||||
|
|
@ -556,7 +557,7 @@ func relocsym(s *LSym) {
|
|||
} else {
|
||||
o += int64(r.Siz)
|
||||
}
|
||||
} else if HEADTYPE == obj.Hwindows && Thearch.Thechar == '6' { // only amd64 needs PCREL
|
||||
} else if HEADTYPE == obj.Hwindows && SysArch.Family == sys.AMD64 { // only amd64 needs PCREL
|
||||
// PE/COFF's PC32 relocation uses the address after the relocated
|
||||
// bytes as the base. Compensate by skewing the addend.
|
||||
o += int64(r.Siz)
|
||||
|
|
@ -675,7 +676,7 @@ func dynrelocsym(s *LSym) {
|
|||
r.Add = int64(targ.Plt)
|
||||
|
||||
// jmp *addr
|
||||
if Thearch.Thechar == '8' {
|
||||
if SysArch.Family == sys.I386 {
|
||||
Adduint8(Ctxt, rel, 0xff)
|
||||
Adduint8(Ctxt, rel, 0x25)
|
||||
Addaddr(Ctxt, rel, targ)
|
||||
|
|
@ -982,7 +983,7 @@ func addstrdata(name string, value string) {
|
|||
s.Attr |= AttrDuplicateOK
|
||||
reachable := s.Attr.Reachable()
|
||||
Addaddr(Ctxt, s, sp)
|
||||
adduintxx(Ctxt, s, uint64(len(value)), Thearch.Ptrsize)
|
||||
adduintxx(Ctxt, s, uint64(len(value)), SysArch.PtrSize)
|
||||
|
||||
// addstring, addaddr, etc., mark the symbols as reachable.
|
||||
// In this case that is not necessarily true, so stick to what
|
||||
|
|
@ -1128,7 +1129,7 @@ func (p *GCProg) writeByte(x byte) {
|
|||
}
|
||||
|
||||
func (p *GCProg) End(size int64) {
|
||||
p.w.ZeroUntil(size / int64(Thearch.Ptrsize))
|
||||
p.w.ZeroUntil(size / int64(SysArch.PtrSize))
|
||||
p.w.End()
|
||||
if debugGCProg {
|
||||
fmt.Fprintf(os.Stderr, "ld: end GCProg\n")
|
||||
|
|
@ -1144,7 +1145,7 @@ func (p *GCProg) AddSym(s *LSym) {
|
|||
return
|
||||
}
|
||||
|
||||
ptrsize := int64(Thearch.Ptrsize)
|
||||
ptrsize := int64(SysArch.PtrSize)
|
||||
nptr := decodetype_ptrdata(typ) / ptrsize
|
||||
|
||||
if debugGCProg {
|
||||
|
|
@ -1532,7 +1533,7 @@ func dodata() {
|
|||
if s != nil && s.Type == obj.STLSBSS {
|
||||
if Iself && (Linkmode == LinkExternal || Debug['d'] == 0) && HEADTYPE != obj.Hopenbsd {
|
||||
sect = addsection(&Segdata, ".tbss", 06)
|
||||
sect.Align = int32(Thearch.Ptrsize)
|
||||
sect.Align = int32(SysArch.PtrSize)
|
||||
sect.Vaddr = 0
|
||||
} else {
|
||||
sect = nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue