...

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

View as plain text