Skip to content

Commit 434b350

Browse files
author
Holger Hans Peter Freyther
committed
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: 4127df6 GitHub-Pull-Request: #60868
1 parent 5c15498 commit 434b350

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/cmd/go/internal/work/security.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ var validCompilerFlags = []*lazyregexp.Regexp{
5959
re(`-f(no-)builtin-[a-zA-Z0-9_]*`),
6060
re(`-f(no-)?common`),
6161
re(`-f(no-)?constant-cfstrings`),
62+
re(`-fdebug-prefix-map=([^@]+)=([^@]+)`),
6263
re(`-fdiagnostics-show-note-include-stack`),
64+
re(`-ffile-prefix-map=([^@]+)=([^@]+)`),
65+
re(`-fno-canonical-system-headers`),
6366
re(`-f(no-)?eliminate-unused-debug-types`),
6467
re(`-f(no-)?exceptions`),
6568
re(`-f(no-)?fast-math`),

src/cmd/go/testdata/script/cgo_suspect_flag_force_external.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ stderr preferlinkext
5555
env CGO_CFLAGS=-fprofile-instr-generate
5656
go build -x -n -o dummy.exe ./usesInternalCgo
5757
stderr preferlinkext
58+
59+
env CGO_CFLAGS=-fdebug-prefix-map=/some/sandbox/execroot/workspace=/tmp/new
60+
go build -x -n -o dummy.exe ./usesInternalCgo
61+
! stderr preferlinkext
62+
env CGO_CFLAGS=-fdebug-prefix-map=/Users/someone/.cache/bazel/_bazel_someone/3fa7e4650c43657ead684537951f49e2/sandbox/linux-sandbox/10/execroot/rules_go_static=.
63+
go build -x -n -o dummy.exe ./usesInternalCgo
64+
! stderr preferlinkext
65+
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_=.
66+
go build -x -n -o dummy.exe ./usesInternalCgo
67+
! stderr preferlinkext
68+
env CGO_CFLAGS=-fdebug-prefix-map=old=/tmp/new -ffile-prefix-map=/Users/someone/_11233/things=new -fno-canonical-system-headers
69+
go build -x -n -o dummy.exe ./usesInternalCgo
70+
! stderr preferlinkext
5871
env CGO_CFLAGS=
5972

6073
[short] skip

0 commit comments

Comments
 (0)