github.com/dannin/go@v0.0.0-20161031215817-d35dfd405eaa/src/cmd/link/main.go (about)

     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/mips64"
    14  	"cmd/link/internal/ppc64"
    15  	"cmd/link/internal/s390x"
    16  	"cmd/link/internal/x86"
    17  	"fmt"
    18  	"os"
    19  )
    20  
    21  // The bulk of the linker implementation lives in cmd/link/internal/ld.
    22  // Architecture-specific code lives in cmd/link/internal/GOARCH.
    23  //
    24  // Program initialization:
    25  //
    26  // Before any argument parsing is done, the Init function of relevant
    27  // architecture package is called. The only job done in Init is
    28  // configuration of the ld.Thearch and ld.SysArch variables.
    29  //
    30  // Then control flow passes to ld.Main, which parses flags, makes
    31  // some configuration decisions, and then gives the architecture
    32  // packages a second chance to modify the linker's configuration
    33  // via the ld.Thearch.Archinit function.
    34  
    35  func main() {
    36  	switch obj.GOARCH {
    37  	default:
    38  		fmt.Fprintf(os.Stderr, "link: unknown architecture %q\n", obj.GOARCH)
    39  		os.Exit(2)
    40  	case "386":
    41  		x86.Init()
    42  	case "amd64", "amd64p32":
    43  		amd64.Init()
    44  	case "arm":
    45  		arm.Init()
    46  	case "arm64":
    47  		arm64.Init()
    48  	case "mips64", "mips64le":
    49  		mips64.Init()
    50  	case "ppc64", "ppc64le":
    51  		ppc64.Init()
    52  	case "s390x":
    53  		s390x.Init()
    54  	}
    55  	ld.Main()
    56  }