1
0
mirror of https://github.com/golang/go synced 2024-09-30 17:28:32 -06:00

[dev.link] cmd/link: move asmb2 plan 9 architecture code out of architectures

Change-Id: I7a8f8edc4511e3ae0c44ec5017167f14d4c60755
Reviewed-on: https://go-review.googlesource.com/c/go/+/234891
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Jeremy Faller 2020-05-21 20:20:26 -04:00
parent 13c1401b8e
commit ebdb15f7f8
8 changed files with 44 additions and 106 deletions

View File

@ -679,41 +679,6 @@ func addgotsym(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loade
}
}
func asmb2(ctxt *ld.Link, _ *loader.Loader) {
if ctxt.IsDarwin() {
panic("darwin should be generic")
}
if ctxt.IsElf() {
panic("elf should be generic")
}
if ctxt.IsWindows() {
panic("pe should be generic")
}
switch ctxt.HeadType {
default:
ld.Errorf(nil, "unknown header type %v", ctxt.HeadType)
fallthrough
case objabi.Hplan9:
break
}
ld.Symsize = 0
ld.Spsize = 0
ld.Lcsize = 0
if !*ld.FlagS {
*ld.FlagS = true
symo := int64(ld.Segdata.Fileoff + ld.Segdata.Filelen)
ctxt.Out.SeekSet(symo)
ld.Asmplan9sym(ctxt)
}
ctxt.Out.SeekSet(0)
magic := uint32(4*26*26 + 7)
ld.WritePlan9Header(ctxt.Out, magic, ld.Entryvalue(ctxt), true)
}
func tlsIEtoLE(P []byte, off, size int) {
// Transform the PC-relative instruction into a constant load.
// That is,

View File

@ -53,11 +53,13 @@ func Init() (*sys.Arch, ld.Arch) {
// 0xCC is INT $3 - breakpoint instruction
CodePad: []byte{0xCC},
Plan9Magic: uint32(4*26*26 + 7),
Plan9_64Bit: true,
Adddynrel: adddynrel,
Archinit: archinit,
Archreloc: archreloc,
Archrelocvariant: archrelocvariant,
Asmb2: asmb2,
Elfreloc1: elfreloc1,
Elfsetupplt: elfsetupplt,
Gentext: gentext,

View File

@ -670,32 +670,3 @@ func addgotsym(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loade
ldr.Errorf(s, "addgotsym: unsupported binary format")
}
}
func asmb2(ctxt *ld.Link, _ *loader.Loader) {
if ctxt.IsElf() {
panic("elf should be generic")
}
if ctxt.IsWindows() {
panic("pe should be generic")
}
/* output symbol table */
ld.Symsize = 0
ld.Lcsize = 0
if !*ld.FlagS {
symo := uint32(ld.Segdata.Fileoff + ld.Segdata.Filelen)
ctxt.Out.SeekSet(int64(symo))
ld.Asmplan9sym(ctxt)
}
ld.WritePlan9Header(ctxt.Out, 0x647, ld.Entryvalue(ctxt), false)
if *ld.FlagC {
fmt.Printf("textsize=%d\n", ld.Segtext.Filelen)
fmt.Printf("datsize=%d\n", ld.Segdata.Filelen)
fmt.Printf("bsssize=%d\n", ld.Segdata.Length-ld.Segdata.Filelen)
fmt.Printf("symsize=%d\n", ld.Symsize)
fmt.Printf("lcsize=%d\n", ld.Lcsize)
fmt.Printf("total=%d\n", ld.Segtext.Filelen+ld.Segdata.Length+uint64(ld.Symsize)+uint64(ld.Lcsize))
}
}

View File

@ -46,12 +46,13 @@ func Init() (*sys.Arch, ld.Arch) {
Dwarfregsp: dwarfRegSP,
Dwarfreglr: dwarfRegLR,
Plan9Magic: 0x647,
Adddynrel: adddynrel,
Archinit: archinit,
Archreloc: archreloc,
Archrelocvariant: archrelocvariant,
Trampoline: trampoline,
Asmb2: asmb2,
Elfreloc1: elfreloc1,
Elfsetupplt: elfsetupplt,
Gentext: gentext,

View File

@ -6,6 +6,7 @@ package ld
import (
"cmd/link/internal/loader"
"fmt"
"sync"
)
@ -74,12 +75,16 @@ func asmb(ctxt *Link, ldr *loader.Loader) {
// - writing out the architecture specific pieces.
// This function handles the second part.
func asmb2(ctxt *Link) bool {
// TODO: Spsize is only used for plan9
if ctxt.IsDarwin() {
machlink := Domacholink(ctxt)
if ctxt.IsAIX() || ctxt.IsWasm() {
return false
}
Symsize = 0
Spsize = 0
Lcsize = 0
if ctxt.IsDarwin() {
machlink := Domacholink(ctxt)
if !*FlagS && ctxt.IsExternal() {
symo := int64(Segdwarf.Fileoff + uint64(Rnd(int64(Segdwarf.Filelen), int64(*FlagRound))) + uint64(machlink))
ctxt.Out.SeekSet(symo)
@ -87,12 +92,9 @@ func asmb2(ctxt *Link) bool {
}
ctxt.Out.SeekSet(0)
Asmbmacho(ctxt)
return true
}
if ctxt.IsElf() {
Symsize = 0
Spsize = 0
Lcsize = 0
var symo int64
if !*FlagS {
symo = int64(Segdwarf.Fileoff + Segdwarf.Filelen)
@ -106,16 +108,33 @@ func asmb2(ctxt *Link) bool {
}
ctxt.Out.SeekSet(0)
Asmbelf(ctxt, symo)
return true
}
if ctxt.IsWindows() {
Symsize = 0
Spsize = 0
Lcsize = 0
Asmbpe(ctxt)
return true
}
return false
if ctxt.IsPlan9() {
if !*FlagS {
*FlagS = true
symo := int64(Segdata.Fileoff + Segdata.Filelen)
ctxt.Out.SeekSet(symo)
Asmplan9sym(ctxt)
}
ctxt.Out.SeekSet(0)
WritePlan9Header(ctxt.Out, thearch.Plan9Magic, Entryvalue(ctxt), thearch.Plan9_64Bit)
}
if *FlagC {
fmt.Printf("textsize=%d\n", Segtext.Filelen)
fmt.Printf("datsize=%d\n", Segdata.Filelen)
fmt.Printf("bsssize=%d\n", Segdata.Length-Segdata.Filelen)
fmt.Printf("symsize=%d\n", Symsize)
fmt.Printf("lcsize=%d\n", Lcsize)
fmt.Printf("total=%d\n", Segtext.Filelen+Segdata.Length+uint64(Symsize)+uint64(Lcsize))
}
return true
}
// WritePlan9Header writes out the plan9 header at the present position in the OutBuf.

View File

@ -195,6 +195,10 @@ type Arch struct {
// Set to true to write all text blocks in with CodeBlkWrite
WriteTextBlocks bool
// Plan 9 variables.
Plan9Magic uint32
Plan9_64Bit bool
Adddynrel func(*Target, *loader.Loader, *ArchSyms, loader.Sym, loader.Reloc2, int) bool
Archinit func(*Link)
// Archreloc is an arch-specific hook that assists in relocation processing

View File

@ -509,28 +509,3 @@ func addgotsym(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, s loade
ldr.Errorf(s, "addgotsym: unsupported binary format")
}
}
func asmb2(ctxt *ld.Link, _ *loader.Loader) {
if ctxt.IsDarwin() {
panic("darwin should be generic")
}
if ctxt.IsElf() {
panic("elf should be generic")
}
if ctxt.IsWindows() {
panic("pe should be generic")
}
ld.Symsize = 0
ld.Spsize = 0
ld.Lcsize = 0
if !*ld.FlagS {
symo := uint32(ld.Segdata.Fileoff + ld.Segdata.Filelen)
ctxt.Out.SeekSet(int64(symo))
ld.Asmplan9sym(ctxt)
}
ctxt.Out.SeekSet(0)
magic := uint32(4*11*11 + 7)
ld.WritePlan9Header(ctxt.Out, magic, ld.Entryvalue(ctxt), false)
}

View File

@ -48,11 +48,12 @@ func Init() (*sys.Arch, ld.Arch) {
// 0xCC is INT $3 - breakpoint instruction
CodePad: []byte{0xCC},
Plan9Magic: uint32(4*11*11 + 7),
Adddynrel: adddynrel,
Archinit: archinit,
Archreloc: archreloc,
Archrelocvariant: archrelocvariant,
Asmb2: asmb2,
Elfreloc1: elfreloc1,
Elfsetupplt: elfsetupplt,
Gentext: gentext,