github.com/riscv/riscv-go@v0.0.0-20200123204226-124ebd6fcc8e/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/mips"
    14  	"cmd/link/internal/mips64"
    15  	"cmd/link/internal/ppc64"
    16  	"cmd/link/internal/riscv"
    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 ld.Thearch and ld.SysArch 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  	switch obj.GOARCH {
    39  	default:
    40  		fmt.Fprintf(os.Stderr, "link: unknown architecture %q\n", obj.GOARCH)
    41  		os.Exit(2)
    42  	case "386":
    43  		x86.Init()
    44  	case "amd64", "amd64p32":
    45  		amd64.Init()
    46  	case "arm":
    47  		arm.Init()
    48  	case "arm64":
    49  		arm64.Init()
    50  	case "mips", "mipsle":
    51  		mips.Init()
    52  	case "mips64", "mips64le":
    53  		mips64.Init()
    54  	case "ppc64", "ppc64le":
    55  		ppc64.Init()
    56  	case "riscv":
    57  		riscv.Main()
    58  	case "s390x":
    59  		s390x.Init()
    60  	}
    61  	ld.Main()
    62  }