Skip to content

Commit 0f5d86c

Browse files
Holger Hans Peter Freythergopherbot
Holger Hans Peter Freyther
authored andcommitted
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 flag used by the hermetic_cc_toolchain bzlmod. 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 #72842 Change-Id: Ic6de29b535a4e2c0720f383567ea6b3c7ca4f541 Reviewed-on: https://go-review.googlesource.com/c/go/+/657575 Auto-Submit: Ian Lance Taylor <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
1 parent 6bd5741 commit 0f5d86c

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ var validCompilerFlags = []*lazyregexp.Regexp{
9090
re(`-f(no-)?use-linker-plugin`), // safe if -B is not used; we don't permit -B
9191
re(`-f(no-)?visibility-inlines-hidden`),
9292
re(`-fsanitize=(.+)`),
93+
re(`-fsanitize-undefined-strip-path-components=(-)?[0-9]+`),
9394
re(`-ftemplate-depth-(.+)`),
9495
re(`-ftls-model=(global-dynamic|local-dynamic|initial-exec|local-exec)`),
9596
re(`-fvisibility=(.+)`),

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ env CGO_CFLAGS=-fprofile-instr-generate
5656
go build -x -n -o dummy.exe ./usesInternalCgo
5757
stderr preferlinkext
5858

59+
# Trimming file information for the UndefinedBehaviorSanitizer is permitted for internal linking.
60+
env CGO_CFLAGS=-fsanitize-undefined-strip-path-components=-1
61+
go build -x -n -o dummy.exe ./usesInternalCgo
62+
! stderr preferlinkext
63+
env CGO_CFLAGS=-fsanitize-undefined-strip-path-components=2
64+
go build -x -n -o dummy.exe ./usesInternalCgo
65+
! stderr preferlinkext
66+
5967
# The -fdebug-prefix-map=path is permitted for internal linking.
6068
env CGO_CFLAGS=-fdebug-prefix-map=/some/sandbox/execroot/workspace=/tmp/new
6169
go build -x -n -o dummy.exe ./usesInternalCgo

0 commit comments

Comments
 (0)