]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: delay calculating pe file parameters after Linkmode is set
authorAlex Brainman <alex.brainman@gmail.com>
Tue, 14 Feb 2017 01:01:01 +0000 (12:01 +1100)
committerAlex Brainman <alex.brainman@gmail.com>
Thu, 16 Feb 2017 04:35:36 +0000 (04:35 +0000)
For #10776.

Change-Id: Id64a7e35c7cdcd9be16cbe3358402fa379090e36
Reviewed-on: https://go-review.googlesource.com/36975
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/link/internal/amd64/obj.go
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/ld/pe.go
src/cmd/link/internal/x86/obj.go

index 1ecade890666793efa0b5b6443b1353ea812e1bb..52ea8ffe0fbdf3a46d190bd0a2c5f81d6aaa8168 100644 (file)
@@ -142,18 +142,8 @@ func archinit(ctxt *ld.Link) {
                }
 
        case obj.Hwindows, obj.Hwindowsgui: /* PE executable */
-               ld.Peinit(ctxt)
-
-               ld.HEADR = ld.PEFILEHEADR
-               if *ld.FlagTextAddr == -1 {
-                       *ld.FlagTextAddr = ld.PEBASE + int64(ld.PESECTHEADR)
-               }
-               if *ld.FlagDataAddr == -1 {
-                       *ld.FlagDataAddr = 0
-               }
-               if *ld.FlagRound == -1 {
-                       *ld.FlagRound = int(ld.PESECTALIGN)
-               }
+               // ld.HEADR, ld.FlagTextAddr, ld.FlagDataAddr and ld.FlagRound are set in ld.Peinit
+               return
        }
 
        if *ld.FlagDataAddr != 0 && *ld.FlagRound != 0 {
index 74d79d394c641fa59bf174825f5a3514b3a085fe..7f056826c8a8bd17abc35f9bb42e712e9d229e28 100644 (file)
@@ -430,6 +430,11 @@ func (ctxt *Link) loadlib() {
        // We now have enough information to determine the link mode.
        determineLinkMode(ctxt)
 
+       // Recalculate pe parameters now that we have Linkmode set.
+       if Headtype == obj.Hwindows || Headtype == obj.Hwindowsgui {
+               Peinit(ctxt)
+       }
+
        if Linkmode == LinkExternal && SysArch.Family == sys.PPC64 {
                toc := ctxt.Syms.Lookup(".TOC.", 0)
                toc.Type = obj.SDYNIMPORT
index e3ebc3ae28705cc17eb3817d82fbe15bfc06b722..6a1c19520c79e9d0ee1faedfd037d59e49fb68ea 100644 (file)
@@ -455,6 +455,20 @@ func Peinit(ctxt *Link) {
        ctxt.xdefine("__image_base__", obj.SDATA, PEBASE)
 
        ctxt.xdefine("_image_base__", obj.SDATA, PEBASE)
+
+       HEADR = PEFILEHEADR
+       if *FlagTextAddr == -1 {
+               *FlagTextAddr = PEBASE + int64(PESECTHEADR)
+       }
+       if *FlagDataAddr == -1 {
+               *FlagDataAddr = 0
+       }
+       if *FlagRound == -1 {
+               *FlagRound = int(PESECTALIGN)
+       }
+       if *FlagDataAddr != 0 && *FlagRound != 0 {
+               fmt.Printf("warning: -D0x%x is ignored because of -R0x%x\n", uint64(*FlagDataAddr), uint32(*FlagRound))
+       }
 }
 
 func pewrite() {
index 8ae351df9767c8ea35de37ea2a5552e52a21eba9..ba1dfcd4d05b8c97426c5e7ff4a6ca2daf0eaa47 100644 (file)
@@ -134,18 +134,8 @@ func archinit(ctxt *ld.Link) {
                }
 
        case obj.Hwindows, obj.Hwindowsgui: /* PE executable */
-               ld.Peinit(ctxt)
-
-               ld.HEADR = ld.PEFILEHEADR
-               if *ld.FlagTextAddr == -1 {
-                       *ld.FlagTextAddr = ld.PEBASE + int64(ld.PESECTHEADR)
-               }
-               if *ld.FlagDataAddr == -1 {
-                       *ld.FlagDataAddr = 0
-               }
-               if *ld.FlagRound == -1 {
-                       *ld.FlagRound = int(ld.PESECTALIGN)
-               }
+               // ld.HEADR, ld.FlagTextAddr, ld.FlagDataAddr and ld.FlagRound are set in ld.Peinit
+               return
        }
 
        if *ld.FlagDataAddr != 0 && *ld.FlagRound != 0 {