@@ -34,6 +34,7 @@ import (
34
34
"fmt"
35
35
"os"
36
36
"regexp"
37
+ "strings"
37
38
)
38
39
39
40
var re = regexp .MustCompile
@@ -45,26 +46,42 @@ var validCompilerFlags = []*regexp.Regexp{
45
46
re (`-O([^@\-].*)` ),
46
47
re (`-W` ),
47
48
re (`-W([^@,]+)` ), // -Wall but not -Wa,-foo.
49
+ re (`-f(no-)?blocks` ),
50
+ re (`-f(no-)?common` ),
51
+ re (`-f(no-)?constant-cfstrings` ),
52
+ re (`-f(no-)?exceptions` ),
53
+ re (`-finput-charset=([^@\-].*)` ),
54
+ re (`-f(no-)?lto` ),
55
+ re (`-f(no-)?modules` ),
48
56
re (`-f(no-)?objc-arc` ),
49
57
re (`-f(no-)?omit-frame-pointer` ),
58
+ re (`-f(no-)?openmp(-simd)?` ),
59
+ re (`-f(no-)?permissive` ),
50
60
re (`-f(no-)?(pic|PIC|pie|PIE)` ),
61
+ re (`-f(no-)?rtti` ),
51
62
re (`-f(no-)?split-stack` ),
52
63
re (`-f(no-)?stack-(.+)` ),
53
64
re (`-f(no-)?strict-aliasing` ),
54
65
re (`-fsanitize=(.+)` ),
55
66
re (`-g([^@\-].*)?` ),
56
67
re (`-m(arch|cpu|fpu|tune)=([^@\-].*)` ),
68
+ re (`-m(no-)?avx[0-9a-z.]*` ),
69
+ re (`-m(no-)?ms-bitfields` ),
57
70
re (`-m(no-)?stack-(.+)` ),
58
71
re (`-mmacosx-(.+)` ),
59
72
re (`-mnop-fun-dllimport` ),
73
+ re (`-m(no-)?sse[0-9.]*` ),
74
+ re (`-pedantic(-errors)?` ),
75
+ re (`-pipe` ),
60
76
re (`-pthread` ),
61
- re (`-std=([^@\-].*)` ),
77
+ re (`-?- std=([^@\-].*)` ),
62
78
re (`-x([^@\-].*)` ),
63
79
}
64
80
65
81
var validCompilerFlagsWithNextArg = []string {
66
82
"-D" ,
67
83
"-I" ,
84
+ "-isystem" ,
68
85
"-framework" ,
69
86
"-x" ,
70
87
}
@@ -79,23 +96,37 @@ var validLinkerFlags = []*regexp.Regexp{
79
96
re (`-m(arch|cpu|fpu|tune)=([^@\-].*)` ),
80
97
re (`-(pic|PIC|pie|PIE)` ),
81
98
re (`-pthread` ),
99
+ re (`-?-static([-a-z0-9+]*)` ),
82
100
83
101
// Note that any wildcards in -Wl need to exclude comma,
84
102
// since -Wl splits its argument at commas and passes
85
103
// them all to the linker uninterpreted. Allowing comma
86
104
// in a wildcard would allow tunnelling arbitrary additional
87
105
// linker arguments through one of these.
106
+ re (`-Wl,--(no-)?as-needed` ),
107
+ re (`-Wl,-Bdynamic` ),
108
+ re (`-Wl,-Bstatic` ),
109
+ re (`-Wl,--disable-new-dtags` ),
110
+ re (`-Wl,--enable-new-dtags` ),
111
+ re (`-Wl,--end-group` ),
112
+ re (`-Wl,-framework,[^,@\-][^,]+` ),
113
+ re (`-Wl,-headerpad_max_install_names` ),
114
+ re (`-Wl,--no-undefined` ),
88
115
re (`-Wl,-rpath,([^,@\-][^,]+)` ),
116
+ re (`-Wl,-search_paths_first` ),
117
+ re (`-Wl,--start-group` ),
118
+ re (`-Wl,-?-unresolved-symbols=[^,]+` ),
89
119
re (`-Wl,--(no-)?warn-([^,]+)` ),
90
120
91
- re (`[a-zA-Z0-9_].*\.(o|obj|dll|dylib|so)` ), // direct linker inputs: x.o or libfoo.so (but not -foo.o or @foo.o)
121
+ 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)
92
122
}
93
123
94
124
var validLinkerFlagsWithNextArg = []string {
95
125
"-F" ,
96
126
"-l" ,
97
127
"-L" ,
98
128
"-framework" ,
129
+ "-Wl,-framework" ,
99
130
}
100
131
101
132
func checkCompilerFlags (name , source string , list []string ) error {
@@ -147,10 +178,21 @@ Args:
147
178
i ++
148
179
continue Args
149
180
}
181
+
182
+ // Permit -Wl,-framework -Wl,name.
183
+ if i + 1 < len (list ) &&
184
+ strings .HasPrefix (arg , "-Wl," ) &&
185
+ strings .HasPrefix (list [i + 1 ], "-Wl," ) &&
186
+ load .SafeArg (list [i + 1 ][4 :]) &&
187
+ ! strings .Contains (list [i + 1 ][4 :], "," ) {
188
+ i ++
189
+ continue Args
190
+ }
191
+
150
192
if i + 1 < len (list ) {
151
- return fmt .Errorf ("invalid flag in %s: %s %s" , source , arg , list [i + 1 ])
193
+ return fmt .Errorf ("invalid flag in %s: %s %s (see https://golang.org/s/invalidflag) " , source , arg , list [i + 1 ])
152
194
}
153
- return fmt .Errorf ("invalid flag in %s: %s without argument" , source , arg )
195
+ return fmt .Errorf ("invalid flag in %s: %s without argument (see https://golang.org/s/invalidflag) " , source , arg )
154
196
}
155
197
}
156
198
Bad:
0 commit comments