Commit a7e25562 authored by Alex Brainman's avatar Alex Brainman

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/36976Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent a37f9d8a
......@@ -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)
}
......
......@@ -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:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment