mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/link: default to internal linking for android/arm64
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 <mail@eliasnaur.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
parent
42b93b7fe6
commit
e6d7326fb6
6 changed files with 30 additions and 8 deletions
|
|
@ -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":
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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"
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ type Arch struct {
|
|||
Minalign int
|
||||
Dwarfregsp int
|
||||
Dwarfreglr int
|
||||
Androiddynld string
|
||||
Linuxdynld string
|
||||
Freebsddynld string
|
||||
Netbsddynld string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue