Home | History | Annotate | Download | only in link
      1 // Copyright 2015 The Go Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 package main
      6 
      7 import (
      8 	"cmd/internal/obj"
      9 	"cmd/link/internal/amd64"
     10 	"cmd/link/internal/arm"
     11 	"cmd/link/internal/arm64"
     12 	"cmd/link/internal/ld"
     13 	"cmd/link/internal/mips"
     14 	"cmd/link/internal/mips64"
     15 	"cmd/link/internal/ppc64"
     16 	"cmd/link/internal/s390x"
     17 	"cmd/link/internal/x86"
     18 	"fmt"
     19 	"os"
     20 )
     21 
     22 // The bulk of the linker implementation lives in cmd/link/internal/ld.
     23 // Architecture-specific code lives in cmd/link/internal/GOARCH.
     24 //
     25 // Program initialization:
     26 //
     27 // Before any argument parsing is done, the Init function of relevant
     28 // architecture package is called. The only job done in Init is
     29 // configuration of the ld.Thearch and ld.SysArch variables.
     30 //
     31 // Then control flow passes to ld.Main, which parses flags, makes
     32 // some configuration decisions, and then gives the architecture
     33 // packages a second chance to modify the linker's configuration
     34 // via the ld.Thearch.Archinit function.
     35 
     36 func main() {
     37 	switch obj.GOARCH {
     38 	default:
     39 		fmt.Fprintf(os.Stderr, "link: unknown architecture %q\n", obj.GOARCH)
     40 		os.Exit(2)
     41 	case "386":
     42 		x86.Init()
     43 	case "amd64", "amd64p32":
     44 		amd64.Init()
     45 	case "arm":
     46 		arm.Init()
     47 	case "arm64":
     48 		arm64.Init()
     49 	case "mips", "mipsle":
     50 		mips.Init()
     51 	case "mips64", "mips64le":
     52 		mips64.Init()
     53 	case "ppc64", "ppc64le":
     54 		ppc64.Init()
     55 	case "s390x":
     56 		s390x.Init()
     57 	}
     58 	ld.Main()
     59 }
     60