Commit 791f71d1 authored by David Crawshaw's avatar David Crawshaw

cmd: use obj.GOOS, obj.GOARCH, etc

As cmd/internal/obj is coordinating the definition of GOOS, GOARCH,
etc across the compiler and linker, turn its functions into globals
and use them everywhere.

Change-Id: I5db5addda3c6b6435c37fd5581c7c3d9a561f492
Reviewed-on: https://go-review.googlesource.com/28854
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent f2f374d1
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
package asm package asm
import ( import (
"os"
"testing" "testing"
"cmd/asm/internal/arch" "cmd/asm/internal/arch"
...@@ -16,8 +15,8 @@ import ( ...@@ -16,8 +15,8 @@ import (
// A simple in-out test: Do we print what we parse? // A simple in-out test: Do we print what we parse?
func setArch(goarch string) (*arch.Arch, *obj.Link) { func setArch(goarch string) (*arch.Arch, *obj.Link) {
os.Setenv("GOOS", "linux") // obj can handle this OS for all architectures. obj.GOOS = "linux" // obj can handle this OS for all architectures.
os.Setenv("GOARCH", goarch) obj.GOARCH = goarch
architecture := arch.Set(goarch) architecture := arch.Set(goarch)
if architecture == nil { if architecture == nil {
panic("asm: unrecognized architecture " + goarch) panic("asm: unrecognized architecture " + goarch)
......
...@@ -24,7 +24,7 @@ func main() { ...@@ -24,7 +24,7 @@ func main() {
log.SetFlags(0) log.SetFlags(0)
log.SetPrefix("asm: ") log.SetPrefix("asm: ")
GOARCH := obj.Getgoarch() GOARCH := obj.GOARCH
architecture := arch.Set(GOARCH) architecture := arch.Set(GOARCH)
if architecture == nil { if architecture == nil {
...@@ -51,7 +51,7 @@ func main() { ...@@ -51,7 +51,7 @@ func main() {
defer bio.MustClose(out) defer bio.MustClose(out)
buf := bufio.NewWriter(bio.MustWriter(out)) buf := bufio.NewWriter(bio.MustWriter(out))
fmt.Fprintf(buf, "go object %s %s %s\n", obj.Getgoos(), obj.Getgoarch(), obj.Getgoversion()) fmt.Fprintf(buf, "go object %s %s %s\n", obj.GOOS, obj.GOARCH, obj.Version)
fmt.Fprintf(buf, "!\n") fmt.Fprintf(buf, "!\n")
var ok, diag bool var ok, diag bool
......
...@@ -80,7 +80,7 @@ func blockcopy(n, ns *gc.Node, osrc, odst, w int64) { ...@@ -80,7 +80,7 @@ func blockcopy(n, ns *gc.Node, osrc, odst, w int64) {
gins(x86.ACLD, nil, nil) gins(x86.ACLD, nil, nil)
} else { } else {
// normal direction // normal direction
if q > 128 || (gc.Nacl && q >= 4) || (obj.Getgoos() == "plan9" && q >= 4) { if q > 128 || (gc.Nacl && q >= 4) || (obj.GOOS == "plan9" && q >= 4) {
gconreg(movptr, q, x86.REG_CX) gconreg(movptr, q, x86.REG_CX)
gins(x86.AREP, nil, nil) // repeat gins(x86.AREP, nil, nil) // repeat
gins(x86.AMOVSQ, nil, nil) // MOVQ *(SI)+,*(DI)+ gins(x86.AMOVSQ, nil, nil) // MOVQ *(SI)+,*(DI)+
......
...@@ -18,17 +18,17 @@ var ( ...@@ -18,17 +18,17 @@ var (
) )
func betypeinit() { func betypeinit() {
if obj.Getgoarch() == "amd64p32" { if obj.GOARCH == "amd64p32" {
addptr = x86.AADDL addptr = x86.AADDL
movptr = x86.AMOVL movptr = x86.AMOVL
leaptr = x86.ALEAL leaptr = x86.ALEAL
cmpptr = x86.ACMPL cmpptr = x86.ACMPL
} }
if gc.Ctxt.Flag_dynlink || obj.Getgoos() == "nacl" { if gc.Ctxt.Flag_dynlink || obj.GOOS == "nacl" {
resvd = append(resvd, x86.REG_R15) resvd = append(resvd, x86.REG_R15)
} }
if gc.Ctxt.Framepointer_enabled || obj.Getgoos() == "nacl" { if gc.Ctxt.Framepointer_enabled || obj.GOOS == "nacl" {
resvd = append(resvd, x86.REG_BP) resvd = append(resvd, x86.REG_BP)
} }
gc.Thearch.ReservedRegs = resvd gc.Thearch.ReservedRegs = resvd
...@@ -36,7 +36,7 @@ func betypeinit() { ...@@ -36,7 +36,7 @@ func betypeinit() {
func Main() { func Main() {
gc.Thearch.LinkArch = &x86.Linkamd64 gc.Thearch.LinkArch = &x86.Linkamd64
if obj.Getgoarch() == "amd64p32" { if obj.GOARCH == "amd64p32" {
gc.Thearch.LinkArch = &x86.Linkamd64p32 gc.Thearch.LinkArch = &x86.Linkamd64p32
} }
gc.Thearch.REGSP = x86.REGSP gc.Thearch.REGSP = x86.REGSP
......
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
) )
// no floating point in note handlers on Plan 9 // no floating point in note handlers on Plan 9
var isPlan9 = obj.Getgoos() == "plan9" var isPlan9 = obj.GOOS == "plan9"
func defframe(ptxt *obj.Prog) { func defframe(ptxt *obj.Prog) {
// fill in argument size, stack size // fill in argument size, stack size
......
...@@ -66,7 +66,7 @@ func defframe(ptxt *obj.Prog) { ...@@ -66,7 +66,7 @@ func defframe(ptxt *obj.Prog) {
zerorange(p, int64(frame), lo, hi) zerorange(p, int64(frame), lo, hi)
} }
var darwin = obj.Getgoos() == "darwin" var darwin = obj.GOOS == "darwin"
func zerorange(p *obj.Prog, frame int64, lo int64, hi int64) *obj.Prog { func zerorange(p *obj.Prog, frame int64, lo int64, hi int64) *obj.Prog {
cnt := hi - lo cnt := hi - lo
......
...@@ -26,9 +26,6 @@ import ( ...@@ -26,9 +26,6 @@ import (
var imported_unsafe bool var imported_unsafe bool
var ( var (
goos string
goarch string
goroot string
buildid string buildid string
flag_newparser bool flag_newparser bool
...@@ -89,7 +86,7 @@ func doversion() { ...@@ -89,7 +86,7 @@ func doversion() {
if p != "" { if p != "" {
sep = " " sep = " "
} }
fmt.Printf("compile version %s%s%s\n", obj.Getgoversion(), sep, p) fmt.Printf("compile version %s%s%s\n", obj.Version, sep, p)
os.Exit(0) os.Exit(0)
} }
...@@ -108,8 +105,6 @@ func Main() { ...@@ -108,8 +105,6 @@ func Main() {
defer hidePanic() defer hidePanic()
goarch = obj.Getgoarch()
Ctxt = obj.Linknew(Thearch.LinkArch) Ctxt = obj.Linknew(Thearch.LinkArch)
Ctxt.DiagFunc = Yyerror Ctxt.DiagFunc = Yyerror
bstdout = bufio.NewWriter(os.Stdout) bstdout = bufio.NewWriter(os.Stdout)
...@@ -151,10 +146,7 @@ func Main() { ...@@ -151,10 +146,7 @@ func Main() {
mappkg.Name = "go.map" mappkg.Name = "go.map"
mappkg.Prefix = "go.map" mappkg.Prefix = "go.map"
goroot = obj.Getgoroot() Nacl = obj.GOOS == "nacl"
goos = obj.Getgoos()
Nacl = goos == "nacl"
if Nacl { if Nacl {
flag_largemodel = true flag_largemodel = true
} }
...@@ -533,7 +525,7 @@ func writebench(filename string) error { ...@@ -533,7 +525,7 @@ func writebench(filename string) error {
} }
var buf bytes.Buffer var buf bytes.Buffer
fmt.Fprintln(&buf, "commit:", obj.Getgoversion()) fmt.Fprintln(&buf, "commit:", obj.Version)
fmt.Fprintln(&buf, "goos:", runtime.GOOS) fmt.Fprintln(&buf, "goos:", runtime.GOOS)
fmt.Fprintln(&buf, "goarch:", runtime.GOARCH) fmt.Fprintln(&buf, "goarch:", runtime.GOARCH)
timings.Write(&buf, "BenchmarkCompile:"+myimportpath+":") timings.Write(&buf, "BenchmarkCompile:"+myimportpath+":")
...@@ -656,7 +648,7 @@ func findpkg(name string) (file string, ok bool) { ...@@ -656,7 +648,7 @@ func findpkg(name string) (file string, ok bool) {
} }
} }
if goroot != "" { if obj.GOROOT != "" {
suffix := "" suffix := ""
suffixsep := "" suffixsep := ""
if flag_installsuffix != "" { if flag_installsuffix != "" {
...@@ -670,11 +662,11 @@ func findpkg(name string) (file string, ok bool) { ...@@ -670,11 +662,11 @@ func findpkg(name string) (file string, ok bool) {
suffix = "msan" suffix = "msan"
} }
file = fmt.Sprintf("%s/pkg/%s_%s%s%s/%s.a", goroot, goos, goarch, suffixsep, suffix, name) file = fmt.Sprintf("%s/pkg/%s_%s%s%s/%s.a", obj.GOROOT, obj.GOOS, obj.GOARCH, suffixsep, suffix, name)
if _, err := os.Stat(file); err == nil { if _, err := os.Stat(file); err == nil {
return file, true return file, true
} }
file = fmt.Sprintf("%s/pkg/%s_%s%s%s/%s.o", goroot, goos, goarch, suffixsep, suffix, name) file = fmt.Sprintf("%s/pkg/%s_%s%s%s/%s.o", obj.GOROOT, obj.GOOS, obj.GOARCH, suffixsep, suffix, name)
if _, err := os.Stat(file); err == nil { if _, err := os.Stat(file); err == nil {
return file, true return file, true
} }
...@@ -814,7 +806,7 @@ func importfile(f *Val, indent []byte) { ...@@ -814,7 +806,7 @@ func importfile(f *Val, indent []byte) {
errorexit() errorexit()
} }
q := fmt.Sprintf("%s %s %s %s", obj.Getgoos(), obj.Getgoarch(), obj.Getgoversion(), obj.Expstring()) q := fmt.Sprintf("%s %s %s %s", obj.GOOS, obj.GOARCH, obj.Version, obj.Expstring())
if p[10:] != q { if p[10:] != q {
Yyerror("import %s: object is [%s] expected [%s]", file, p[10:], q) Yyerror("import %s: object is [%s] expected [%s]", file, p[10:], q)
errorexit() errorexit()
......
...@@ -68,7 +68,7 @@ func dumpobj1(outfile string, mode int) { ...@@ -68,7 +68,7 @@ func dumpobj1(outfile string, mode int) {
} }
printheader := func() { printheader := func() {
fmt.Fprintf(bout, "go object %s %s %s %s\n", obj.Getgoos(), obj.Getgoarch(), obj.Getgoversion(), obj.Expstring()) fmt.Fprintf(bout, "go object %s %s %s %s\n", obj.GOOS, obj.GOARCH, obj.Version, obj.Expstring())
if buildid != "" { if buildid != "" {
fmt.Fprintf(bout, "build id %q\n", buildid) fmt.Fprintf(bout, "build id %q\n", buildid)
} }
......
...@@ -155,7 +155,7 @@ func Fatalf(fmt_ string, args ...interface{}) { ...@@ -155,7 +155,7 @@ func Fatalf(fmt_ string, args ...interface{}) {
fmt.Printf("\n") fmt.Printf("\n")
// If this is a released compiler version, ask for a bug report. // If this is a released compiler version, ask for a bug report.
if strings.HasPrefix(obj.Getgoversion(), "release") { if strings.HasPrefix(obj.Version, "release") {
fmt.Printf("\n") fmt.Printf("\n")
fmt.Printf("Please file a bug report including a short program that triggers the error.\n") fmt.Printf("Please file a bug report including a short program that triggers the error.\n")
fmt.Printf("https://golang.org/issue/new\n") fmt.Printf("https://golang.org/issue/new\n")
......
...@@ -16,7 +16,7 @@ func betypeinit() { ...@@ -16,7 +16,7 @@ func betypeinit() {
func Main() { func Main() {
gc.Thearch.LinkArch = &mips.Linkmips64 gc.Thearch.LinkArch = &mips.Linkmips64
if obj.Getgoarch() == "mips64le" { if obj.GOARCH == "mips64le" {
gc.Thearch.LinkArch = &mips.Linkmips64le gc.Thearch.LinkArch = &mips.Linkmips64le
} }
gc.Thearch.REGSP = mips.REGSP gc.Thearch.REGSP = mips.REGSP
......
...@@ -19,7 +19,7 @@ func betypeinit() { ...@@ -19,7 +19,7 @@ func betypeinit() {
func Main() { func Main() {
gc.Thearch.LinkArch = &ppc64.Linkppc64 gc.Thearch.LinkArch = &ppc64.Linkppc64
if obj.Getgoarch() == "ppc64le" { if obj.GOARCH == "ppc64le" {
gc.Thearch.LinkArch = &ppc64.Linkppc64le gc.Thearch.LinkArch = &ppc64.Linkppc64le
} }
gc.Thearch.REGSP = ppc64.REGSP gc.Thearch.REGSP = ppc64.REGSP
......
...@@ -182,7 +182,7 @@ func NewConfig(arch string, fe Frontend, ctxt *obj.Link, optimize bool) *Config ...@@ -182,7 +182,7 @@ func NewConfig(arch string, fe Frontend, ctxt *obj.Link, optimize bool) *Config
c.fpRegMask = fpRegMaskARM64 c.fpRegMask = fpRegMaskARM64
c.FPReg = framepointerRegARM64 c.FPReg = framepointerRegARM64
c.hasGReg = true c.hasGReg = true
c.noDuffDevice = obj.Getgoos() == "darwin" // darwin linker cannot handle BR26 reloc with non-zero addend c.noDuffDevice = obj.GOOS == "darwin" // darwin linker cannot handle BR26 reloc with non-zero addend
case "ppc64le": case "ppc64le":
c.IntSize = 8 c.IntSize = 8
c.PtrSize = 8 c.PtrSize = 8
...@@ -211,11 +211,11 @@ func NewConfig(arch string, fe Frontend, ctxt *obj.Link, optimize bool) *Config ...@@ -211,11 +211,11 @@ func NewConfig(arch string, fe Frontend, ctxt *obj.Link, optimize bool) *Config
} }
c.ctxt = ctxt c.ctxt = ctxt
c.optimize = optimize c.optimize = optimize
c.nacl = obj.Getgoos() == "nacl" c.nacl = obj.GOOS == "nacl"
// Don't use Duff's device on Plan 9 AMD64, because floating // Don't use Duff's device on Plan 9 AMD64, because floating
// point operations are not allowed in note handler. // point operations are not allowed in note handler.
if obj.Getgoos() == "plan9" && arch == "amd64" { if obj.GOOS == "plan9" && arch == "amd64" {
c.noDuffDevice = true c.noDuffDevice = true
} }
......
...@@ -24,7 +24,7 @@ func Main() { ...@@ -24,7 +24,7 @@ func Main() {
gc.Thearch.REGRETURN = x86.REG_AX gc.Thearch.REGRETURN = x86.REG_AX
gc.Thearch.REGMIN = x86.REG_AX gc.Thearch.REGMIN = x86.REG_AX
gc.Thearch.REGMAX = x86.REG_DI gc.Thearch.REGMAX = x86.REG_DI
switch v := obj.Getgo386(); v { switch v := obj.GO386; v {
case "387": case "387":
gc.Thearch.FREGMIN = x86.REG_F0 gc.Thearch.FREGMIN = x86.REG_F0
gc.Thearch.FREGMAX = x86.REG_F7 gc.Thearch.FREGMAX = x86.REG_F7
......
...@@ -23,9 +23,9 @@ func main() { ...@@ -23,9 +23,9 @@ func main() {
log.SetFlags(0) log.SetFlags(0)
log.SetPrefix("compile: ") log.SetPrefix("compile: ")
switch obj.Getgoarch() { switch obj.GOARCH {
default: default:
fmt.Fprintf(os.Stderr, "compile: unknown architecture %q\n", obj.Getgoarch()) fmt.Fprintf(os.Stderr, "compile: unknown architecture %q\n", obj.GOARCH)
os.Exit(2) os.Exit(2)
case "386": case "386":
x86.Main() x86.Main()
......
...@@ -2794,7 +2794,7 @@ func omvl(ctxt *obj.Link, p *obj.Prog, a *obj.Addr, dr int) uint32 { ...@@ -2794,7 +2794,7 @@ func omvl(ctxt *obj.Link, p *obj.Prog, a *obj.Addr, dr int) uint32 {
func chipzero5(ctxt *obj.Link, e float64) int { func chipzero5(ctxt *obj.Link, e float64) int {
// We use GOARM=7 to gate the use of VFPv3 vmov (imm) instructions. // We use GOARM=7 to gate the use of VFPv3 vmov (imm) instructions.
if ctxt.Goarm < 7 || e != 0 { if obj.GOARM < 7 || e != 0 {
return -1 return -1
} }
return 0 return 0
...@@ -2802,7 +2802,7 @@ func chipzero5(ctxt *obj.Link, e float64) int { ...@@ -2802,7 +2802,7 @@ func chipzero5(ctxt *obj.Link, e float64) int {
func chipfloat5(ctxt *obj.Link, e float64) int { func chipfloat5(ctxt *obj.Link, e float64) int {
// We use GOARM=7 to gate the use of VFPv3 vmov (imm) instructions. // We use GOARM=7 to gate the use of VFPv3 vmov (imm) instructions.
if ctxt.Goarm < 7 { if obj.GOARM < 7 {
return -1 return -1
} }
......
...@@ -66,7 +66,7 @@ func progedit(ctxt *obj.Link, p *obj.Prog) { ...@@ -66,7 +66,7 @@ func progedit(ctxt *obj.Link, p *obj.Prog) {
ctxt.Diag("%v: TLS MRC instruction must write to R0 as it might get translated into a BL instruction", p.Line()) ctxt.Diag("%v: TLS MRC instruction must write to R0 as it might get translated into a BL instruction", p.Line())
} }
if ctxt.Goarm < 7 { if obj.GOARM < 7 {
// Replace it with BL runtime.read_tls_fallback(SB) for ARM CPUs that lack the tls extension. // Replace it with BL runtime.read_tls_fallback(SB) for ARM CPUs that lack the tls extension.
if progedit_tlsfallback == nil { if progedit_tlsfallback == nil {
progedit_tlsfallback = obj.Linklookup(ctxt, "runtime.read_tls_fallback", 0) progedit_tlsfallback = obj.Linklookup(ctxt, "runtime.read_tls_fallback", 0)
...@@ -626,7 +626,7 @@ func isfloatreg(a *obj.Addr) bool { ...@@ -626,7 +626,7 @@ func isfloatreg(a *obj.Addr) bool {
} }
func softfloat(ctxt *obj.Link, cursym *obj.LSym) { func softfloat(ctxt *obj.Link, cursym *obj.LSym) {
if ctxt.Goarm > 5 { if obj.GOARM > 5 {
return return
} }
......
...@@ -625,7 +625,6 @@ const ( ...@@ -625,7 +625,6 @@ const (
// Link holds the context for writing object code from a compiler // Link holds the context for writing object code from a compiler
// to be linker input or for reading that input into the linker. // to be linker input or for reading that input into the linker.
type Link struct { type Link struct {
Goarm int32
Headtype HeadType Headtype HeadType
Arch *LinkArch Arch *LinkArch
Debugasm int32 Debugasm int32
......
...@@ -567,7 +567,7 @@ func gendwarf(ctxt *Link, text []*LSym) []*LSym { ...@@ -567,7 +567,7 @@ func gendwarf(ctxt *Link, text []*LSym) []*LSym {
if ctxt.FixedFrameSize() == 0 { if ctxt.FixedFrameSize() == 0 {
offs -= int32(ctxt.Arch.PtrSize) offs -= int32(ctxt.Arch.PtrSize)
} }
if Framepointer_enabled(Getgoos(), Getgoarch()) { if Framepointer_enabled(GOOS, GOARCH) {
offs -= int32(ctxt.Arch.PtrSize) offs -= int32(ctxt.Arch.PtrSize)
} }
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
package obj package obj
import ( import (
"cmd/internal/sys"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
...@@ -43,7 +42,7 @@ func Linknew(arch *LinkArch) *Link { ...@@ -43,7 +42,7 @@ func Linknew(arch *LinkArch) *Link {
ctxt.Hash = make(map[SymVer]*LSym) ctxt.Hash = make(map[SymVer]*LSym)
ctxt.Arch = arch ctxt.Arch = arch
ctxt.Version = HistVersion ctxt.Version = HistVersion
ctxt.Goroot = Getgoroot() ctxt.Goroot = GOROOT
ctxt.Goroot_final = os.Getenv("GOROOT_FINAL") ctxt.Goroot_final = os.Getenv("GOROOT_FINAL")
var buf string var buf string
...@@ -54,22 +53,17 @@ func Linknew(arch *LinkArch) *Link { ...@@ -54,22 +53,17 @@ func Linknew(arch *LinkArch) *Link {
buf = filepath.ToSlash(buf) buf = filepath.ToSlash(buf)
ctxt.Pathname = buf ctxt.Pathname = buf
ctxt.LineHist.GOROOT = ctxt.Goroot ctxt.LineHist.GOROOT = GOROOT
ctxt.LineHist.GOROOT_FINAL = ctxt.Goroot_final ctxt.LineHist.GOROOT_FINAL = ctxt.Goroot_final
ctxt.LineHist.Dir = ctxt.Pathname ctxt.LineHist.Dir = ctxt.Pathname
ctxt.Headtype.Set(Getgoos()) ctxt.Headtype.Set(GOOS)
if ctxt.Headtype < 0 { if ctxt.Headtype < 0 {
log.Fatalf("unknown goos %s", Getgoos()) log.Fatalf("unknown goos %s", GOOS)
}
// On arm, record goarm.
if ctxt.Arch.Family == sys.ARM {
ctxt.Goarm = Getgoarm()
} }
ctxt.Flag_optimize = true ctxt.Flag_optimize = true
ctxt.Framepointer_enabled = Framepointer_enabled(Getgoos(), arch.Name) ctxt.Framepointer_enabled = Framepointer_enabled(GOOS, arch.Name)
return ctxt return ctxt
} }
......
...@@ -31,19 +31,16 @@ func envOr(key, value string) string { ...@@ -31,19 +31,16 @@ func envOr(key, value string) string {
return value return value
} }
func Getgoroot() string { var (
return envOr("GOROOT", defaultGOROOT) GOROOT = envOr("GOROOT", defaultGOROOT)
} GOARCH = envOr("GOARCH", defaultGOARCH)
GOOS = envOr("GOOS", defaultGOOS)
func Getgoarch() string { GO386 = envOr("GO386", defaultGO386)
return envOr("GOARCH", defaultGOARCH) GOARM = goarm()
} Version = version
)
func Getgoos() string {
return envOr("GOOS", defaultGOOS)
}
func Getgoarm() int32 { func goarm() int {
switch v := envOr("GOARM", defaultGOARM); v { switch v := envOr("GOARM", defaultGOARM); v {
case "5": case "5":
return 5 return 5
...@@ -57,19 +54,10 @@ func Getgoarm() int32 { ...@@ -57,19 +54,10 @@ func Getgoarm() int32 {
panic("unreachable") panic("unreachable")
} }
func Getgo386() string {
// Validated by cmd/compile.
return envOr("GO386", defaultGO386)
}
func Getgoextlinkenabled() string { func Getgoextlinkenabled() string {
return envOr("GO_EXTLINK_ENABLED", defaultGO_EXTLINK_ENABLED) return envOr("GO_EXTLINK_ENABLED", defaultGO_EXTLINK_ENABLED)
} }
func Getgoversion() string {
return version
}
func (p *Prog) Line() string { func (p *Prog) Line() string {
return p.Ctxt.LineHist.LineString(int(p.Lineno)) return p.Ctxt.LineHist.LineString(int(p.Lineno))
} }
...@@ -287,7 +275,7 @@ func Dconv(p *Prog, a *Addr) string { ...@@ -287,7 +275,7 @@ func Dconv(p *Prog, a *Addr) string {
case TYPE_SHIFT: case TYPE_SHIFT:
v := int(a.Offset) v := int(a.Offset)
ops := "<<>>->@>" ops := "<<>>->@>"
switch goarch := Getgoarch(); goarch { switch GOARCH {
case "arm": case "arm":
op := ops[((v>>5)&3)<<1:] op := ops[((v>>5)&3)<<1:]
if v&(1<<4) != 0 { if v&(1<<4) != 0 {
...@@ -302,7 +290,7 @@ func Dconv(p *Prog, a *Addr) string { ...@@ -302,7 +290,7 @@ func Dconv(p *Prog, a *Addr) string {
op := ops[((v>>22)&3)<<1:] op := ops[((v>>22)&3)<<1:]
str = fmt.Sprintf("R%d%c%c%d", (v>>16)&31, op[0], op[1], (v>>10)&63) str = fmt.Sprintf("R%d%c%c%d", (v>>16)&31, op[0], op[1], (v>>10)&63)
default: default:
panic("TYPE_SHIFT is not supported on " + goarch) panic("TYPE_SHIFT is not supported on " + GOARCH)
} }
case TYPE_REGREG: case TYPE_REGREG:
......
...@@ -2152,7 +2152,7 @@ func instinit() { ...@@ -2152,7 +2152,7 @@ func instinit() {
} }
} }
var isAndroid = (obj.Getgoos() == "android") var isAndroid = (obj.GOOS == "android")
func prefixof(ctxt *obj.Link, p *obj.Prog, a *obj.Addr) int { func prefixof(ctxt *obj.Link, p *obj.Prog, a *obj.Addr) int {
if a.Reg < REG_CS && a.Index < REG_CS { // fast path if a.Reg < REG_CS && a.Index < REG_CS { // fast path
......
...@@ -47,7 +47,7 @@ func Main() { ...@@ -47,7 +47,7 @@ func Main() {
func linkarchinit() { func linkarchinit() {
ld.SysArch = sys.ArchAMD64 ld.SysArch = sys.ArchAMD64
if obj.Getgoarch() == "amd64p32" { if obj.GOARCH == "amd64p32" {
ld.SysArch = sys.ArchAMD64P32 ld.SysArch = sys.ArchAMD64P32
} }
......
...@@ -165,7 +165,7 @@ func readArmap(filename string, f *bio.Reader, arhdr ArHdr) archiveMap { ...@@ -165,7 +165,7 @@ func readArmap(filename string, f *bio.Reader, arhdr ArHdr) archiveMap {
// For Mach-O and PE/386 files we strip a leading // For Mach-O and PE/386 files we strip a leading
// underscore from the symbol name. // underscore from the symbol name.
if goos == "darwin" || (goos == "windows" && goarch == "386") { if obj.GOOS == "darwin" || (obj.GOOS == "windows" && obj.GOARCH == "386") {
if name[0] == '_' && len(name) > 1 { if name[0] == '_' && len(name) > 1 {
name = name[1:] name = name[1:]
} }
......
...@@ -399,7 +399,7 @@ func relocsym(ctxt *Link, s *Symbol) { ...@@ -399,7 +399,7 @@ func relocsym(ctxt *Link, s *Symbol) {
} }
case obj.R_TLS_LE: case obj.R_TLS_LE:
isAndroidX86 := goos == "android" && (SysArch.InFamily(sys.AMD64, sys.I386)) isAndroidX86 := obj.GOOS == "android" && (SysArch.InFamily(sys.AMD64, sys.I386))
if Linkmode == LinkExternal && Iself && Headtype != obj.Hopenbsd && !isAndroidX86 { if Linkmode == LinkExternal && Iself && Headtype != obj.Hopenbsd && !isAndroidX86 {
r.Done = 0 r.Done = 0
...@@ -433,7 +433,7 @@ func relocsym(ctxt *Link, s *Symbol) { ...@@ -433,7 +433,7 @@ func relocsym(ctxt *Link, s *Symbol) {
} }
case obj.R_TLS_IE: case obj.R_TLS_IE:
isAndroidX86 := goos == "android" && (SysArch.InFamily(sys.AMD64, sys.I386)) isAndroidX86 := obj.GOOS == "android" && (SysArch.InFamily(sys.AMD64, sys.I386))
if Linkmode == LinkExternal && Iself && Headtype != obj.Hopenbsd && !isAndroidX86 { if Linkmode == LinkExternal && Iself && Headtype != obj.Hopenbsd && !isAndroidX86 {
r.Done = 0 r.Done = 0
......
...@@ -223,7 +223,7 @@ func (d *deadcodepass) init() { ...@@ -223,7 +223,7 @@ func (d *deadcodepass) init() {
if SysArch.Family == sys.ARM { if SysArch.Family == sys.ARM {
// mark some functions that are only referenced after linker code editing // mark some functions that are only referenced after linker code editing
if d.ctxt.Goarm == 5 { if obj.GOARM == 5 {
names = append(names, "_sfloat") names = append(names, "_sfloat")
} }
names = append(names, "runtime.read_tls_fallback") names = append(names, "runtime.read_tls_fallback")
......
...@@ -197,8 +197,6 @@ var ( ...@@ -197,8 +197,6 @@ var (
Segdwarf Segment Segdwarf Segment
) )
/* set by call to mywhatsys() */
/* whence for ldpkg */ /* whence for ldpkg */
const ( const (
FileObj = 0 + iota FileObj = 0 + iota
...@@ -237,9 +235,6 @@ var ( ...@@ -237,9 +235,6 @@ var (
// Set if we see an object compiled by the host compiler that is not // Set if we see an object compiled by the host compiler that is not
// from a package that is known to support internal linking mode. // from a package that is known to support internal linking mode.
externalobj = false externalobj = false
goroot string
goarch string
goos string
theline string theline string
) )
...@@ -262,7 +257,6 @@ func mayberemoveoutfile() { ...@@ -262,7 +257,6 @@ func mayberemoveoutfile() {
func libinit(ctxt *Link) { func libinit(ctxt *Link) {
Funcalign = Thearch.Funcalign Funcalign = Thearch.Funcalign
mywhatsys() // get goroot, goarch, goos
// add goroot to the end of the libdir list. // add goroot to the end of the libdir list.
suffix := "" suffix := ""
...@@ -279,7 +273,7 @@ func libinit(ctxt *Link) { ...@@ -279,7 +273,7 @@ func libinit(ctxt *Link) {
suffix = "msan" suffix = "msan"
} }
Lflag(ctxt, filepath.Join(goroot, "pkg", fmt.Sprintf("%s_%s%s%s", goos, goarch, suffixsep, suffix))) Lflag(ctxt, filepath.Join(obj.GOROOT, "pkg", fmt.Sprintf("%s_%s%s%s", obj.GOOS, obj.GOARCH, suffixsep, suffix)))
mayberemoveoutfile() mayberemoveoutfile()
f, err := os.OpenFile(*flagOutfile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0775) f, err := os.OpenFile(*flagOutfile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0775)
...@@ -293,9 +287,9 @@ func libinit(ctxt *Link) { ...@@ -293,9 +287,9 @@ func libinit(ctxt *Link) {
if *flagEntrySymbol == "" { if *flagEntrySymbol == "" {
switch Buildmode { switch Buildmode {
case BuildmodeCShared, BuildmodeCArchive: case BuildmodeCShared, BuildmodeCArchive:
*flagEntrySymbol = fmt.Sprintf("_rt0_%s_%s_lib", goarch, goos) *flagEntrySymbol = fmt.Sprintf("_rt0_%s_%s_lib", obj.GOARCH, obj.GOOS)
case BuildmodeExe, BuildmodePIE: case BuildmodeExe, BuildmodePIE:
*flagEntrySymbol = fmt.Sprintf("_rt0_%s_%s", goarch, goos) *flagEntrySymbol = fmt.Sprintf("_rt0_%s_%s", obj.GOARCH, obj.GOOS)
case BuildmodeShared: case BuildmodeShared:
// No *flagEntrySymbol for -buildmode=shared // No *flagEntrySymbol for -buildmode=shared
default: default:
...@@ -446,7 +440,7 @@ func (ctxt *Link) loadlib() { ...@@ -446,7 +440,7 @@ func (ctxt *Link) loadlib() {
} }
// Force external linking for android. // Force external linking for android.
if goos == "android" { if obj.GOOS == "android" {
Linkmode = LinkExternal Linkmode = LinkExternal
} }
...@@ -474,7 +468,7 @@ func (ctxt *Link) loadlib() { ...@@ -474,7 +468,7 @@ func (ctxt *Link) loadlib() {
// cmd/7l doesn't support cgo internal linking // cmd/7l doesn't support cgo internal linking
// This is https://golang.org/issue/10373. // This is https://golang.org/issue/10373.
// mips64x doesn't support cgo internal linking either (golang.org/issue/14449) // mips64x doesn't support cgo internal linking either (golang.org/issue/14449)
if iscgo && (goarch == "arm64" || goarch == "mips64" || goarch == "mips64le") { if iscgo && (obj.GOARCH == "arm64" || obj.GOARCH == "mips64" || obj.GOARCH == "mips64le") {
Linkmode = LinkExternal Linkmode = LinkExternal
} }
...@@ -543,10 +537,10 @@ func (ctxt *Link) loadlib() { ...@@ -543,10 +537,10 @@ func (ctxt *Link) loadlib() {
s := Linklookup(ctxt, "runtime.goarm", 0) s := Linklookup(ctxt, "runtime.goarm", 0)
s.Type = obj.SRODATA s.Type = obj.SRODATA
s.Size = 0 s.Size = 0
Adduint8(ctxt, s, uint8(ctxt.Goarm)) Adduint8(ctxt, s, uint8(obj.GOARM))
} }
if obj.Framepointer_enabled(obj.Getgoos(), obj.Getgoarch()) { if obj.Framepointer_enabled(obj.GOOS, obj.GOARCH) {
s := Linklookup(ctxt, "runtime.framepointer_enabled", 0) s := Linklookup(ctxt, "runtime.framepointer_enabled", 0)
s.Type = obj.SRODATA s.Type = obj.SRODATA
s.Size = 0 s.Size = 0
...@@ -1062,7 +1056,7 @@ func (l *Link) hostlink() { ...@@ -1062,7 +1056,7 @@ func (l *Link) hostlink() {
// only want to do this when producing a Windows output file // only want to do this when producing a Windows output file
// on a Windows host. // on a Windows host.
outopt := *flagOutfile outopt := *flagOutfile
if goos == "windows" && runtime.GOOS == "windows" && filepath.Ext(outopt) == "" { if obj.GOOS == "windows" && runtime.GOOS == "windows" && filepath.Ext(outopt) == "" {
outopt += "." outopt += "."
} }
argv = append(argv, "-o") argv = append(argv, "-o")
...@@ -1278,8 +1272,8 @@ func ldobj(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string, file ...@@ -1278,8 +1272,8 @@ func ldobj(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string, file
return nil return nil
} }
// First, check that the basic goos, goarch, and version match. // First, check that the basic GOOS, GOARCH, and Version match.
t := fmt.Sprintf("%s %s %s ", goos, obj.Getgoarch(), obj.Getgoversion()) t := fmt.Sprintf("%s %s %s ", obj.GOOS, obj.GOARCH, obj.Version)
line = strings.TrimRight(line, "\n") line = strings.TrimRight(line, "\n")
if !strings.HasPrefix(line[10:]+" ", t) && !*flagF { if !strings.HasPrefix(line[10:]+" ", t) && !*flagF {
...@@ -1503,12 +1497,6 @@ func ldshlibsyms(ctxt *Link, shlib string) { ...@@ -1503,12 +1497,6 @@ func ldshlibsyms(ctxt *Link, shlib string) {
ctxt.Shlibs = append(ctxt.Shlibs, Shlib{Path: libpath, Hash: hash, Deps: deps, File: f, gcdataAddresses: gcdataAddresses}) ctxt.Shlibs = append(ctxt.Shlibs, Shlib{Path: libpath, Hash: hash, Deps: deps, File: f, gcdataAddresses: gcdataAddresses})
} }
func mywhatsys() {
goroot = obj.Getgoroot()
goos = obj.Getgoos()
goarch = obj.Getgoarch()
}
// Copied from ../gc/subr.c:/^pathtoprefix; must stay in sync. // Copied from ../gc/subr.c:/^pathtoprefix; must stay in sync.
/* /*
* Convert raw string to the prefix that will be used in the symbol table. * Convert raw string to the prefix that will be used in the symbol table.
...@@ -1822,7 +1810,7 @@ func usage() { ...@@ -1822,7 +1810,7 @@ func usage() {
} }
func doversion() { func doversion() {
Exitf("version %s", obj.Getgoversion()) Exitf("version %s", obj.Version)
} }
func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, int, int64, int64, int, *Symbol)) { func genasmsym(ctxt *Link, put func(*Link, *Symbol, string, int, int64, int64, int, *Symbol)) {
......
...@@ -160,12 +160,10 @@ type Shlib struct { ...@@ -160,12 +160,10 @@ type Shlib struct {
} }
type Link struct { type Link struct {
Goarm int32
Arch *sys.Arch Arch *sys.Arch
Debugvlog int Debugvlog int
Bso *bufio.Writer Bso *bufio.Writer
Windows int32 Windows int32
Goroot string
// Symbol lookup based on name and indexed by version. // Symbol lookup based on name and indexed by version.
Hash []map[string]*Symbol Hash []map[string]*Symbol
......
...@@ -111,7 +111,7 @@ func Main() { ...@@ -111,7 +111,7 @@ func Main() {
} }
// TODO(matloob): define these above and then check flag values here // TODO(matloob): define these above and then check flag values here
if SysArch.Family == sys.AMD64 && obj.Getgoos() == "plan9" { if SysArch.Family == sys.AMD64 && obj.GOOS == "plan9" {
flag.BoolVar(&Flag8, "8", false, "use 64-bit addresses in symbol table") flag.BoolVar(&Flag8, "8", false, "use 64-bit addresses in symbol table")
} }
obj.Flagfn1("B", "add an ELF NT_GNU_BUILD_ID `note` when using ELF", addbuildinfo) obj.Flagfn1("B", "add an ELF NT_GNU_BUILD_ID `note` when using ELF", addbuildinfo)
...@@ -144,7 +144,7 @@ func Main() { ...@@ -144,7 +144,7 @@ func Main() {
libinit(ctxt) // creates outfile libinit(ctxt) // creates outfile
if Headtype == obj.Hunknown { if Headtype == obj.Hunknown {
Headtype.Set(obj.Getgoos()) Headtype.Set(obj.GOOS)
} }
ctxt.computeTLSOffset() ctxt.computeTLSOffset()
......
...@@ -374,7 +374,7 @@ func (ctxt *Link) pclntab() { ...@@ -374,7 +374,7 @@ func (ctxt *Link) pclntab() {
func expandGoroot(s string) string { func expandGoroot(s string) string {
const n = len("$GOROOT") const n = len("$GOROOT")
if len(s) >= n+1 && s[:n] == "$GOROOT" && (s[n] == '/' || s[n] == '\\') { if len(s) >= n+1 && s[:n] == "$GOROOT" && (s[n] == '/' || s[n] == '\\') {
root := goroot root := obj.GOROOT
if final := os.Getenv("GOROOT_FINAL"); final != "" { if final := os.Getenv("GOROOT_FINAL"); final != "" {
root = final root = final
} }
......
...@@ -876,9 +876,9 @@ func peemitreloc(ctxt *Link, text, data, ctors *IMAGE_SECTION_HEADER) { ...@@ -876,9 +876,9 @@ func peemitreloc(ctxt *Link, text, data, ctors *IMAGE_SECTION_HEADER) {
sectoff := ctors.VirtualAddress sectoff := ctors.VirtualAddress
Lputl(sectoff) Lputl(sectoff)
Lputl(uint32(dottext.Dynid)) Lputl(uint32(dottext.Dynid))
switch obj.Getgoarch() { switch obj.GOARCH {
default: default:
fmt.Fprintf(os.Stderr, "link: unknown architecture for PE: %q\n", obj.Getgoarch()) fmt.Fprintf(os.Stderr, "link: unknown architecture for PE: %q\n", obj.GOARCH)
os.Exit(2) os.Exit(2)
case "386": case "386":
Wputl(IMAGE_REL_I386_DIR32) Wputl(IMAGE_REL_I386_DIR32)
...@@ -1097,9 +1097,9 @@ func addinitarray(ctxt *Link) (c *IMAGE_SECTION_HEADER) { ...@@ -1097,9 +1097,9 @@ func addinitarray(ctxt *Link) (c *IMAGE_SECTION_HEADER) {
// However, the entire Go runtime is initialized from just one function, so it is unlikely // However, the entire Go runtime is initialized from just one function, so it is unlikely
// that this will need to grow in the future. // that this will need to grow in the future.
var size int var size int
switch obj.Getgoarch() { switch obj.GOARCH {
default: default:
fmt.Fprintf(os.Stderr, "link: unknown architecture for PE: %q\n", obj.Getgoarch()) fmt.Fprintf(os.Stderr, "link: unknown architecture for PE: %q\n", obj.GOARCH)
os.Exit(2) os.Exit(2)
case "386": case "386":
size = 4 size = 4
...@@ -1116,7 +1116,7 @@ func addinitarray(ctxt *Link) (c *IMAGE_SECTION_HEADER) { ...@@ -1116,7 +1116,7 @@ func addinitarray(ctxt *Link) (c *IMAGE_SECTION_HEADER) {
init_entry := Linklookup(ctxt, *flagEntrySymbol, 0) init_entry := Linklookup(ctxt, *flagEntrySymbol, 0)
addr := uint64(init_entry.Value) - init_entry.Sect.Vaddr addr := uint64(init_entry.Value) - init_entry.Sect.Vaddr
switch obj.Getgoarch() { switch obj.GOARCH {
case "386": case "386":
Lputl(uint32(addr)) Lputl(uint32(addr))
case "amd64": case "amd64":
......
...@@ -47,17 +47,10 @@ func linknew(arch *sys.Arch) *Link { ...@@ -47,17 +47,10 @@ func linknew(arch *sys.Arch) *Link {
}, },
Allsym: make([]*Symbol, 0, 100000), Allsym: make([]*Symbol, 0, 100000),
Arch: arch, Arch: arch,
Goroot: obj.Getgoroot(),
} }
p := obj.Getgoarch() if obj.GOARCH != arch.Name {
if p != arch.Name { log.Fatalf("invalid obj.GOARCH %s (want %s)", obj.GOARCH, arch.Name)
log.Fatalf("invalid goarch %s (want %s)", p, arch.Name)
}
// On arm, record goarm.
if ctxt.Arch.Family == sys.ARM {
ctxt.Goarm = obj.Getgoarm()
} }
return ctxt return ctxt
...@@ -83,7 +76,7 @@ func (ctxt *Link) computeTLSOffset() { ...@@ -83,7 +76,7 @@ func (ctxt *Link) computeTLSOffset() {
obj.Hopenbsd, obj.Hopenbsd,
obj.Hdragonfly, obj.Hdragonfly,
obj.Hsolaris: obj.Hsolaris:
if obj.Getgoos() == "android" { if obj.GOOS == "android" {
switch ctxt.Arch.Family { switch ctxt.Arch.Family {
case sys.AMD64: case sys.AMD64:
// Android/amd64 constant - offset from 0(FS) to our TLS slot. // Android/amd64 constant - offset from 0(FS) to our TLS slot.
...@@ -194,10 +187,8 @@ const ( ...@@ -194,10 +187,8 @@ const (
) )
func (mode *BuildMode) Set(s string) error { func (mode *BuildMode) Set(s string) error {
goos := obj.Getgoos()
goarch := obj.Getgoarch()
badmode := func() error { badmode := func() error {
return fmt.Errorf("buildmode %s not supported on %s/%s", s, goos, goarch) return fmt.Errorf("buildmode %s not supported on %s/%s", s, obj.GOOS, obj.GOARCH)
} }
switch s { switch s {
default: default:
...@@ -205,17 +196,17 @@ func (mode *BuildMode) Set(s string) error { ...@@ -205,17 +196,17 @@ func (mode *BuildMode) Set(s string) error {
case "exe": case "exe":
*mode = BuildmodeExe *mode = BuildmodeExe
case "pie": case "pie":
switch goos { switch obj.GOOS {
case "android", "linux": case "android", "linux":
default: default:
return badmode() return badmode()
} }
*mode = BuildmodePIE *mode = BuildmodePIE
case "c-archive": case "c-archive":
switch goos { switch obj.GOOS {
case "darwin", "linux": case "darwin", "linux":
case "windows": case "windows":
switch goarch { switch obj.GOARCH {
case "amd64", "386": case "amd64", "386":
default: default:
return badmode() return badmode()
...@@ -225,16 +216,16 @@ func (mode *BuildMode) Set(s string) error { ...@@ -225,16 +216,16 @@ func (mode *BuildMode) Set(s string) error {
} }
*mode = BuildmodeCArchive *mode = BuildmodeCArchive
case "c-shared": case "c-shared":
switch goarch { switch obj.GOARCH {
case "386", "amd64", "arm", "arm64": case "386", "amd64", "arm", "arm64":
default: default:
return badmode() return badmode()
} }
*mode = BuildmodeCShared *mode = BuildmodeCShared
case "shared": case "shared":
switch goos { switch obj.GOOS {
case "linux": case "linux":
switch goarch { switch obj.GOARCH {
case "386", "amd64", "arm", "arm64", "ppc64le", "s390x": case "386", "amd64", "arm", "arm64", "ppc64le", "s390x":
default: default:
return badmode() return badmode()
......
...@@ -46,7 +46,7 @@ func Main() { ...@@ -46,7 +46,7 @@ func Main() {
} }
func linkarchinit() { func linkarchinit() {
if obj.Getgoarch() == "mips64le" { if obj.GOARCH == "mips64le" {
ld.SysArch = sys.ArchMIPS64LE ld.SysArch = sys.ArchMIPS64LE
} else { } else {
ld.SysArch = sys.ArchMIPS64 ld.SysArch = sys.ArchMIPS64
......
...@@ -46,7 +46,7 @@ func Main() { ...@@ -46,7 +46,7 @@ func Main() {
} }
func linkarchinit() { func linkarchinit() {
if obj.Getgoarch() == "ppc64le" { if obj.GOARCH == "ppc64le" {
ld.SysArch = sys.ArchPPC64LE ld.SysArch = sys.ArchPPC64LE
} else { } else {
ld.SysArch = sys.ArchPPC64 ld.SysArch = sys.ArchPPC64
......
...@@ -18,9 +18,9 @@ import ( ...@@ -18,9 +18,9 @@ import (
) )
func main() { func main() {
switch obj.Getgoarch() { switch obj.GOARCH {
default: default:
fmt.Fprintf(os.Stderr, "link: unknown architecture %q\n", obj.Getgoarch()) fmt.Fprintf(os.Stderr, "link: unknown architecture %q\n", obj.GOARCH)
os.Exit(2) os.Exit(2)
case "386": case "386":
x86.Main() x86.Main()
......
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