]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: do not read .bss sections in ldpe
authorAlex Brainman <alex.brainman@gmail.com>
Thu, 4 May 2017 06:49:23 +0000 (16:49 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Fri, 5 May 2017 01:00:11 +0000 (01:00 +0000)
For .bss section symbol ldelf does not set P (raw symbol data).
Make ldpe do the same.

Change-Id: Ib3d558456f505ee568d0972465fa9b08b5794a87
Reviewed-on: https://go-review.googlesource.com/42631
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/ld/ldpe.go

index fd3664c2ed10a223bf187532b1399b14671a7e65..14f56d4b3c7824bd9431de441eb5f3082f825303 100644 (file)
@@ -162,12 +162,6 @@ func ldpeError(ctxt *Link, input *bio.Reader, pkg string, length int64, pn strin
                        continue
                }
 
-               data, err := sect.Data()
-               if err != nil {
-                       return err
-               }
-               sectdata[sect] = data
-
                name := fmt.Sprintf("%s(%s)", pkg, sect.Name)
                s := ctxt.Syms.Lookup(name, localSymVersion)
 
@@ -177,18 +171,6 @@ func ldpeError(ctxt *Link, input *bio.Reader, pkg string, length int64, pn strin
 
                case IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE: //.bss
                        s.Type = SNOPTRBSS
-                       // It seems like this shouldn't happen, but it does, with symbol "runtime/cgo(.bss)".
-                       // TODO: Figure out why and either document why it is ok or fix it at the source--
-                       // either by eliminating the all-zero data or
-                       // by making this SNOPTRDATA (IMAGE_SCN_CNT_INITIALIZED_DATA) to begin with.
-                       if len(data) > 0 {
-                               for _, x := range data {
-                                       if x != 0 {
-                                               Errorf(s, "non-zero data in .bss section: %q", data)
-                                       }
-                               }
-                               s.Type = SNOPTRDATA
-                       }
 
                case IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE: //.data
                        s.Type = SNOPTRDATA
@@ -200,8 +182,15 @@ func ldpeError(ctxt *Link, input *bio.Reader, pkg string, length int64, pn strin
                        return fmt.Errorf("unexpected flags %#06x for PE section %s", sect.Characteristics, sect.Name)
                }
 
-               s.P = data
-               s.Size = int64(len(data))
+               if s.Type != SNOPTRBSS {
+                       data, err := sect.Data()
+                       if err != nil {
+                               return err
+                       }
+                       sectdata[sect] = data
+                       s.P = data
+               }
+               s.Size = int64(sect.Size)
                sectsyms[sect] = s
                if sect.Name == ".rsrc" {
                        setpersrc(ctxt, s)