1
0
mirror of https://github.com/golang/go synced 2024-11-18 15:44:41 -07:00

cmd/link: set VirtualAddress to 0 for external linker

This is what gcc does when it generates object files.
And pecoff.doc says: "for simplicity, compilers should
 set this to zero". It is easier to count everything,
when it starts from 0. Make go linker do the same.

For #10776.

Change-Id: Iffa4b3ad86160624ed34adf1c6ba13feba34c658
Reviewed-on: https://go-review.googlesource.com/36976
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Alex Brainman 2017-02-06 15:18:26 +11:00
parent a37f9d8a17
commit a7e2556255
2 changed files with 7 additions and 6 deletions

View File

@ -656,9 +656,6 @@ func relocsym(ctxt *Link, s *Symbol) {
// PE/COFF's PC32 relocation uses the address after the relocated
// bytes as the base. Compensate by skewing the addend.
o += int64(r.Siz)
// GNU ld always add VirtualAddress of the .text section to the
// relocated address, compensate that.
o -= int64(s.Sect.Vaddr - PEBASE)
} else {
Errorf(s, "unhandled pcrel relocation to %s on %v", rs.Name, Headtype)
}

View File

@ -485,6 +485,11 @@ func pewrite() {
} else {
binary.Write(&coutbuf, binary.LittleEndian, &oh)
}
if Linkmode == LinkExternal {
for i := range sh[:pensect] {
sh[i].VirtualAddress = 0
}
}
binary.Write(&coutbuf, binary.LittleEndian, sh[:pensect])
}
@ -828,7 +833,7 @@ func perelocsect(ctxt *Link, sect *Section, syms []*Symbol) int {
if r.Xsym.Dynid < 0 {
Errorf(sym, "reloc %d to non-coff symbol %s (outer=%s) %d", r.Type, r.Sym.Name, r.Xsym.Name, r.Sym.Type)
}
if !Thearch.PEreloc1(sym, r, int64(uint64(sym.Value+int64(r.Off))-PEBASE)) {
if !Thearch.PEreloc1(sym, r, int64(uint64(sym.Value+int64(r.Off))-sect.Seg.Vaddr)) {
Errorf(sym, "unsupported obj reloc %d/%d to %s", r.Type, r.Siz, r.Sym.Name)
}
@ -896,8 +901,7 @@ func peemitreloc(ctxt *Link, text, data, ctors *IMAGE_SECTION_HEADER) {
dottext := ctxt.Syms.Lookup(".text", 0)
ctors.NumberOfRelocations = 1
ctors.PointerToRelocations = uint32(coutbuf.Offset())
sectoff := ctors.VirtualAddress
Lputl(sectoff)
Lputl(0)
Lputl(uint32(dottext.Dynid))
switch obj.GOARCH {
default: