]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: move cgo export map from loadcgo to setCgoAttr
authorAustin Clements <austin@google.com>
Sun, 11 Apr 2021 21:29:17 +0000 (17:29 -0400)
committerAustin Clements <austin@google.com>
Tue, 13 Apr 2021 20:07:45 +0000 (20:07 +0000)
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>

src/cmd/link/internal/ld/go.go
src/cmd/link/internal/ld/util.go

index 8cbdd58b3a3dd3f41f3d996a70cf62c2fd53dd85..ec6ceb82ce731b26f5a1551d7e8206603a9a97be 100644 (file)
@@ -101,29 +101,6 @@ func loadcgo(ctxt *Link, file string, pkg string, p string) {
                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.
        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
                        }
 
+                       // Mark exported symbols and also add them to
+                       // the lists used for roots in the deadcode pass.
                        if f[0] == "cgo_export_static" {
                                l.SetAttrCgoExportStatic(s, true)
+                               ctxt.cgo_export_static[local] = true
                        } else {
                                l.SetAttrCgoExportDynamic(s, true)
+                               ctxt.cgo_export_dynamic[local] = true
                        }
+
                        continue
 
                case "cgo_dynamic_linker":
index 9228ed163d0fc3d8f98936196584905bf9660146..779f4988b68a3aa107843c063aff6297d17b04da 100644 (file)
@@ -57,7 +57,7 @@ func afterErrorAction() {
 // Logging an error means that on exit cmd/link will delete any
 // 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.
 func Errorf(dummy *int, format string, args ...interface{}) {
        format += "\n"