]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: add support for GOARCH=mips{,le}
authorVladimir Stefanovic <vladimir.stefanovic@imgtec.com>
Tue, 18 Oct 2016 21:50:47 +0000 (23:50 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 8 Nov 2016 19:58:09 +0000 (19:58 +0000)
Only internal linking without cgo is supported for now.

Change-Id: I772d2ba496a613c78bee7e93f29e9538e6407bdc
Reviewed-on: https://go-review.googlesource.com/31481
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/link/internal/ld/elf.go
src/cmd/link/internal/mips/asm.go [new file with mode: 0644]
src/cmd/link/internal/mips/l.go [new file with mode: 0644]
src/cmd/link/internal/mips/obj.go [new file with mode: 0644]

index bfd449847b7612435d2df4703cd8a96a512102e4..b4d5aae27a683d0a1a4490fa091010f13dfd47f4 100644 (file)
@@ -2199,7 +2199,7 @@ func Asmbelf(ctxt *Link, symo int64) {
        switch SysArch.Family {
        default:
                Exitf("unknown architecture in asmbelf: %v", SysArch.Family)
-       case sys.MIPS64:
+       case sys.MIPS, sys.MIPS64:
                eh.machine = EM_MIPS
        case sys.ARM:
                eh.machine = EM_ARM
diff --git a/src/cmd/link/internal/mips/asm.go b/src/cmd/link/internal/mips/asm.go
new file mode 100644 (file)
index 0000000..b2c7289
--- /dev/null
@@ -0,0 +1,191 @@
+// Inferno utils/5l/asm.c
+// https://bitbucket.org/inferno-os/inferno-os/src/default/utils/5l/asm.c
+//
+//     Copyright © 1994-1999 Lucent Technologies Inc.  All rights reserved.
+//     Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
+//     Portions Copyright © 1997-1999 Vita Nuova Limited
+//     Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
+//     Portions Copyright © 2004,2006 Bruce Ellis
+//     Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
+//     Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
+//     Portions Copyright © 2016 The Go Authors. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+package mips
+
+import (
+       "cmd/internal/obj"
+       "cmd/link/internal/ld"
+       "fmt"
+       "log"
+)
+
+func gentext(ctxt *ld.Link) {
+       return
+}
+
+func adddynrel(ctxt *ld.Link, s *ld.Symbol, r *ld.Reloc) bool {
+       log.Fatalf("adddynrel not implemented")
+       return false
+}
+
+func elfreloc1(ctxt *ld.Link, r *ld.Reloc, sectoff int64) int {
+       return -1
+}
+
+func elfsetupplt(ctxt *ld.Link) {
+       return
+}
+
+func machoreloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) int {
+       return -1
+}
+
+func archreloc(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, val *int64) int {
+       if ld.Linkmode == ld.LinkExternal {
+               return -1
+       }
+
+       switch r.Type {
+       case obj.R_CONST:
+               *val = r.Add
+               return 0
+
+       case obj.R_GOTOFF:
+               *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0))
+               return 0
+
+       case obj.R_ADDRMIPS,
+               obj.R_ADDRMIPSU:
+               t := ld.Symaddr(r.Sym) + r.Add
+               o1 := ld.SysArch.ByteOrder.Uint32(s.P[r.Off:])
+               if r.Type == obj.R_ADDRMIPS {
+                       *val = int64(o1&0xffff0000 | uint32(t)&0xffff)
+               } else {
+                       *val = int64(o1&0xffff0000 | uint32((t+1<<15)>>16)&0xffff)
+               }
+               return 0
+
+       case obj.R_CALLMIPS,
+               obj.R_JMPMIPS:
+               // Low 26 bits = (S + A) >> 2
+               t := ld.Symaddr(r.Sym) + r.Add
+               o1 := ld.SysArch.ByteOrder.Uint32(s.P[r.Off:])
+               *val = int64(o1&0xfc000000 | uint32(t>>2)&^0xfc000000)
+               return 0
+       }
+
+       return -1
+}
+
+func archrelocvariant(ctxt *ld.Link, r *ld.Reloc, s *ld.Symbol, t int64) int64 {
+       return -1
+}
+
+func asmb(ctxt *ld.Link) {
+       if ctxt.Debugvlog != 0 {
+               ctxt.Logf("%5.2f asmb\n", obj.Cputime())
+       }
+
+       if ld.Iself {
+               ld.Asmbelfsetup()
+       }
+
+       sect := ld.Segtext.Sect
+       ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
+       ld.Codeblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
+       for sect = sect.Next; sect != nil; sect = sect.Next {
+               ld.Cseek(int64(sect.Vaddr - ld.Segtext.Vaddr + ld.Segtext.Fileoff))
+               ld.Datblk(ctxt, int64(sect.Vaddr), int64(sect.Length))
+       }
+
+       if ld.Segrodata.Filelen > 0 {
+               if ctxt.Debugvlog != 0 {
+                       ctxt.Logf("%5.2f rodatblk\n", obj.Cputime())
+               }
+
+               ld.Cseek(int64(ld.Segrodata.Fileoff))
+               ld.Datblk(ctxt, int64(ld.Segrodata.Vaddr), int64(ld.Segrodata.Filelen))
+       }
+
+       if ctxt.Debugvlog != 0 {
+               ctxt.Logf("%5.2f datblk\n", obj.Cputime())
+       }
+
+       ld.Cseek(int64(ld.Segdata.Fileoff))
+       ld.Datblk(ctxt, int64(ld.Segdata.Vaddr), int64(ld.Segdata.Filelen))
+
+       ld.Cseek(int64(ld.Segdwarf.Fileoff))
+       ld.Dwarfblk(ctxt, int64(ld.Segdwarf.Vaddr), int64(ld.Segdwarf.Filelen))
+
+       /* output symbol table */
+       ld.Symsize = 0
+
+       ld.Lcsize = 0
+       symo := uint32(0)
+       if !*ld.FlagS {
+               if !ld.Iself {
+                       ld.Errorf(nil, "unsupported executable format")
+               }
+               if ctxt.Debugvlog != 0 {
+                       ctxt.Logf("%5.2f sym\n", obj.Cputime())
+               }
+               symo = uint32(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen)
+               symo = uint32(ld.Rnd(int64(symo), int64(*ld.FlagRound)))
+
+               ld.Cseek(int64(symo))
+               if ctxt.Debugvlog != 0 {
+                       ctxt.Logf("%5.2f elfsym\n", obj.Cputime())
+               }
+               ld.Asmelfsym(ctxt)
+               ld.Cflush()
+               ld.Cwrite(ld.Elfstrdat)
+
+               if ctxt.Debugvlog != 0 {
+                       ctxt.Logf("%5.2f dwarf\n", obj.Cputime())
+               }
+
+               if ld.Linkmode == ld.LinkExternal {
+                       ld.Elfemitreloc(ctxt)
+               }
+       }
+
+       if ctxt.Debugvlog != 0 {
+               ctxt.Logf("%5.2f header\n", obj.Cputime())
+       }
+
+       ld.Cseek(0)
+       switch ld.Headtype {
+       default:
+               ld.Errorf(nil, "unsupported operating system")
+       case obj.Hlinux:
+               ld.Asmbelf(ctxt, int64(symo))
+       }
+
+       ld.Cflush()
+       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))
+       }
+}
diff --git a/src/cmd/link/internal/mips/l.go b/src/cmd/link/internal/mips/l.go
new file mode 100644 (file)
index 0000000..adbde40
--- /dev/null
@@ -0,0 +1,74 @@
+// Inferno utils/5l/asm.c
+// https://bitbucket.org/inferno-os/inferno-os/src/default/utils/5l/asm.c
+//
+//     Copyright © 1994-1999 Lucent Technologies Inc.  All rights reserved.
+//     Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
+//     Portions Copyright © 1997-1999 Vita Nuova Limited
+//     Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
+//     Portions Copyright © 2004,2006 Bruce Ellis
+//     Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
+//     Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
+//     Portions Copyright © 2016 The Go Authors.  All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+package mips
+
+// Writing object files.
+
+// cmd/9l/l.h from Vita Nuova.
+//
+//     Copyright © 1994-1999 Lucent Technologies Inc.  All rights reserved.
+//     Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
+//     Portions Copyright © 1997-1999 Vita Nuova Limited
+//     Portions Copyright © 2000-2008 Vita Nuova Holdings Limited (www.vitanuova.com)
+//     Portions Copyright © 2004,2006 Bruce Ellis
+//     Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
+//     Revisions Copyright © 2000-2008 Lucent Technologies Inc. and others
+//     Portions Copyright © 2016 The Go Authors.  All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+const (
+       MaxAlign  = 32 // max data alignment
+       MinAlign  = 1  // min data alignment
+       FuncAlign = 4
+)
+
+/* Used by ../internal/ld/dwarf.go */
+const (
+       DWARFREGSP = 29
+       DWARFREGLR = 31
+)
diff --git a/src/cmd/link/internal/mips/obj.go b/src/cmd/link/internal/mips/obj.go
new file mode 100644 (file)
index 0000000..a333876
--- /dev/null
@@ -0,0 +1,110 @@
+// Inferno utils/5l/obj.c
+// https://bitbucket.org/inferno-os/inferno-os/src/default/utils/5l/obj.c
+//
+//     Copyright © 1994-1999 Lucent Technologies Inc.  All rights reserved.
+//     Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
+//     Portions Copyright © 1997-1999 Vita Nuova Limited
+//     Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
+//     Portions Copyright © 2004,2006 Bruce Ellis
+//     Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
+//     Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
+//     Portions Copyright © 2016 The Go Authors. All rights reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+package mips
+
+import (
+       "cmd/internal/obj"
+       "cmd/internal/sys"
+       "cmd/link/internal/ld"
+       "fmt"
+)
+
+// Reading object files.
+
+func Init() {
+       if obj.GOARCH == "mipsle" {
+               ld.SysArch = sys.ArchMIPSLE
+       } else {
+               ld.SysArch = sys.ArchMIPS
+       }
+
+       ld.Thearch.Funcalign = FuncAlign
+       ld.Thearch.Maxalign = MaxAlign
+       ld.Thearch.Minalign = MinAlign
+       ld.Thearch.Dwarfregsp = DWARFREGSP
+       ld.Thearch.Dwarfreglr = DWARFREGLR
+
+       ld.Thearch.Adddynrel = adddynrel
+       ld.Thearch.Archinit = archinit
+       ld.Thearch.Archreloc = archreloc
+       ld.Thearch.Archrelocvariant = archrelocvariant
+       ld.Thearch.Asmb = asmb
+       ld.Thearch.Elfreloc1 = elfreloc1
+       ld.Thearch.Elfsetupplt = elfsetupplt
+       ld.Thearch.Gentext = gentext
+       ld.Thearch.Machoreloc1 = machoreloc1
+       if ld.SysArch == sys.ArchMIPSLE {
+               ld.Thearch.Lput = ld.Lputl
+               ld.Thearch.Wput = ld.Wputl
+               ld.Thearch.Vput = ld.Vputl
+               ld.Thearch.Append16 = ld.Append16l
+               ld.Thearch.Append32 = ld.Append32l
+               ld.Thearch.Append64 = ld.Append64l
+       } else {
+               ld.Thearch.Lput = ld.Lputb
+               ld.Thearch.Wput = ld.Wputb
+               ld.Thearch.Vput = ld.Vputb
+               ld.Thearch.Append16 = ld.Append16b
+               ld.Thearch.Append32 = ld.Append32b
+               ld.Thearch.Append64 = ld.Append64b
+       }
+
+       ld.Thearch.Linuxdynld = "/lib/ld.so.1"
+
+       ld.Thearch.Freebsddynld = "XXX"
+       ld.Thearch.Openbsddynld = "XXX"
+       ld.Thearch.Netbsddynld = "XXX"
+       ld.Thearch.Dragonflydynld = "XXX"
+       ld.Thearch.Solarisdynld = "XXX"
+}
+
+func archinit(ctxt *ld.Link) {
+       switch ld.Headtype {
+       default:
+               ld.Exitf("unknown -H option: %v", ld.Headtype)
+       case obj.Hlinux: /* mips elf */
+               ld.Elfinit(ctxt)
+               ld.HEADR = ld.ELFRESERVE
+               if *ld.FlagTextAddr == -1 {
+                       *ld.FlagTextAddr = 0x10000 + int64(ld.HEADR)
+               }
+               if *ld.FlagDataAddr == -1 {
+                       *ld.FlagDataAddr = 0
+               }
+               if *ld.FlagRound == -1 {
+                       *ld.FlagRound = 0x10000
+               }
+       }
+
+       if *ld.FlagDataAddr != 0 && *ld.FlagRound != 0 {
+               fmt.Printf("warning: -D0x%x is ignored because of -R0x%x\n", uint64(*ld.FlagDataAddr), uint32(*ld.FlagRound))
+       }
+}