]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: make sure that runtime.epclntab lives in .text section
authorAlex Brainman <alex.brainman@gmail.com>
Tue, 2 May 2017 06:03:45 +0000 (16:03 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Thu, 18 May 2017 05:32:41 +0000 (05:32 +0000)
Second attempt to fix #14710.

CL 35272 already tried to fix this issue. But CL 35272 assumed
that runtime.epclntab type is STEXT, while it is actually SRODATA.

This CL uses Symbol.Sect.Seg to determine if symbol is part
of Segtext or Segdata.

Fixes #14710

Change-Id: Ic6b6f657555c87a64d2bc36cc4c07ab0591d00c4
Reviewed-on: https://go-review.googlesource.com/42390
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/pe.go

index 2c28ceb0c60de7221d1ff8f5fe949f513f7bedf8..a64975cbe6e2c2e3ec67937062b59fff2a512fe1 100644 (file)
@@ -1016,17 +1016,17 @@ func writePESymTableRecords(ctxt *Link) int {
                typ := uint16(IMAGE_SYM_TYPE_NULL)
                var sect int
                var value int64
-               // Note: although address of runtime.edata (type SDATA) is at the start of .bss section
-               // it still belongs to the .data section, not the .bss section.
-               // Same for runtime.epclntab (type STEXT), it belongs to .text
-               // section, not the .data section.
-               if uint64(s.Value) >= Segdata.Vaddr+Segdata.Filelen && s.Type != SDATA && Linkmode == LinkExternal {
-                       value = int64(uint64(s.Value) - Segdata.Vaddr - Segdata.Filelen)
-                       sect = bsssect
-               } else if uint64(s.Value) >= Segdata.Vaddr && s.Type != STEXT {
-                       value = int64(uint64(s.Value) - Segdata.Vaddr)
-                       sect = datasect
-               } else if uint64(s.Value) >= Segtext.Vaddr {
+               if s.Sect != nil && s.Sect.Seg == &Segdata {
+                       // Note: although address of runtime.edata (type SDATA) is at the start of .bss section
+                       // it still belongs to the .data section, not the .bss section.
+                       if uint64(s.Value) >= Segdata.Vaddr+Segdata.Filelen && s.Type != SDATA && Linkmode == LinkExternal {
+                               value = int64(uint64(s.Value) - Segdata.Vaddr - Segdata.Filelen)
+                               sect = bsssect
+                       } else {
+                               value = int64(uint64(s.Value) - Segdata.Vaddr)
+                               sect = datasect
+                       }
+               } else if s.Sect != nil && s.Sect.Seg == &Segtext {
                        value = int64(uint64(s.Value) - Segtext.Vaddr)
                        sect = textsect
                } else if type_ == UndefinedSym {