aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <freythergo@gmail.com>2023-09-24 12:05:37 +0000
committerGopher Robot <gobot@golang.org>2023-09-25 18:16:01 +0000
commitbc9da01e9d7de25f04173f7122e09fe0996aaa05 (patch)
tree051db7f78383438c08ed0de20237c3dbbcef3740 /src/cmd
parent70e04706d8ccd4c93de54e1f5c7b15c942018dee (diff)
downloadgo-bc9da01e9d7de25f04173f7122e09fe0996aaa05.tar.xz
cmd/go: permit additional cflags when compiling
In CL 475375 the Go command started to generate the "preferlinkext" token file for "strange/dangerous" compiler flags. This serves as a hint to the Go linker whether to call the external linker or not. Permit compiler flags used by bazel and bazelbuild/rules_go during compilation of cgo code to not prefer external linking. This restores the behavior of previous versions of Go. As a side effect, it also allows these flags to appear in #cgo directives in source code. We don't know of any cases where that is actually useful, but it appears to be harmless and simplifies the implementation of the internal linking change. Fixes #60865 Change-Id: I176a6a2a2cf36293dd9aed24be928f98fa2fb6d9 GitHub-Last-Rev: 071e915b8e4e6b466e1accbfd2b9b45fc9982a34 GitHub-Pull-Request: golang/go#60868 Reviewed-on: https://go-review.googlesource.com/c/go/+/504335 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/go/internal/work/security.go4
-rw-r--r--src/cmd/go/testdata/script/cgo_suspect_flag_force_external.txt26
2 files changed, 30 insertions, 0 deletions
diff --git a/src/cmd/go/internal/work/security.go b/src/cmd/go/internal/work/security.go
index 270a34e9c7..88504be6cd 100644
--- a/src/cmd/go/internal/work/security.go
+++ b/src/cmd/go/internal/work/security.go
@@ -59,7 +59,10 @@ var validCompilerFlags = []*lazyregexp.Regexp{
re(`-f(no-)builtin-[a-zA-Z0-9_]*`),
re(`-f(no-)?common`),
re(`-f(no-)?constant-cfstrings`),
+ re(`-fdebug-prefix-map=([^@]+)=([^@]+)`),
re(`-fdiagnostics-show-note-include-stack`),
+ re(`-ffile-prefix-map=([^@]+)=([^@]+)`),
+ re(`-fno-canonical-system-headers`),
re(`-f(no-)?eliminate-unused-debug-types`),
re(`-f(no-)?exceptions`),
re(`-f(no-)?fast-math`),
@@ -114,6 +117,7 @@ var validCompilerFlags = []*lazyregexp.Regexp{
re(`-mthumb(-interwork)?`),
re(`-mthreads`),
re(`-mwindows`),
+ re(`-no-canonical-prefixes`),
re(`--param=ssp-buffer-size=[0-9]*`),
re(`-pedantic(-errors)?`),
re(`-pipe`),
diff --git a/src/cmd/go/testdata/script/cgo_suspect_flag_force_external.txt b/src/cmd/go/testdata/script/cgo_suspect_flag_force_external.txt
index d555278865..6dc30bedb9 100644
--- a/src/cmd/go/testdata/script/cgo_suspect_flag_force_external.txt
+++ b/src/cmd/go/testdata/script/cgo_suspect_flag_force_external.txt
@@ -55,6 +55,32 @@ stderr preferlinkext
env CGO_CFLAGS=-fprofile-instr-generate
go build -x -n -o dummy.exe ./usesInternalCgo
stderr preferlinkext
+
+# The -fdebug-prefix-map=path is permitted for internal linking.
+env CGO_CFLAGS=-fdebug-prefix-map=/some/sandbox/execroot/workspace=/tmp/new
+go build -x -n -o dummy.exe ./usesInternalCgo
+! stderr preferlinkext
+env CGO_CFLAGS=-fdebug-prefix-map=/Users/someone/.cache/bazel/_bazel_someone/3fa7e4650c43657ead684537951f49e2/sandbox/linux-sandbox/10/execroot/rules_go_static=.
+go build -x -n -o dummy.exe ./usesInternalCgo
+! stderr preferlinkext
+# The -ffile-prefix-map=path is permitted for internal linking too.
+env CGO_CFLAGS=-ffile-prefix-map=/Users/someone/.cache/bazel/_bazel_someone/3fa7e4650c43657ead684537951f49e2/sandbox/linux-sandbox/10/execroot/rules_go_static/bazel-out/aarch64-fastbuild-ST-b33d65c724e6/bin/external/io_bazel_rules_go/stdlib_=.
+go build -x -n -o dummy.exe ./usesInternalCgo
+! stderr preferlinkext
+# Verifying that -fdebug-prefix-map=path, -ffile-prefix-map, -no-canonical-prefixes
+# and -fno-canonical-systemd-headers are permitted for internal linking.
+env CGO_CFLAGS=-fdebug-prefix-map=old=/tmp/new
+go build -x -n -o dummy.exe ./usesInternalCgo
+! stderr preferlinkext
+env CGO_CFLAGS=-ffile-prefix-map=/Users/someone/_11233/things=new
+go build -x -n -o dummy.exe ./usesInternalCgo
+! stderr preferlinkext
+env CGO_CFLAGS=-no-canonical-prefixes
+go build -x -n -o dummy.exe ./usesInternalCgo
+! stderr preferlinkext
+env CGO_CFLAGS=-fno-canonical-system-headers
+go build -x -n -o dummy.exe ./usesInternalCgo
+! stderr preferlinkext
env CGO_CFLAGS=
[short] skip