Skip to content

Commit eef2fd2

Browse files
ianlancetaylorandybons
authored andcommitted
[release-branch.go1.10] cmd/go: add more C compiler/linker options to whitelist
Fixes #23937 Change-Id: Ie63d91355d1a724d0012d99d457d939deeeb8d3e Reviewed-on: https://go-review.googlesource.com/102818 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Andrew Bonventre <[email protected]> Reviewed-on: https://go-review.googlesource.com/103015 Run-TryBot: Andrew Bonventre <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 4bc847d commit eef2fd2

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

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

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,19 @@ var validCompilerFlags = []*regexp.Regexp{
4646
re(`-O([^@\-].*)`),
4747
re(`-W`),
4848
re(`-W([^@,]+)`), // -Wall but not -Wa,-foo.
49+
re(`-Wa,-mbig-obj`),
50+
re(`-ansi`),
4951
re(`-f(no-)?blocks`),
5052
re(`-f(no-)?common`),
5153
re(`-f(no-)?constant-cfstrings`),
54+
re(`-fdiagnostics-show-note-include-stack`),
5255
re(`-f(no-)?exceptions`),
56+
re(`-f(no-)?inline-functions`),
5357
re(`-finput-charset=([^@\-].*)`),
58+
re(`-f(no-)?fat-lto-objects`),
5459
re(`-f(no-)?lto`),
60+
re(`-fmacro-backtrace-limit=(.+)`),
61+
re(`-fmessage-length=(.+)`),
5562
re(`-f(no-)?modules`),
5663
re(`-f(no-)?objc-arc`),
5764
re(`-f(no-)?omit-frame-pointer`),
@@ -62,71 +69,108 @@ var validCompilerFlags = []*regexp.Regexp{
6269
re(`-f(no-)?split-stack`),
6370
re(`-f(no-)?stack-(.+)`),
6471
re(`-f(no-)?strict-aliasing`),
72+
re(`-f(un)signed-char`),
73+
re(`-f(no-)?use-linker-plugin`), // safe if -B is not used; we don't permit -B
6574
re(`-fsanitize=(.+)`),
75+
re(`-ftemplate-depth-(.+)`),
76+
re(`-fvisibility=(.+)`),
6677
re(`-g([^@\-].*)?`),
78+
re(`-m32`),
79+
re(`-m64`),
6780
re(`-m(arch|cpu|fpu|tune)=([^@\-].*)`),
6881
re(`-m(no-)?avx[0-9a-z.]*`),
6982
re(`-m(no-)?ms-bitfields`),
7083
re(`-m(no-)?stack-(.+)`),
7184
re(`-mmacosx-(.+)`),
85+
re(`-mios-simulator-version-min=(.+)`),
86+
re(`-miphoneos-version-min=(.+)`),
7287
re(`-mnop-fun-dllimport`),
7388
re(`-m(no-)?sse[0-9.]*`),
89+
re(`-mwindows`),
7490
re(`-pedantic(-errors)?`),
7591
re(`-pipe`),
7692
re(`-pthread`),
7793
re(`-?-std=([^@\-].*)`),
94+
re(`-?-stdlib=([^@\-].*)`),
95+
re(`-w`),
7896
re(`-x([^@\-].*)`),
7997
}
8098

8199
var validCompilerFlagsWithNextArg = []string{
100+
"-arch",
82101
"-D",
83102
"-I",
84-
"-isystem",
85103
"-framework",
104+
"-isysroot",
105+
"-isystem",
106+
"--sysroot",
107+
"-target",
86108
"-x",
87109
}
88110

89111
var validLinkerFlags = []*regexp.Regexp{
90112
re(`-F([^@\-].*)`),
91113
re(`-l([^@\-].*)`),
92114
re(`-L([^@\-].*)`),
115+
re(`-O`),
116+
re(`-O([^@\-].*)`),
93117
re(`-f(no-)?(pic|PIC|pie|PIE)`),
94118
re(`-fsanitize=([^@\-].*)`),
95119
re(`-g([^@\-].*)?`),
96120
re(`-m(arch|cpu|fpu|tune)=([^@\-].*)`),
121+
re(`-mmacosx-(.+)`),
122+
re(`-mios-simulator-version-min=(.+)`),
123+
re(`-miphoneos-version-min=(.+)`),
124+
re(`-mwindows`),
97125
re(`-(pic|PIC|pie|PIE)`),
98126
re(`-pthread`),
127+
re(`-shared`),
99128
re(`-?-static([-a-z0-9+]*)`),
129+
re(`-?-stdlib=([^@\-].*)`),
100130

101131
// Note that any wildcards in -Wl need to exclude comma,
102132
// since -Wl splits its argument at commas and passes
103133
// them all to the linker uninterpreted. Allowing comma
104134
// in a wildcard would allow tunnelling arbitrary additional
105135
// linker arguments through one of these.
136+
re(`-Wl,--(no-)?allow-multiple-definition`),
106137
re(`-Wl,--(no-)?as-needed`),
107138
re(`-Wl,-Bdynamic`),
108139
re(`-Wl,-Bstatic`),
140+
re(`-Wl,-d[ny]`),
109141
re(`-Wl,--disable-new-dtags`),
110142
re(`-Wl,--enable-new-dtags`),
111143
re(`-Wl,--end-group`),
112144
re(`-Wl,-framework,[^,@\-][^,]+`),
113145
re(`-Wl,-headerpad_max_install_names`),
114146
re(`-Wl,--no-undefined`),
115-
re(`-Wl,-rpath,([^,@\-][^,]+)`),
147+
re(`-Wl,-rpath[=,]([^,@\-][^,]+)`),
116148
re(`-Wl,-search_paths_first`),
149+
re(`-Wl,-sectcreate,([^,@\-][^,]+),([^,@\-][^,]+),([^,@\-][^,]+)`),
117150
re(`-Wl,--start-group`),
151+
re(`-Wl,-?-static`),
152+
re(`-Wl,--subsystem,(native|windows|console|posix|xbox)`),
153+
re(`-Wl,-undefined[=,]([^,@\-][^,]+)`),
118154
re(`-Wl,-?-unresolved-symbols=[^,]+`),
119155
re(`-Wl,--(no-)?warn-([^,]+)`),
156+
re(`-Wl,-z,(no)?execstack`),
157+
re(`-Wl,-z,relro`),
120158

121159
re(`[a-zA-Z0-9_/].*\.(a|o|obj|dll|dylib|so)`), // direct linker inputs: x.o or libfoo.so (but not -foo.o or @foo.o)
122160
}
123161

124162
var validLinkerFlagsWithNextArg = []string{
163+
"-arch",
125164
"-F",
126165
"-l",
127166
"-L",
128167
"-framework",
168+
"-isysroot",
169+
"--sysroot",
170+
"-target",
129171
"-Wl,-framework",
172+
"-Wl,-rpath",
173+
"-Wl,-undefined",
130174
}
131175

132176
func checkCompilerFlags(name, source string, list []string) error {

src/cmd/go/internal/work/security_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ var goodLinkerFlags = [][]string{
140140
var badLinkerFlags = [][]string{
141141
{"-DFOO"},
142142
{"-Dfoo=bar"},
143-
{"-O"},
144-
{"-O2"},
145-
{"-Osmall"},
146143
{"-W"},
147144
{"-Wall"},
148145
{"-fobjc-arc"},
@@ -155,7 +152,6 @@ var badLinkerFlags = [][]string{
155152
{"-fno-stack-xxx"},
156153
{"-mstack-overflow"},
157154
{"-mno-stack-overflow"},
158-
{"-mmacosx-version"},
159155
{"-mnop-fun-dllimport"},
160156
{"-std=c99"},
161157
{"-xc"},

0 commit comments

Comments
 (0)