]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: don't emit default entry symbol in some situations
authorHiroshi Ioka <hirochachacha@gmail.com>
Wed, 21 Jun 2017 09:35:38 +0000 (18:35 +0900)
committerIan Lance Taylor <iant@golang.org>
Mon, 14 Aug 2017 05:28:22 +0000 (05:28 +0000)
Also, fix comment.

Change-Id: Ieb7ba21f34730dc51ab45a652d225e4145d4b861
Reviewed-on: https://go-review.googlesource.com/54870
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/link/internal/ld/deadcode.go

index dbb96fb77fab7046a13a0ba8f3417e8139dd9b4f..119e406080b291da41fe96895a19ec9e5b6500c0 100644 (file)
@@ -215,18 +215,29 @@ func (d *deadcodepass) init() {
        } else {
                // In a normal binary, start at main.main and the init
                // functions and mark what is reachable from there.
-               names = append(names, *flagEntrySymbol)
+
                if *FlagLinkshared && (Buildmode == BuildmodeExe || Buildmode == BuildmodePIE) {
                        names = append(names, "main.main", "main.init")
-               } else if Buildmode == BuildmodePlugin {
-                       names = append(names, *flagPluginPath+".init", *flagPluginPath+".main", "go.plugin.tabs")
+               } else {
+                       // The external linker refers main symbol directly.
+                       if Linkmode == LinkExternal && (Buildmode == BuildmodeExe || Buildmode == BuildmodePIE) {
+                               if Headtype == objabi.Hwindows && SysArch.Family == sys.I386 {
+                                       *flagEntrySymbol = "_main"
+                               } else {
+                                       *flagEntrySymbol = "main"
+                               }
+                       }
+                       names = append(names, *flagEntrySymbol)
+                       if Buildmode == BuildmodePlugin {
+                               names = append(names, *flagPluginPath+".init", *flagPluginPath+".main", "go.plugin.tabs")
 
-                       // We don't keep the go.plugin.exports symbol,
-                       // but we do keep the symbols it refers to.
-                       exports := d.ctxt.Syms.ROLookup("go.plugin.exports", 0)
-                       if exports != nil {
-                               for _, r := range exports.R {
-                                       d.mark(r.Sym, nil)
+                               // We don't keep the go.plugin.exports symbol,
+                               // but we do keep the symbols it refers to.
+                               exports := d.ctxt.Syms.ROLookup("go.plugin.exports", 0)
+                               if exports != nil {
+                                       for _, r := range exports.R {
+                                               d.mark(r.Sym, nil)
+                                       }
                                }
                        }
                }
@@ -240,7 +251,7 @@ func (d *deadcodepass) init() {
        }
 }
 
-// flood flood fills symbols reachable from the markQueue symbols.
+// flood fills symbols reachable from the markQueue symbols.
 // As it goes, it collects methodref and interface method declarations.
 func (d *deadcodepass) flood() {
        for len(d.markQueue) > 0 {