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