diff options
| author | Bryan C. Mills <bcmills@google.com> | 2023-03-10 15:37:17 -0500 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-03-15 13:31:05 +0000 |
| commit | bbf795ebb114918a8e8dc7fd4d825cd5928d3f4d (patch) | |
| tree | 814cd8f52220d444b6bf621b8b2c798ec643858d /src/cmd/nm | |
| parent | a8cd10f2ab66d15ec43c6c6f688c3362f638237f (diff) | |
| download | go-bbf795ebb114918a8e8dc7fd4d825cd5928d3f4d.tar.xz | |
internal/platform: add a function to report whether default builds are PIE
This consolidates a condition that was previously repeated (in
different approximations) in several different places in the code.
For #58807.
Change-Id: Idd308759f6262b1f5c61f79022965612319edf94
Reviewed-on: https://go-review.googlesource.com/c/go/+/475457
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/cmd/nm')
| -rw-r--r-- | src/cmd/nm/nm_test.go | 15 |
1 files changed, 3 insertions, 12 deletions
diff --git a/src/cmd/nm/nm_test.go b/src/cmd/nm/nm_test.go index 014a5d2bd7..8c23d73d6d 100644 --- a/src/cmd/nm/nm_test.go +++ b/src/cmd/nm/nm_test.go @@ -6,6 +6,7 @@ package main import ( "internal/obscuretestdata" + "internal/platform" "internal/testenv" "os" "path/filepath" @@ -165,20 +166,10 @@ func testGoExec(t *testing.T, iscgo, isexternallinker bool) { return true } } - // Code is always relocated if the default buildmode is PIE. - // - // TODO(#58807): factor this condition out into a function in - // internal/platform so that it won't get out of sync with cmd/go and - // cmd/link. - if runtime.GOOS == "android" { + if platform.DefaultPIE(runtime.GOOS, runtime.GOARCH) { + // Code is always relocated if the default buildmode is PIE. return true } - if runtime.GOOS == "windows" { - return true - } - if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" { - return true // On darwin/arm64 everything is PIE - } return false } |
