]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: move asmb2 plan 9 architecture code out of architectures
authorJeremy Faller <jeremy@golang.org>
Fri, 22 May 2020 00:20:26 +0000 (20:20 -0400)
committerJeremy Faller <jeremy@golang.org>
Tue, 26 May 2020 17:55:53 +0000 (17:55 +0000)
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>
src/cmd/link/internal/amd64/asm.go
src/cmd/link/internal/amd64/obj.go
src/cmd/link/internal/arm/asm.go
src/cmd/link/internal/arm/obj.go
src/cmd/link/internal/ld/asmb.go
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/x86/asm.go
src/cmd/link/internal/x86/obj.go

index 849095d07d2a7cb84e65e5b4a76d3fc2502da541..e111c164a15176e1f6d6b2c3503266fcb1e8536a 100644 (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,
index 90de67d08662ab41504ebf27476e8cf43417a2a9..924ce58aa35d29fac773cea0789ed45785d8de08 100644 (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,
index 3515a60ea754f5b230a295a3e9672ac7bbff7f5d..3212268faba54612aeffb8ac7aa6ec64aa2c31f8 100644 (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))
-       }
-}
index c70b10e75d1a9b5fce0ade20061c854db6d87878..151445ecda8aeb3eee357f8781b5b3b32c704b24 100644 (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,
index aebd1d2ceb24f4f9ebe74b8464c951418bbda8ff..b6237d35c3edb4c31d5c2bbbd7e165f2cfd1b79a 100644 (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.IsAIX() || ctxt.IsWasm() {
+               return false
+       }
+
+       Symsize = 0
+       Spsize = 0
+       Lcsize = 0
+
        if ctxt.IsDarwin() {
                machlink := Domacholink(ctxt)
-               Symsize = 0
-               Spsize = 0
-               Lcsize = 0
                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.
index d8621c7db176e28809971e36c5a33bab716bab8a..5c047c84ee9f8e208d1e4cfd501edb62257e5f1d 100644 (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
index 746661a0288114990ed38549604d08f7d104f3f1..d5ac40c5832246c49ea314ed5dc67dcc22d299ec 100644 (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)
-}
index b604c1f8c2db2507423d55adcb2294f7b730de26..9239e71032afce0935be725d2b3cbf04adbe4573 100644 (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,