From b5e964cc1cfb9307285c7f18f51beca8124f1b22 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Tue, 2 May 2017 16:03:45 +1000 Subject: [PATCH] cmd/link: make sure that runtime.epclntab lives in .text section 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 TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/link/internal/ld/pe.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/cmd/link/internal/ld/pe.go b/src/cmd/link/internal/ld/pe.go index 2c28ceb0c6..a64975cbe6 100644 --- a/src/cmd/link/internal/ld/pe.go +++ b/src/cmd/link/internal/ld/pe.go @@ -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 { -- 2.50.0