mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/link: move cgo export map from loadcgo to setCgoAttr
Currently, both loadcgo and setCgoAttr do some processing of cgo_export_static and cgo_export_dynamic cgo directives, which means they both have to parse them. There's no reason to do this in loadcgo, so move all directive processing to setCgoAttr. For #40724. Change-Id: Icb3cdf7ef3517e866dd220e40a5f5dec7fd47e2b Reviewed-on: https://go-review.googlesource.com/c/go/+/309339 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
6208b10d1e
commit
007e247af1
2 changed files with 6 additions and 24 deletions
|
|
@ -101,29 +101,6 @@ func loadcgo(ctxt *Link, file string, pkg string, p string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find cgo_export symbols. They are roots in the deadcode pass.
|
|
||||||
for _, f := range directives {
|
|
||||||
switch f[0] {
|
|
||||||
case "cgo_export_static", "cgo_export_dynamic":
|
|
||||||
if len(f) < 2 || len(f) > 3 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
local := f[1]
|
|
||||||
switch ctxt.BuildMode {
|
|
||||||
case BuildModeCShared, BuildModeCArchive, BuildModePlugin:
|
|
||||||
if local == "main" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
local = expandpkg(local, pkg)
|
|
||||||
if f[0] == "cgo_export_static" {
|
|
||||||
ctxt.cgo_export_static[local] = true
|
|
||||||
} else {
|
|
||||||
ctxt.cgo_export_dynamic[local] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Record the directives. We'll process them later after Symbols are created.
|
// Record the directives. We'll process them later after Symbols are created.
|
||||||
ctxt.cgodata = append(ctxt.cgodata, cgodata{file, pkg, directives})
|
ctxt.cgodata = append(ctxt.cgodata, cgodata{file, pkg, directives})
|
||||||
}
|
}
|
||||||
|
|
@ -254,11 +231,16 @@ func setCgoAttr(ctxt *Link, file string, pkg string, directives [][]string, host
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mark exported symbols and also add them to
|
||||||
|
// the lists used for roots in the deadcode pass.
|
||||||
if f[0] == "cgo_export_static" {
|
if f[0] == "cgo_export_static" {
|
||||||
l.SetAttrCgoExportStatic(s, true)
|
l.SetAttrCgoExportStatic(s, true)
|
||||||
|
ctxt.cgo_export_static[local] = true
|
||||||
} else {
|
} else {
|
||||||
l.SetAttrCgoExportDynamic(s, true)
|
l.SetAttrCgoExportDynamic(s, true)
|
||||||
|
ctxt.cgo_export_dynamic[local] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
case "cgo_dynamic_linker":
|
case "cgo_dynamic_linker":
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ func afterErrorAction() {
|
||||||
// Logging an error means that on exit cmd/link will delete any
|
// Logging an error means that on exit cmd/link will delete any
|
||||||
// output file and return a non-zero error code.
|
// output file and return a non-zero error code.
|
||||||
//
|
//
|
||||||
// TODO: remove. Use ctxt.Errof instead.
|
// TODO: remove. Use ctxt.Errorf instead.
|
||||||
// All remaining calls use nil as first arg.
|
// All remaining calls use nil as first arg.
|
||||||
func Errorf(dummy *int, format string, args ...interface{}) {
|
func Errorf(dummy *int, format string, args ...interface{}) {
|
||||||
format += "\n"
|
format += "\n"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue