...

Source file src/pkg/cmd/link/main.go

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

View as plain text