From bbf795ebb114918a8e8dc7fd4d825cd5928d3f4d Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Fri, 10 Mar 2023 15:37:17 -0500 Subject: 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 Auto-Submit: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Cherry Mui --- src/cmd/nm/nm_test.go | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'src/cmd/nm/nm_test.go') 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 } -- cgit v1.3