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