Commit 28ed2b0c authored by David Crawshaw's avatar David Crawshaw

cmd/link: skip arch-specific main function

Add some notes to main.go on what happens where.

Change-Id: I4fb0b6c280e5f990ddc5d749267372b86870af6d
Reviewed-on: https://go-review.googlesource.com/28970
TryBot-Result: Gobot Gobot <gobot@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent c199c76c
...@@ -37,14 +37,7 @@ import ( ...@@ -37,14 +37,7 @@ import (
"fmt" "fmt"
) )
// Reading object files. func Init() {
func Main() {
linkarchinit()
ld.Main()
}
func linkarchinit() {
ld.SysArch = sys.ArchAMD64 ld.SysArch = sys.ArchAMD64
if obj.GOARCH == "amd64p32" { if obj.GOARCH == "amd64p32" {
ld.SysArch = sys.ArchAMD64P32 ld.SysArch = sys.ArchAMD64P32
......
...@@ -37,14 +37,7 @@ import ( ...@@ -37,14 +37,7 @@ import (
"fmt" "fmt"
) )
// Reading object files. func Init() {
func Main() {
linkarchinit()
ld.Main()
}
func linkarchinit() {
ld.SysArch = sys.ArchARM ld.SysArch = sys.ArchARM
ld.Thearch.Funcalign = FuncAlign ld.Thearch.Funcalign = FuncAlign
......
...@@ -37,14 +37,7 @@ import ( ...@@ -37,14 +37,7 @@ import (
"fmt" "fmt"
) )
// Reading object files. func Init() {
func Main() {
linkarchinit()
ld.Main()
}
func linkarchinit() {
ld.SysArch = sys.ArchARM64 ld.SysArch = sys.ArchARM64
ld.Thearch.Funcalign = FuncAlign ld.Thearch.Funcalign = FuncAlign
......
...@@ -37,14 +37,7 @@ import ( ...@@ -37,14 +37,7 @@ import (
"fmt" "fmt"
) )
// Reading object files. func Init() {
func Main() {
linkarchinit()
ld.Main()
}
func linkarchinit() {
if obj.GOARCH == "mips64le" { if obj.GOARCH == "mips64le" {
ld.SysArch = sys.ArchMIPS64LE ld.SysArch = sys.ArchMIPS64LE
} else { } else {
......
...@@ -37,14 +37,7 @@ import ( ...@@ -37,14 +37,7 @@ import (
"fmt" "fmt"
) )
// Reading object files. func Init() {
func Main() {
linkarchinit()
ld.Main()
}
func linkarchinit() {
if obj.GOARCH == "ppc64le" { if obj.GOARCH == "ppc64le" {
ld.SysArch = sys.ArchPPC64LE ld.SysArch = sys.ArchPPC64LE
} else { } else {
......
...@@ -37,14 +37,7 @@ import ( ...@@ -37,14 +37,7 @@ import (
"fmt" "fmt"
) )
// Reading object files. func Init() {
func Main() {
linkarchinit()
ld.Main()
}
func linkarchinit() {
ld.SysArch = sys.ArchS390X ld.SysArch = sys.ArchS390X
ld.Thearch.Funcalign = FuncAlign ld.Thearch.Funcalign = FuncAlign
......
...@@ -37,14 +37,7 @@ import ( ...@@ -37,14 +37,7 @@ import (
"fmt" "fmt"
) )
// Reading object files. func Init() {
func Main() {
linkarchinit()
ld.Main()
}
func linkarchinit() {
ld.SysArch = sys.Arch386 ld.SysArch = sys.Arch386
ld.Thearch.Funcalign = FuncAlign ld.Thearch.Funcalign = FuncAlign
......
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"cmd/link/internal/amd64" "cmd/link/internal/amd64"
"cmd/link/internal/arm" "cmd/link/internal/arm"
"cmd/link/internal/arm64" "cmd/link/internal/arm64"
"cmd/link/internal/ld"
"cmd/link/internal/mips64" "cmd/link/internal/mips64"
"cmd/link/internal/ppc64" "cmd/link/internal/ppc64"
"cmd/link/internal/s390x" "cmd/link/internal/s390x"
...@@ -17,24 +18,39 @@ import ( ...@@ -17,24 +18,39 @@ import (
"os" "os"
) )
// The bulk of the linker implementation lives in cmd/link/internal/ld.
// Architecture-specific code lives in cmd/link/internal/GOARCH.
//
// Program initialization:
//
// Before any argument parsing is done, the Init function of relevant
// architecture package is called. The only job done in Init is
// configuration of the ld.Thearch and ld.SysArch variables.
//
// Then control flow passes to ld.Main, which parses flags, makes
// some configuration decisions, and then gives the architecture
// packages a second chance to modify the linker's configuration
// via the ld.Thearch.Archinit function.
func main() { func main() {
switch obj.GOARCH { switch obj.GOARCH {
default: default:
fmt.Fprintf(os.Stderr, "link: unknown architecture %q\n", obj.GOARCH) fmt.Fprintf(os.Stderr, "link: unknown architecture %q\n", obj.GOARCH)
os.Exit(2) os.Exit(2)
case "386": case "386":
x86.Main() x86.Init()
case "amd64", "amd64p32": case "amd64", "amd64p32":
amd64.Main() amd64.Init()
case "arm": case "arm":
arm.Main() arm.Init()
case "arm64": case "arm64":
arm64.Main() arm64.Init()
case "mips64", "mips64le": case "mips64", "mips64le":
mips64.Main() mips64.Init()
case "ppc64", "ppc64le": case "ppc64", "ppc64le":
ppc64.Main() ppc64.Init()
case "s390x": case "s390x":
s390x.Main() s390x.Init()
} }
ld.Main()
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment