From ab08f79af3d41e28bf2ccf2f8738024a1404aeac Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Tue, 9 Jun 2015 16:16:42 +1000 Subject: [PATCH] cmd/link: stop linker crashing with -s flag on windows Update #10254 Change-Id: I3ddd26607813ca629e3ab62abf87dc5ab453e36f Reviewed-on: https://go-review.googlesource.com/10835 Reviewed-by: Ian Lance Taylor --- src/cmd/link/internal/ld/pe.go | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/cmd/link/internal/ld/pe.go b/src/cmd/link/internal/ld/pe.go index cb82c053d8..d5f7e62989 100644 --- a/src/cmd/link/internal/ld/pe.go +++ b/src/cmd/link/internal/ld/pe.go @@ -545,10 +545,6 @@ func initdynimport() *Dll { r.Off = 0 r.Siz = uint8(Thearch.Ptrsize) r.Type = obj.R_ADDR - - // pre-allocate symtab entries for those symbols - dynSym.Dynid = int32(ncoffsym) - ncoffsym++ } } } else { @@ -988,20 +984,25 @@ func addpesym(s *LSym, name string, type_ int, addr int64, size int64, ver int, ncoffsym++ } -func addpesymtable() { - if Debug['s'] == 0 { - genasmsym(addpesym) - coffsym = make([]COFFSym, ncoffsym) - ncoffsym = 0 - if Linkmode == LinkExternal { - for d := dr; d != nil; d = d.next { - for m := d.ms; m != nil; m = m.next { - s := m.s.R[0].Xsym - addpesym(s, s.Name, 'U', 0, int64(Thearch.Ptrsize), 0, nil) - } +func pegenasmsym(put func(*LSym, string, int, int64, int64, int, *LSym)) { + if Linkmode == LinkExternal { + for d := dr; d != nil; d = d.next { + for m := d.ms; m != nil; m = m.next { + s := m.s.R[0].Xsym + put(s, s.Name, 'U', 0, int64(Thearch.Ptrsize), 0, nil) } } - genasmsym(addpesym) + } + genasmsym(put) +} + +func addpesymtable() { + if Debug['s'] == 0 || Linkmode == LinkExternal { + ncoffsym = 0 + pegenasmsym(addpesym) + coffsym = make([]COFFSym, ncoffsym) + ncoffsym = 0 + pegenasmsym(addpesym) } size := len(strtbl) + 4 + 18*ncoffsym