本文整理匯總了Golang中cmd/internal/obj.Getgoroot函數的典型用法代碼示例。如果您正苦於以下問題:Golang Getgoroot函數的具體用法?Golang Getgoroot怎麽用?Golang Getgoroot使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Getgoroot函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: mywhatsys
func mywhatsys() {
goroot = obj.Getgoroot()
goos = obj.Getgoos()
goarch = obj.Getgoarch()
if !strings.HasPrefix(goarch, Thestring) {
log.Fatalf("cannot use %cc with GOARCH=%s", Thearch.Thechar, goarch)
}
}
示例2: linknew
func linknew(arch *LinkArch) *Link {
ctxt := &Link{
Hash: []map[string]*LSym{
// preallocate about 2mb for hash of
// non static symbols
make(map[string]*LSym, 100000),
},
Allsym: make([]*LSym, 0, 100000),
Arch: arch,
Goroot: obj.Getgoroot(),
}
p := obj.Getgoarch()
if p != arch.Name {
log.Fatalf("invalid goarch %s (want %s)", p, arch.Name)
}
ctxt.Headtype = headtype(obj.Getgoos())
if ctxt.Headtype < 0 {
log.Fatalf("unknown goos %s", obj.Getgoos())
}
// Record thread-local storage offset.
// TODO(rsc): Move tlsoffset back into the linker.
switch ctxt.Headtype {
default:
log.Fatalf("unknown thread-local storage offset for %s", Headstr(ctxt.Headtype))
case obj.Hplan9, obj.Hwindows:
break
/*
* ELF uses TLS offset negative from FS.
* Translate 0(FS) and 8(FS) into -16(FS) and -8(FS).
* Known to low-level assembly in package runtime and runtime/cgo.
*/
case obj.Hlinux,
obj.Hfreebsd,
obj.Hnetbsd,
obj.Hopenbsd,
obj.Hdragonfly,
obj.Hsolaris:
if obj.Getgoos() == "android" {
switch ctxt.Arch.Thechar {
case '6':
// Android/amd64 constant - offset from 0(FS) to our TLS slot.
// Explained in src/runtime/cgo/gcc_android_*.c
ctxt.Tlsoffset = 0x1d0
case '8':
// Android/386 constant - offset from 0(GS) to our TLS slot.
ctxt.Tlsoffset = 0xf8
default:
ctxt.Tlsoffset = -1 * ctxt.Arch.Ptrsize
}
} else {
ctxt.Tlsoffset = -1 * ctxt.Arch.Ptrsize
}
case obj.Hnacl:
switch ctxt.Arch.Thechar {
default:
log.Fatalf("unknown thread-local storage offset for nacl/%s", ctxt.Arch.Name)
case '5':
ctxt.Tlsoffset = 0
case '6':
ctxt.Tlsoffset = 0
case '8':
ctxt.Tlsoffset = -8
}
/*
* OS X system constants - offset from 0(GS) to our TLS.
* Explained in src/runtime/cgo/gcc_darwin_*.c.
*/
case obj.Hdarwin:
switch ctxt.Arch.Thechar {
default:
log.Fatalf("unknown thread-local storage offset for darwin/%s", ctxt.Arch.Name)
case '5':
ctxt.Tlsoffset = 0 // dummy value, not needed
case '6':
ctxt.Tlsoffset = 0x8a0
case '7':
ctxt.Tlsoffset = 0 // dummy value, not needed
case '8':
ctxt.Tlsoffset = 0x468
}
}
// On arm, record goarm.
if ctxt.Arch.Thechar == '5' {
ctxt.Goarm = obj.Getgoarm()
}
//.........這裏部分代碼省略.........
示例3: linknew
func linknew(arch *LinkArch) *Link {
ctxt := new(Link)
ctxt.Hash = make(map[symVer]*LSym)
ctxt.Arch = arch
ctxt.Version = obj.HistVersion
ctxt.Goroot = obj.Getgoroot()
p := obj.Getgoarch()
if p != arch.Name {
log.Fatalf("invalid goarch %s (want %s)", p, arch.Name)
}
var buf string
buf, _ = os.Getwd()
if buf == "" {
buf = "/???"
}
buf = filepath.ToSlash(buf)
ctxt.Headtype = headtype(obj.Getgoos())
if ctxt.Headtype < 0 {
log.Fatalf("unknown goos %s", obj.Getgoos())
}
// Record thread-local storage offset.
// TODO(rsc): Move tlsoffset back into the linker.
switch ctxt.Headtype {
default:
log.Fatalf("unknown thread-local storage offset for %s", Headstr(ctxt.Headtype))
case obj.Hplan9, obj.Hwindows:
break
/*
* ELF uses TLS offset negative from FS.
* Translate 0(FS) and 8(FS) into -16(FS) and -8(FS).
* Known to low-level assembly in package runtime and runtime/cgo.
*/
case obj.Hlinux,
obj.Hfreebsd,
obj.Hnetbsd,
obj.Hopenbsd,
obj.Hdragonfly,
obj.Hsolaris:
if obj.Getgoos() == "android" && ctxt.Arch.Thechar == '6' {
// Android/x86 constant - offset from 0(FS) to our
// TLS slot. Explained in src/runtime/cgo/gcc_android_*.c
ctxt.Tlsoffset = 0x1d0
} else {
ctxt.Tlsoffset = -1 * ctxt.Arch.Ptrsize
}
case obj.Hnacl:
switch ctxt.Arch.Thechar {
default:
log.Fatalf("unknown thread-local storage offset for nacl/%s", ctxt.Arch.Name)
case '5':
ctxt.Tlsoffset = 0
case '6':
ctxt.Tlsoffset = 0
case '8':
ctxt.Tlsoffset = -8
}
/*
* OS X system constants - offset from 0(GS) to our TLS.
* Explained in src/runtime/cgo/gcc_darwin_*.c.
*/
case obj.Hdarwin:
switch ctxt.Arch.Thechar {
default:
log.Fatalf("unknown thread-local storage offset for darwin/%s", ctxt.Arch.Name)
case '5':
ctxt.Tlsoffset = 0 // dummy value, not needed
case '6':
ctxt.Tlsoffset = 0x8a0
case '7':
ctxt.Tlsoffset = 0 // dummy value, not needed
case '8':
ctxt.Tlsoffset = 0x468
}
}
// On arm, record goarm.
if ctxt.Arch.Thechar == '5' {
ctxt.Goarm = obj.Getgoarm()
}
return ctxt
}
示例4: Main
func Main() {
defer hidePanic()
// Allow GOARCH=thearch.thestring or GOARCH=thearch.thestringsuffix,
// but not other values.
p := obj.Getgoarch()
if !strings.HasPrefix(p, Thearch.Thestring) {
log.Fatalf("cannot use %cg with GOARCH=%s", Thearch.Thechar, p)
}
goarch = p
Thearch.Linkarchinit()
Ctxt = obj.Linknew(Thearch.Thelinkarch)
Ctxt.Diag = Yyerror
Ctxt.Bso = &bstdout
bstdout = *obj.Binitw(os.Stdout)
localpkg = mkpkg("")
localpkg.Prefix = "\"\""
// pseudo-package, for scoping
builtinpkg = mkpkg("go.builtin")
builtinpkg.Prefix = "go.builtin" // not go%2ebuiltin
// pseudo-package, accessed by import "unsafe"
unsafepkg = mkpkg("unsafe")
unsafepkg.Name = "unsafe"
// real package, referred to by generated runtime calls
Runtimepkg = mkpkg("runtime")
Runtimepkg.Name = "runtime"
// pseudo-packages used in symbol tables
gostringpkg = mkpkg("go.string")
gostringpkg.Name = "go.string"
gostringpkg.Prefix = "go.string" // not go%2estring
itabpkg = mkpkg("go.itab")
itabpkg.Name = "go.itab"
itabpkg.Prefix = "go.itab" // not go%2eitab
weaktypepkg = mkpkg("go.weak.type")
weaktypepkg.Name = "go.weak.type"
weaktypepkg.Prefix = "go.weak.type" // not go%2eweak%2etype
typelinkpkg = mkpkg("go.typelink")
typelinkpkg.Name = "go.typelink"
typelinkpkg.Prefix = "go.typelink" // not go%2etypelink
trackpkg = mkpkg("go.track")
trackpkg.Name = "go.track"
trackpkg.Prefix = "go.track" // not go%2etrack
typepkg = mkpkg("type")
typepkg.Name = "type"
goroot = obj.Getgoroot()
goos = obj.Getgoos()
Nacl = goos == "nacl"
if Nacl {
flag_largemodel = 1
}
outfile = ""
obj.Flagcount("+", "compiling runtime", &compiling_runtime)
obj.Flagcount("%", "debug non-static initializers", &Debug['%'])
obj.Flagcount("A", "for bootstrapping, allow 'any' type", &Debug['A'])
obj.Flagcount("B", "disable bounds checking", &Debug['B'])
obj.Flagstr("D", "path: set relative path for local imports", &localimport)
obj.Flagcount("E", "debug symbol export", &Debug['E'])
obj.Flagfn1("I", "dir: add dir to import search path", addidir)
obj.Flagcount("K", "debug missing line numbers", &Debug['K'])
obj.Flagcount("L", "use full (long) path in error messages", &Debug['L'])
obj.Flagcount("M", "debug move generation", &Debug['M'])
obj.Flagcount("N", "disable optimizations", &Debug['N'])
obj.Flagcount("P", "debug peephole optimizer", &Debug['P'])
obj.Flagcount("R", "debug register optimizer", &Debug['R'])
obj.Flagcount("S", "print assembly listing", &Debug['S'])
obj.Flagfn0("V", "print compiler version", doversion)
obj.Flagcount("W", "debug parse tree after type checking", &Debug['W'])
obj.Flagstr("asmhdr", "file: write assembly header to named file", &asmhdr)
obj.Flagcount("complete", "compiling complete package (no C or assembly)", &pure_go)
obj.Flagstr("d", "list: print debug information about items in list", &debugstr)
obj.Flagcount("e", "no limit on number of errors reported", &Debug['e'])
obj.Flagcount("f", "debug stack frames", &Debug['f'])
obj.Flagcount("g", "debug code generation", &Debug['g'])
obj.Flagcount("h", "halt on error", &Debug['h'])
obj.Flagcount("i", "debug line number stack", &Debug['i'])
obj.Flagstr("installsuffix", "pkg directory suffix", &flag_installsuffix)
obj.Flagcount("j", "debug runtime-initialized variables", &Debug['j'])
//.........這裏部分代碼省略.........
示例5: Main
func Main() {
defer hidePanic()
// Allow GOARCH=thearch.thestring or GOARCH=thearch.thestringsuffix,
// but not other values.
p := obj.Getgoarch()
if !strings.HasPrefix(p, Thearch.Thestring) {
log.Fatalf("cannot use %cg with GOARCH=%s", Thearch.Thechar, p)
}
goarch = p
Thearch.Linkarchinit()
Ctxt = obj.Linknew(Thearch.Thelinkarch)
Ctxt.DiagFunc = Yyerror
Ctxt.Bso = &bstdout
bstdout = *obj.Binitw(os.Stdout)
localpkg = mkpkg("")
localpkg.Prefix = "\"\""
// pseudo-package, for scoping
builtinpkg = mkpkg("go.builtin")
builtinpkg.Prefix = "go.builtin" // not go%2ebuiltin
// pseudo-package, accessed by import "unsafe"
unsafepkg = mkpkg("unsafe")
unsafepkg.Name = "unsafe"
// real package, referred to by generated runtime calls
Runtimepkg = mkpkg("runtime")
Runtimepkg.Name = "runtime"
// pseudo-packages used in symbol tables
gostringpkg = mkpkg("go.string")
gostringpkg.Name = "go.string"
gostringpkg.Prefix = "go.string" // not go%2estring
itabpkg = mkpkg("go.itab")
itabpkg.Name = "go.itab"
itabpkg.Prefix = "go.itab" // not go%2eitab
weaktypepkg = mkpkg("go.weak.type")
weaktypepkg.Name = "go.weak.type"
weaktypepkg.Prefix = "go.weak.type" // not go%2eweak%2etype
typelinkpkg = mkpkg("go.typelink")
typelinkpkg.Name = "go.typelink"
typelinkpkg.Prefix = "go.typelink" // not go%2etypelink
trackpkg = mkpkg("go.track")
trackpkg.Name = "go.track"
trackpkg.Prefix = "go.track" // not go%2etrack
typepkg = mkpkg("type")
typepkg.Name = "type"
goroot = obj.Getgoroot()
goos = obj.Getgoos()
Nacl = goos == "nacl"
if Nacl {
flag_largemodel = 1
}
outfile = ""
obj.Flagcount("+", "compiling runtime", &compiling_runtime)
obj.Flagcount("%", "debug non-static initializers", &Debug['%'])
obj.Flagcount("A", "for bootstrapping, allow 'any' type", &Debug['A'])
obj.Flagcount("B", "disable bounds checking", &Debug['B'])
obj.Flagstr("D", "set relative `path` for local imports", &localimport)
obj.Flagcount("E", "debug symbol export", &Debug['E'])
obj.Flagfn1("I", "add `directory` to import search path", addidir)
obj.Flagcount("K", "debug missing line numbers", &Debug['K'])
obj.Flagcount("L", "use full (long) path in error messages", &Debug['L'])
obj.Flagcount("M", "debug move generation", &Debug['M'])
obj.Flagcount("N", "disable optimizations", &Debug['N'])
obj.Flagcount("P", "debug peephole optimizer", &Debug['P'])
obj.Flagcount("R", "debug register optimizer", &Debug['R'])
obj.Flagcount("S", "print assembly listing", &Debug['S'])
obj.Flagfn0("V", "print compiler version", doversion)
obj.Flagcount("W", "debug parse tree after type checking", &Debug['W'])
obj.Flagstr("asmhdr", "write assembly header to `file`", &asmhdr)
obj.Flagstr("buildid", "record `id` as the build id in the export metadata", &buildid)
obj.Flagcount("complete", "compiling complete package (no C or assembly)", &pure_go)
obj.Flagstr("d", "print debug information about items in `list`", &debugstr)
obj.Flagcount("e", "no limit on number of errors reported", &Debug['e'])
obj.Flagcount("f", "debug stack frames", &Debug['f'])
obj.Flagcount("g", "debug code generation", &Debug['g'])
obj.Flagcount("h", "halt on error", &Debug['h'])
obj.Flagcount("i", "debug line number stack", &Debug['i'])
obj.Flagfn1("importmap", "add `definition` of the form source=actual to import map", addImportMap)
//.........這裏部分代碼省略.........
示例6: Main
func Main() {
defer hidePanic()
goarch = obj.Getgoarch()
Ctxt = obj.Linknew(Thearch.LinkArch)
Ctxt.DiagFunc = Yyerror
bstdout = bufio.NewWriter(os.Stdout)
Ctxt.Bso = bstdout
localpkg = mkpkg("")
localpkg.Prefix = "\"\""
autopkg = mkpkg("")
autopkg.Prefix = "\"\""
// pseudo-package, for scoping
builtinpkg = mkpkg("go.builtin")
builtinpkg.Prefix = "go.builtin" // not go%2ebuiltin
// pseudo-package, accessed by import "unsafe"
unsafepkg = mkpkg("unsafe")
unsafepkg.Name = "unsafe"
// real package, referred to by generated runtime calls
Runtimepkg = mkpkg("runtime")
Runtimepkg.Name = "runtime"
// pseudo-packages used in symbol tables
itabpkg = mkpkg("go.itab")
itabpkg.Name = "go.itab"
itabpkg.Prefix = "go.itab" // not go%2eitab
itablinkpkg = mkpkg("go.itablink")
itablinkpkg.Name = "go.itablink"
itablinkpkg.Prefix = "go.itablink" // not go%2eitablink
trackpkg = mkpkg("go.track")
trackpkg.Name = "go.track"
trackpkg.Prefix = "go.track" // not go%2etrack
typepkg = mkpkg("type")
typepkg.Name = "type"
// pseudo-package used for map zero values
mappkg = mkpkg("go.map")
mappkg.Name = "go.map"
mappkg.Prefix = "go.map"
goroot = obj.Getgoroot()
goos = obj.Getgoos()
Nacl = goos == "nacl"
if Nacl {
flag_largemodel = true
}
flag.BoolVar(&compiling_runtime, "+", false, "compiling runtime")
obj.Flagcount("%", "debug non-static initializers", &Debug['%'])
obj.Flagcount("A", "for bootstrapping, allow 'any' type", &Debug['A'])
obj.Flagcount("B", "disable bounds checking", &Debug['B'])
flag.StringVar(&localimport, "D", "", "set relative `path` for local imports")
obj.Flagcount("E", "debug symbol export", &Debug['E'])
obj.Flagfn1("I", "add `directory` to import search path", addidir)
obj.Flagcount("K", "debug missing line numbers", &Debug['K'])
obj.Flagcount("M", "debug move generation", &Debug['M'])
obj.Flagcount("N", "disable optimizations", &Debug['N'])
obj.Flagcount("P", "debug peephole optimizer", &Debug['P'])
obj.Flagcount("R", "debug register optimizer", &Debug['R'])
obj.Flagcount("S", "print assembly listing", &Debug['S'])
obj.Flagfn0("V", "print compiler version", doversion)
obj.Flagcount("W", "debug parse tree after type checking", &Debug['W'])
flag.StringVar(&asmhdr, "asmhdr", "", "write assembly header to `file`")
flag.StringVar(&buildid, "buildid", "", "record `id` as the build id in the export metadata")
flag.BoolVar(&pure_go, "complete", false, "compiling complete package (no C or assembly)")
flag.StringVar(&debugstr, "d", "", "print debug information about items in `list`")
obj.Flagcount("e", "no limit on number of errors reported", &Debug['e'])
obj.Flagcount("f", "debug stack frames", &Debug['f'])
obj.Flagcount("g", "debug code generation", &Debug['g'])
obj.Flagcount("h", "halt on error", &Debug['h'])
obj.Flagcount("i", "debug line number stack", &Debug['i'])
obj.Flagfn1("importmap", "add `definition` of the form source=actual to import map", addImportMap)
flag.StringVar(&flag_installsuffix, "installsuffix", "", "set pkg directory `suffix`")
obj.Flagcount("j", "debug runtime-initialized variables", &Debug['j'])
obj.Flagcount("l", "disable inlining", &Debug['l'])
flag.StringVar(&linkobj, "linkobj", "", "write linker-specific object to `file`")
obj.Flagcount("live", "debug liveness analysis", &debuglive)
obj.Flagcount("m", "print optimization decisions", &Debug['m'])
flag.BoolVar(&flag_msan, "msan", false, "build code compatible with C/C++ memory sanitizer")
flag.BoolVar(&newexport, "newexport", true, "use new export format") // TODO(gri) remove eventually (issue 15323)
flag.BoolVar(&nolocalimports, "nolocalimports", false, "reject local (relative) imports")
flag.StringVar(&outfile, "o", "", "write output to `file`")
flag.StringVar(&myimportpath, "p", "", "set expected package import `path`")
flag.BoolVar(&writearchive, "pack", false, "write package file instead of object file")
obj.Flagcount("r", "debug generated wrappers", &Debug['r'])
flag.BoolVar(&flag_race, "race", false, "enable race detector")
obj.Flagcount("s", "warn about composite literals that can be simplified", &Debug['s'])
flag.StringVar(&Ctxt.LineHist.TrimPathPrefix, "trimpath", "", "remove `prefix` from recorded source file paths")
flag.BoolVar(&safemode, "u", false, "reject unsafe code")
obj.Flagcount("v", "increase debug verbosity", &Debug['v'])
obj.Flagcount("w", "debug type checking", &Debug['w'])
//.........這裏部分代碼省略.........