Commit 6738c494 authored by David Crawshaw's avatar David Crawshaw

cmd/link: move FlagLinkshared global to ctxt

For #22095

Change-Id: Ica6b3391541fe5a0355620d7c4a5107cf53eee82
Reviewed-on: https://go-review.googlesource.com/70833
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarDaniel Martí <mvdan@mvdan.cc>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 89ccfe49
...@@ -208,7 +208,7 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) { ...@@ -208,7 +208,7 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) {
case BuildModeShared: case BuildModeShared:
return true, "buildmode=shared" return true, "buildmode=shared"
} }
if *FlagLinkshared { if ctxt.linkShared {
return true, "dynamically linking with a shared library" return true, "dynamically linking with a shared library"
} }
......
...@@ -1206,7 +1206,7 @@ func (ctxt *Link) dodata() { ...@@ -1206,7 +1206,7 @@ func (ctxt *Link) dodata() {
checkdatsize(ctxt, datsize, sym.SNOPTRDATA) checkdatsize(ctxt, datsize, sym.SNOPTRDATA)
sect.Length = uint64(datsize) - sect.Vaddr sect.Length = uint64(datsize) - sect.Vaddr
hasinitarr := *FlagLinkshared hasinitarr := ctxt.linkShared
/* shared library initializer */ /* shared library initializer */
switch ctxt.BuildMode { switch ctxt.BuildMode {
......
...@@ -217,7 +217,7 @@ func (d *deadcodepass) init() { ...@@ -217,7 +217,7 @@ func (d *deadcodepass) init() {
// In a normal binary, start at main.main and the init // In a normal binary, start at main.main and the init
// functions and mark what is reachable from there. // functions and mark what is reachable from there.
if *FlagLinkshared && (d.ctxt.BuildMode == BuildModeExe || d.ctxt.BuildMode == BuildModePIE) { if d.ctxt.linkShared && (d.ctxt.BuildMode == BuildModeExe || d.ctxt.BuildMode == BuildModePIE) {
names = append(names, "main.main", "main.init") names = append(names, "main.main", "main.init")
} else { } else {
// The external linker refers main symbol directly. // The external linker refers main symbol directly.
......
...@@ -1502,7 +1502,7 @@ func (ctxt *Link) doelf() { ...@@ -1502,7 +1502,7 @@ func (ctxt *Link) doelf() {
} }
} }
hasinitarr := *FlagLinkshared hasinitarr := ctxt.linkShared
/* shared library initializer */ /* shared library initializer */
switch ctxt.BuildMode { switch ctxt.BuildMode {
......
...@@ -103,7 +103,7 @@ func findlib(ctxt *Link, lib string) (string, bool) { ...@@ -103,7 +103,7 @@ func findlib(ctxt *Link, lib string) (string, bool) {
var pname string var pname string
isshlib := false isshlib := false
if *FlagLinkshared && ctxt.PackageShlib[name] != "" { if ctxt.linkShared && ctxt.PackageShlib[name] != "" {
pname = ctxt.PackageShlib[name] pname = ctxt.PackageShlib[name]
isshlib = true isshlib = true
} else if ctxt.PackageFile != nil { } else if ctxt.PackageFile != nil {
...@@ -129,7 +129,7 @@ func findlib(ctxt *Link, lib string) (string, bool) { ...@@ -129,7 +129,7 @@ func findlib(ctxt *Link, lib string) (string, bool) {
} }
// try dot, -L "libdir", and then goroot. // try dot, -L "libdir", and then goroot.
for _, dir := range ctxt.Libdir { for _, dir := range ctxt.Libdir {
if *FlagLinkshared { if ctxt.linkShared {
pname = dir + "/" + pkg + ".shlibname" pname = dir + "/" + pkg + ".shlibname"
if _, err := os.Stat(pname); err == nil { if _, err := os.Stat(pname); err == nil {
isshlib = true isshlib = true
......
...@@ -141,7 +141,7 @@ func (ctxt *Link) DynlinkingGo() bool { ...@@ -141,7 +141,7 @@ func (ctxt *Link) DynlinkingGo() bool {
if !ctxt.Loaded { if !ctxt.Loaded {
panic("DynlinkingGo called before all symbols loaded") panic("DynlinkingGo called before all symbols loaded")
} }
return ctxt.BuildMode == BuildModeShared || *FlagLinkshared || ctxt.BuildMode == BuildModePlugin || ctxt.CanUsePlugins() return ctxt.BuildMode == BuildModeShared || ctxt.linkShared || ctxt.BuildMode == BuildModePlugin || ctxt.CanUsePlugins()
} }
// CanUsePlugins returns whether a plugins can be used // CanUsePlugins returns whether a plugins can be used
...@@ -156,7 +156,7 @@ func (ctxt *Link) UseRelro() bool { ...@@ -156,7 +156,7 @@ func (ctxt *Link) UseRelro() bool {
case BuildModeCArchive, BuildModeCShared, BuildModeShared, BuildModePIE, BuildModePlugin: case BuildModeCArchive, BuildModeCShared, BuildModeShared, BuildModePIE, BuildModePlugin:
return Iself return Iself
default: default:
return *FlagLinkshared return ctxt.linkShared
} }
} }
...@@ -270,7 +270,7 @@ func errorexit() { ...@@ -270,7 +270,7 @@ func errorexit() {
} }
func loadinternal(ctxt *Link, name string) *sym.Library { func loadinternal(ctxt *Link, name string) *sym.Library {
if *FlagLinkshared && ctxt.PackageShlib != nil { if ctxt.linkShared && ctxt.PackageShlib != nil {
if shlib := ctxt.PackageShlib[name]; shlib != "" { if shlib := ctxt.PackageShlib[name]; shlib != "" {
return addlibpath(ctxt, "internal", "internal", "", name, shlib) return addlibpath(ctxt, "internal", "internal", "", name, shlib)
} }
...@@ -284,7 +284,7 @@ func loadinternal(ctxt *Link, name string) *sym.Library { ...@@ -284,7 +284,7 @@ func loadinternal(ctxt *Link, name string) *sym.Library {
} }
for i := 0; i < len(ctxt.Libdir); i++ { for i := 0; i < len(ctxt.Libdir); i++ {
if *FlagLinkshared { if ctxt.linkShared {
shlibname := filepath.Join(ctxt.Libdir[i], name+".shlibname") shlibname := filepath.Join(ctxt.Libdir[i], name+".shlibname")
if ctxt.Debugvlog != 0 { if ctxt.Debugvlog != 0 {
ctxt.Logf("searching for %s.a in %s\n", name, shlibname) ctxt.Logf("searching for %s.a in %s\n", name, shlibname)
...@@ -404,7 +404,7 @@ func (ctxt *Link) loadlib() { ...@@ -404,7 +404,7 @@ func (ctxt *Link) loadlib() {
if lib.Shlib != "" { if lib.Shlib != "" {
ldshlibsyms(ctxt, lib.Shlib) ldshlibsyms(ctxt, lib.Shlib)
} else { } else {
if ctxt.BuildMode == BuildModeShared || *FlagLinkshared { if ctxt.BuildMode == BuildModeShared || ctxt.linkShared {
Exitf("cannot implicitly include runtime/cgo in a shared library") Exitf("cannot implicitly include runtime/cgo in a shared library")
} }
loadobjfile(ctxt, lib) loadobjfile(ctxt, lib)
...@@ -655,7 +655,7 @@ func (ctxt *Link) loadlib() { ...@@ -655,7 +655,7 @@ func (ctxt *Link) loadlib() {
// those programs loaded dynamically in multiple parts need these // those programs loaded dynamically in multiple parts need these
// symbols to have entries in the symbol table. // symbols to have entries in the symbol table.
func typeSymbolMangling(ctxt *Link) bool { func typeSymbolMangling(ctxt *Link) bool {
return ctxt.BuildMode == BuildModeShared || *FlagLinkshared || ctxt.BuildMode == BuildModePlugin || ctxt.Syms.ROLookup("plugin.Open", 0) != nil return ctxt.BuildMode == BuildModeShared || ctxt.linkShared || ctxt.BuildMode == BuildModePlugin || ctxt.Syms.ROLookup("plugin.Open", 0) != nil
} }
// typeSymbolMangle mangles the given symbol name into something shorter. // typeSymbolMangle mangles the given symbol name into something shorter.
...@@ -1218,7 +1218,7 @@ func (ctxt *Link) hostlink() { ...@@ -1218,7 +1218,7 @@ func (ctxt *Link) hostlink() {
argv = append(argv, filepath.Join(*flagTmpdir, "go.o")) argv = append(argv, filepath.Join(*flagTmpdir, "go.o"))
argv = append(argv, hostobjCopy()...) argv = append(argv, hostobjCopy()...)
if *FlagLinkshared { if ctxt.linkShared {
seenDirs := make(map[string]bool) seenDirs := make(map[string]bool)
seenLibs := make(map[string]bool) seenLibs := make(map[string]bool)
addshlib := func(path string) { addshlib := func(path string) {
......
...@@ -60,6 +60,7 @@ type Link struct { ...@@ -60,6 +60,7 @@ type Link struct {
Loaded bool // set after all inputs have been loaded as symbols Loaded bool // set after all inputs have been loaded as symbols
linkShared bool // link against installed Go shared libraries
LinkMode LinkMode LinkMode LinkMode
BuildMode BuildMode BuildMode BuildMode
......
...@@ -57,7 +57,6 @@ var ( ...@@ -57,7 +57,6 @@ var (
flagOutfile = flag.String("o", "", "write output to `file`") flagOutfile = flag.String("o", "", "write output to `file`")
flagPluginPath = flag.String("pluginpath", "", "full path name for plugin") flagPluginPath = flag.String("pluginpath", "", "full path name for plugin")
FlagLinkshared = flag.Bool("linkshared", false, "link against installed Go shared libraries")
flagInstallSuffix = flag.String("installsuffix", "", "set package directory `suffix`") flagInstallSuffix = flag.String("installsuffix", "", "set package directory `suffix`")
flagDumpDep = flag.Bool("dumpdep", false, "dump symbol dependency graph") flagDumpDep = flag.Bool("dumpdep", false, "dump symbol dependency graph")
...@@ -116,6 +115,7 @@ func Main(arch *sys.Arch, theArch Arch) { ...@@ -116,6 +115,7 @@ func Main(arch *sys.Arch, theArch Arch) {
if ctxt.Arch.Family == sys.AMD64 && objabi.GOOS == "plan9" { if ctxt.Arch.Family == sys.AMD64 && objabi.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")
} }
flag.BoolVar(&ctxt.linkShared, "linkshared", false, "link against installed Go shared libraries")
flag.Var(&ctxt.LinkMode, "linkmode", "set link `mode`") flag.Var(&ctxt.LinkMode, "linkmode", "set link `mode`")
flag.Var(&ctxt.BuildMode, "buildmode", "set build `mode`") flag.Var(&ctxt.BuildMode, "buildmode", "set build `mode`")
objabi.Flagfn1("B", "add an ELF NT_GNU_BUILD_ID `note` when using ELF", addbuildinfo) objabi.Flagfn1("B", "add an ELF NT_GNU_BUILD_ID `note` when using ELF", addbuildinfo)
...@@ -166,7 +166,7 @@ func Main(arch *sys.Arch, theArch Arch) { ...@@ -166,7 +166,7 @@ func Main(arch *sys.Arch, theArch Arch) {
ctxt.computeTLSOffset() ctxt.computeTLSOffset()
Thearch.Archinit(ctxt) Thearch.Archinit(ctxt)
if *FlagLinkshared && !Iself { if ctxt.linkShared && !Iself {
Exitf("-linkshared can only be used on elf systems") Exitf("-linkshared can only be used on elf systems")
} }
......
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