Black Lives Matter. Support the Equal Justice Initiative.

Source file src/cmd/link/main.go

Documentation: cmd/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/sys"
     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/riscv64"
    17  	"cmd/link/internal/s390x"
    18  	"cmd/link/internal/wasm"
    19  	"cmd/link/internal/x86"
    20  	"fmt"
    21  	"internal/buildcfg"
    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  	buildcfg.Check()
    44  	switch buildcfg.GOARCH {
    45  	default:
    46  		fmt.Fprintf(os.Stderr, "link: unknown architecture %q\n", buildcfg.GOARCH)
    47  		os.Exit(2)
    48  	case "386":
    49  		arch, theArch = x86.Init()
    50  	case "amd64":
    51  		arch, theArch = amd64.Init()
    52  	case "arm":
    53  		arch, theArch = arm.Init()
    54  	case "arm64":
    55  		arch, theArch = arm64.Init()
    56  	case "mips", "mipsle":
    57  		arch, theArch = mips.Init()
    58  	case "mips64", "mips64le":
    59  		arch, theArch = mips64.Init()
    60  	case "ppc64", "ppc64le":
    61  		arch, theArch = ppc64.Init()
    62  	case "riscv64":
    63  		arch, theArch = riscv64.Init()
    64  	case "s390x":
    65  		arch, theArch = s390x.Init()
    66  	case "wasm":
    67  		arch, theArch = wasm.Init()
    68  	}
    69  	ld.Main(arch, theArch)
    70  }
    71  

View as plain text