Skip to content

Commit e6d7326

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent 42b93b7 commit e6d7326

File tree

6 files changed

+30
-8
lines changed

6 files changed

+30
-8
lines changed

src/cmd/go/internal/load/pkg.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,9 @@ func externalLinkingForced(p *Package) bool {
18711871
// Some targets must use external linking even inside GOROOT.
18721872
switch cfg.BuildContext.GOOS {
18731873
case "android":
1874-
return true
1874+
if cfg.BuildContext.GOARCH != "arm64" {
1875+
return true
1876+
}
18751877
case "darwin":
18761878
switch cfg.BuildContext.GOARCH {
18771879
case "arm", "arm64":

src/cmd/internal/sys/supported.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ func MSanSupported(goos, goarch string) bool {
3535
func MustLinkExternal(goos, goarch string) bool {
3636
switch goos {
3737
case "android":
38-
return true
38+
if goarch != "arm64" {
39+
return true
40+
}
3941
case "darwin":
4042
if goarch == "arm" || goarch == "arm64" {
4143
return true

src/cmd/link/internal/arm64/obj.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ func Init() (*sys.Arch, ld.Arch) {
5757
Gentext: gentext,
5858
Machoreloc1: machoreloc1,
5959

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

6263
Freebsddynld: "/usr/libexec/ld-elf.so.1",
6364
Openbsddynld: "/usr/libexec/ld.so",

src/cmd/link/internal/ld/config.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) {
189189
if iscgo && ctxt.Arch.InFamily(sys.MIPS64, sys.MIPS, sys.PPC64) {
190190
return true, objabi.GOARCH + " does not support internal cgo"
191191
}
192+
if iscgo && objabi.GOOS == "android" {
193+
return true, objabi.GOOS + " does not support internal cgo"
194+
}
192195

193196
// When the race flag is set, the LLVM tsan relocatable file is linked
194197
// into the final binary, which means external linking is required because
@@ -205,7 +208,7 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) {
205208
return true, "buildmode=c-shared"
206209
case BuildModePIE:
207210
switch objabi.GOOS + "/" + objabi.GOARCH {
208-
case "linux/amd64", "linux/arm64":
211+
case "linux/amd64", "linux/arm64", "android/arm64":
209212
default:
210213
// Internal linking does not support TLS_IE.
211214
return true, "buildmode=pie"
@@ -244,10 +247,16 @@ func determineLinkMode(ctxt *Link) {
244247
ctxt.LinkMode = LinkExternal
245248
via = "via GO_EXTLINK_ENABLED "
246249
default:
247-
if extNeeded || (iscgo && externalobj) {
250+
ctxt.LinkMode = LinkInternal
251+
switch {
252+
case extNeeded, iscgo && externalobj:
248253
ctxt.LinkMode = LinkExternal
249-
} else {
250-
ctxt.LinkMode = LinkInternal
254+
case ctxt.BuildMode == BuildModePIE:
255+
// Android always use BuildModePIE, and needs internal linking for
256+
// bootstrapping.
257+
if objabi.GOOS != "android" || objabi.GOARCH != "arm64" {
258+
ctxt.LinkMode = LinkExternal
259+
}
251260
}
252261
}
253262
}

src/cmd/link/internal/ld/elf.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1851,7 +1851,14 @@ func Asmbelf(ctxt *Link, symo int64) {
18511851
if interpreter == "" {
18521852
switch ctxt.HeadType {
18531853
case objabi.Hlinux:
1854-
interpreter = thearch.Linuxdynld
1854+
if objabi.GOOS == "android" {
1855+
interpreter = thearch.Androiddynld
1856+
if interpreter == "" {
1857+
Exitf("ELF interpreter not set")
1858+
}
1859+
} else {
1860+
interpreter = thearch.Linuxdynld
1861+
}
18551862

18561863
case objabi.Hfreebsd:
18571864
interpreter = thearch.Freebsddynld

src/cmd/link/internal/ld/lib.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ type Arch struct {
101101
Minalign int
102102
Dwarfregsp int
103103
Dwarfreglr int
104+
Androiddynld string
104105
Linuxdynld string
105106
Freebsddynld string
106107
Netbsddynld string

0 commit comments

Comments
 (0)