Commit b32170ab authored by Alex Brainman's avatar Alex Brainman

cmd/link: simplify peemitreloc

No functional changes.

For #10776.

Change-Id: If9a5ef832af116c5802b06a38e0c050d7363f2d5
Reviewed-on: https://go-review.googlesource.com/36981
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent d0a978f5
...@@ -854,72 +854,68 @@ func perelocsect(ctxt *Link, sect *Section, syms []*Symbol) int { ...@@ -854,72 +854,68 @@ func perelocsect(ctxt *Link, sect *Section, syms []*Symbol) int {
return relocs return relocs
} }
// peemitreloc emits relocation entries for go.o in external linking. // peemitsectreloc emits the relocation entries for sect.
func peemitreloc(ctxt *Link, text, data, ctors *IMAGE_SECTION_HEADER) { // The actual relocations are emitted by relocfn.
for coutbuf.Offset()&7 != 0 { // This updates the corresponding PE section table entry
Cput(0) // with the relocation offset and count.
} func peemitsectreloc(sect *IMAGE_SECTION_HEADER, relocfn func() int) {
sect.PointerToRelocations = uint32(coutbuf.Offset())
text.PointerToRelocations = uint32(coutbuf.Offset())
// first entry: extended relocs // first entry: extended relocs
Lputl(0) // placeholder for number of relocation + 1 Lputl(0) // placeholder for number of relocation + 1
Lputl(0) Lputl(0)
Wputl(0) Wputl(0)
n := perelocsect(ctxt, Segtext.Sect, ctxt.Textp) + 1 n := relocfn() + 1
for sect := Segtext.Sect.Next; sect != nil; sect = sect.Next {
n += perelocsect(ctxt, sect, datap)
}
cpos := coutbuf.Offset() cpos := coutbuf.Offset()
Cseek(int64(text.PointerToRelocations)) Cseek(int64(sect.PointerToRelocations))
Lputl(uint32(n)) Lputl(uint32(n))
Cseek(cpos) Cseek(cpos)
if n > 0x10000 { if n > 0x10000 {
n = 0x10000 n = 0x10000
text.Characteristics |= IMAGE_SCN_LNK_NRELOC_OVFL sect.Characteristics |= IMAGE_SCN_LNK_NRELOC_OVFL
} else { } else {
text.PointerToRelocations += 10 // skip the extend reloc entry sect.PointerToRelocations += 10 // skip the extend reloc entry
} }
text.NumberOfRelocations = uint16(n - 1) sect.NumberOfRelocations = uint16(n - 1)
}
data.PointerToRelocations = uint32(cpos)
// first entry: extended relocs
Lputl(0) // placeholder for number of relocation + 1
Lputl(0)
Wputl(0)
n = 1 // peemitreloc emits relocation entries for go.o in external linking.
for sect := Segdata.Sect; sect != nil; sect = sect.Next { func peemitreloc(ctxt *Link, text, data, ctors *IMAGE_SECTION_HEADER) {
n += perelocsect(ctxt, sect, datap) for coutbuf.Offset()&7 != 0 {
Cput(0)
} }
cpos = coutbuf.Offset() peemitsectreloc(text, func() int {
Cseek(int64(data.PointerToRelocations)) n := perelocsect(ctxt, Segtext.Sect, ctxt.Textp)
Lputl(uint32(n)) for sect := Segtext.Sect.Next; sect != nil; sect = sect.Next {
Cseek(cpos) n += perelocsect(ctxt, sect, datap)
if n > 0x10000 { }
n = 0x10000 return n
data.Characteristics |= IMAGE_SCN_LNK_NRELOC_OVFL })
} else {
data.PointerToRelocations += 10 // skip the extend reloc entry
}
data.NumberOfRelocations = uint16(n - 1)
dottext := ctxt.Syms.Lookup(".text", 0) peemitsectreloc(data, func() int {
ctors.NumberOfRelocations = 1 var n int
ctors.PointerToRelocations = uint32(coutbuf.Offset()) for sect := Segdata.Sect; sect != nil; sect = sect.Next {
Lputl(0) n += perelocsect(ctxt, sect, datap)
Lputl(uint32(dottext.Dynid)) }
switch obj.GOARCH { return n
default: })
fmt.Fprintf(os.Stderr, "link: unknown architecture for PE: %q\n", obj.GOARCH)
os.Exit(2) peemitsectreloc(ctors, func() int {
case "386": dottext := ctxt.Syms.Lookup(".text", 0)
Wputl(IMAGE_REL_I386_DIR32) Lputl(0)
case "amd64": Lputl(uint32(dottext.Dynid))
Wputl(IMAGE_REL_AMD64_ADDR64) switch obj.GOARCH {
} default:
Errorf(dottext, "unknown architecture for PE: %q\n", obj.GOARCH)
case "386":
Wputl(IMAGE_REL_I386_DIR32)
case "amd64":
Wputl(IMAGE_REL_AMD64_ADDR64)
}
return 1
})
} }
func (ctxt *Link) dope() { func (ctxt *Link) dope() {
......
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