Skip to content

Commit

Permalink
cmd/link: default to internal linking for android/arm64
Browse files Browse the repository at this point in the history
The bootstrapping process (make.bash) on all other platforms use
internal linking. This change brings android/arm64 in line, fixing the
scary warning on our self-hosted Corellium builders:

warning: unable to find runtime/cgo.a

The linkmode default is changed to internal for all Android programs,
but in practice that won't matter outside our builders: using Go with
Android apps requires buildmode=c-shared which uses linkmode external.

Fixes #31343
Updates #31819

Change-Id: I3b3ada5ed69a7989e6d8e5960bbebf5e1c22aada
Reviewed-on: https://go-review.googlesource.com/c/go/+/207299
Run-TryBot: Elias Naur <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
Reviewed-by: Cherry Zhang <[email protected]>
  • Loading branch information
eliasnaur committed Feb 26, 2020
1 parent 42b93b7 commit e6d7326
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/cmd/go/internal/load/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -1871,7 +1871,9 @@ func externalLinkingForced(p *Package) bool {
// Some targets must use external linking even inside GOROOT.
switch cfg.BuildContext.GOOS {
case "android":
return true
if cfg.BuildContext.GOARCH != "arm64" {
return true
}
case "darwin":
switch cfg.BuildContext.GOARCH {
case "arm", "arm64":
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/internal/sys/supported.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ func MSanSupported(goos, goarch string) bool {
func MustLinkExternal(goos, goarch string) bool {
switch goos {
case "android":
return true
if goarch != "arm64" {
return true
}
case "darwin":
if goarch == "arm" || goarch == "arm64" {
return true
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/link/internal/arm64/obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func Init() (*sys.Arch, ld.Arch) {
Gentext: gentext,
Machoreloc1: machoreloc1,

Linuxdynld: "/lib/ld-linux-aarch64.so.1",
Androiddynld: "/system/bin/linker64",
Linuxdynld: "/lib/ld-linux-aarch64.so.1",

Freebsddynld: "/usr/libexec/ld-elf.so.1",
Openbsddynld: "/usr/libexec/ld.so",
Expand Down
17 changes: 13 additions & 4 deletions src/cmd/link/internal/ld/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) {
if iscgo && ctxt.Arch.InFamily(sys.MIPS64, sys.MIPS, sys.PPC64) {
return true, objabi.GOARCH + " does not support internal cgo"
}
if iscgo && objabi.GOOS == "android" {
return true, objabi.GOOS + " does not support internal cgo"
}

// When the race flag is set, the LLVM tsan relocatable file is linked
// into the final binary, which means external linking is required because
Expand All @@ -205,7 +208,7 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) {
return true, "buildmode=c-shared"
case BuildModePIE:
switch objabi.GOOS + "/" + objabi.GOARCH {
case "linux/amd64", "linux/arm64":
case "linux/amd64", "linux/arm64", "android/arm64":
default:
// Internal linking does not support TLS_IE.
return true, "buildmode=pie"
Expand Down Expand Up @@ -244,10 +247,16 @@ func determineLinkMode(ctxt *Link) {
ctxt.LinkMode = LinkExternal
via = "via GO_EXTLINK_ENABLED "
default:
if extNeeded || (iscgo && externalobj) {
ctxt.LinkMode = LinkInternal
switch {
case extNeeded, iscgo && externalobj:
ctxt.LinkMode = LinkExternal
} else {
ctxt.LinkMode = LinkInternal
case ctxt.BuildMode == BuildModePIE:
// Android always use BuildModePIE, and needs internal linking for
// bootstrapping.
if objabi.GOOS != "android" || objabi.GOARCH != "arm64" {
ctxt.LinkMode = LinkExternal
}
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/cmd/link/internal/ld/elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -1851,7 +1851,14 @@ func Asmbelf(ctxt *Link, symo int64) {
if interpreter == "" {
switch ctxt.HeadType {
case objabi.Hlinux:
interpreter = thearch.Linuxdynld
if objabi.GOOS == "android" {
interpreter = thearch.Androiddynld
if interpreter == "" {
Exitf("ELF interpreter not set")
}
} else {
interpreter = thearch.Linuxdynld
}

case objabi.Hfreebsd:
interpreter = thearch.Freebsddynld
Expand Down
1 change: 1 addition & 0 deletions src/cmd/link/internal/ld/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type Arch struct {
Minalign int
Dwarfregsp int
Dwarfreglr int
Androiddynld string
Linuxdynld string
Freebsddynld string
Netbsddynld string
Expand Down

0 comments on commit e6d7326

Please sign in to comment.