Commit 7e34ac1f authored by Ian Lance Taylor's avatar Ian Lance Taylor

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 <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarAndrew Bonventre <andybons@golang.org>
parent 89f4592d
...@@ -46,12 +46,19 @@ var validCompilerFlags = []*regexp.Regexp{ ...@@ -46,12 +46,19 @@ var validCompilerFlags = []*regexp.Regexp{
re(`-O([^@\-].*)`), re(`-O([^@\-].*)`),
re(`-W`), re(`-W`),
re(`-W([^@,]+)`), // -Wall but not -Wa,-foo. re(`-W([^@,]+)`), // -Wall but not -Wa,-foo.
re(`-Wa,-mbig-obj`),
re(`-ansi`),
re(`-f(no-)?blocks`), re(`-f(no-)?blocks`),
re(`-f(no-)?common`), re(`-f(no-)?common`),
re(`-f(no-)?constant-cfstrings`), re(`-f(no-)?constant-cfstrings`),
re(`-fdiagnostics-show-note-include-stack`),
re(`-f(no-)?exceptions`), re(`-f(no-)?exceptions`),
re(`-f(no-)?inline-functions`),
re(`-finput-charset=([^@\-].*)`), re(`-finput-charset=([^@\-].*)`),
re(`-f(no-)?fat-lto-objects`),
re(`-f(no-)?lto`), re(`-f(no-)?lto`),
re(`-fmacro-backtrace-limit=(.+)`),
re(`-fmessage-length=(.+)`),
re(`-f(no-)?modules`), re(`-f(no-)?modules`),
re(`-f(no-)?objc-arc`), re(`-f(no-)?objc-arc`),
re(`-f(no-)?omit-frame-pointer`), re(`-f(no-)?omit-frame-pointer`),
...@@ -62,27 +69,42 @@ var validCompilerFlags = []*regexp.Regexp{ ...@@ -62,27 +69,42 @@ var validCompilerFlags = []*regexp.Regexp{
re(`-f(no-)?split-stack`), re(`-f(no-)?split-stack`),
re(`-f(no-)?stack-(.+)`), re(`-f(no-)?stack-(.+)`),
re(`-f(no-)?strict-aliasing`), re(`-f(no-)?strict-aliasing`),
re(`-f(un)signed-char`),
re(`-f(no-)?use-linker-plugin`), // safe if -B is not used; we don't permit -B
re(`-fsanitize=(.+)`), re(`-fsanitize=(.+)`),
re(`-ftemplate-depth-(.+)`),
re(`-fvisibility=(.+)`),
re(`-g([^@\-].*)?`), re(`-g([^@\-].*)?`),
re(`-m32`),
re(`-m64`),
re(`-m(arch|cpu|fpu|tune)=([^@\-].*)`), re(`-m(arch|cpu|fpu|tune)=([^@\-].*)`),
re(`-m(no-)?avx[0-9a-z.]*`), re(`-m(no-)?avx[0-9a-z.]*`),
re(`-m(no-)?ms-bitfields`), re(`-m(no-)?ms-bitfields`),
re(`-m(no-)?stack-(.+)`), re(`-m(no-)?stack-(.+)`),
re(`-mmacosx-(.+)`), re(`-mmacosx-(.+)`),
re(`-mios-simulator-version-min=(.+)`),
re(`-miphoneos-version-min=(.+)`),
re(`-mnop-fun-dllimport`), re(`-mnop-fun-dllimport`),
re(`-m(no-)?sse[0-9.]*`), re(`-m(no-)?sse[0-9.]*`),
re(`-mwindows`),
re(`-pedantic(-errors)?`), re(`-pedantic(-errors)?`),
re(`-pipe`), re(`-pipe`),
re(`-pthread`), re(`-pthread`),
re(`-?-std=([^@\-].*)`), re(`-?-std=([^@\-].*)`),
re(`-?-stdlib=([^@\-].*)`),
re(`-w`),
re(`-x([^@\-].*)`), re(`-x([^@\-].*)`),
} }
var validCompilerFlagsWithNextArg = []string{ var validCompilerFlagsWithNextArg = []string{
"-arch",
"-D", "-D",
"-I", "-I",
"-isystem",
"-framework", "-framework",
"-isysroot",
"-isystem",
"--sysroot",
"-target",
"-x", "-x",
} }
...@@ -90,43 +112,65 @@ var validLinkerFlags = []*regexp.Regexp{ ...@@ -90,43 +112,65 @@ var validLinkerFlags = []*regexp.Regexp{
re(`-F([^@\-].*)`), re(`-F([^@\-].*)`),
re(`-l([^@\-].*)`), re(`-l([^@\-].*)`),
re(`-L([^@\-].*)`), re(`-L([^@\-].*)`),
re(`-O`),
re(`-O([^@\-].*)`),
re(`-f(no-)?(pic|PIC|pie|PIE)`), re(`-f(no-)?(pic|PIC|pie|PIE)`),
re(`-fsanitize=([^@\-].*)`), re(`-fsanitize=([^@\-].*)`),
re(`-g([^@\-].*)?`), re(`-g([^@\-].*)?`),
re(`-m(arch|cpu|fpu|tune)=([^@\-].*)`), re(`-m(arch|cpu|fpu|tune)=([^@\-].*)`),
re(`-mmacosx-(.+)`),
re(`-mios-simulator-version-min=(.+)`),
re(`-miphoneos-version-min=(.+)`),
re(`-mwindows`),
re(`-(pic|PIC|pie|PIE)`), re(`-(pic|PIC|pie|PIE)`),
re(`-pthread`), re(`-pthread`),
re(`-shared`),
re(`-?-static([-a-z0-9+]*)`), re(`-?-static([-a-z0-9+]*)`),
re(`-?-stdlib=([^@\-].*)`),
// Note that any wildcards in -Wl need to exclude comma, // Note that any wildcards in -Wl need to exclude comma,
// since -Wl splits its argument at commas and passes // since -Wl splits its argument at commas and passes
// them all to the linker uninterpreted. Allowing comma // them all to the linker uninterpreted. Allowing comma
// in a wildcard would allow tunnelling arbitrary additional // in a wildcard would allow tunnelling arbitrary additional
// linker arguments through one of these. // linker arguments through one of these.
re(`-Wl,--(no-)?allow-multiple-definition`),
re(`-Wl,--(no-)?as-needed`), re(`-Wl,--(no-)?as-needed`),
re(`-Wl,-Bdynamic`), re(`-Wl,-Bdynamic`),
re(`-Wl,-Bstatic`), re(`-Wl,-Bstatic`),
re(`-Wl,-d[ny]`),
re(`-Wl,--disable-new-dtags`), re(`-Wl,--disable-new-dtags`),
re(`-Wl,--enable-new-dtags`), re(`-Wl,--enable-new-dtags`),
re(`-Wl,--end-group`), re(`-Wl,--end-group`),
re(`-Wl,-framework,[^,@\-][^,]+`), re(`-Wl,-framework,[^,@\-][^,]+`),
re(`-Wl,-headerpad_max_install_names`), re(`-Wl,-headerpad_max_install_names`),
re(`-Wl,--no-undefined`), re(`-Wl,--no-undefined`),
re(`-Wl,-rpath,([^,@\-][^,]+)`), re(`-Wl,-rpath[=,]([^,@\-][^,]+)`),
re(`-Wl,-search_paths_first`), re(`-Wl,-search_paths_first`),
re(`-Wl,-sectcreate,([^,@\-][^,]+),([^,@\-][^,]+),([^,@\-][^,]+)`),
re(`-Wl,--start-group`), re(`-Wl,--start-group`),
re(`-Wl,-?-static`),
re(`-Wl,--subsystem,(native|windows|console|posix|xbox)`),
re(`-Wl,-undefined[=,]([^,@\-][^,]+)`),
re(`-Wl,-?-unresolved-symbols=[^,]+`), re(`-Wl,-?-unresolved-symbols=[^,]+`),
re(`-Wl,--(no-)?warn-([^,]+)`), re(`-Wl,--(no-)?warn-([^,]+)`),
re(`-Wl,-z,(no)?execstack`),
re(`-Wl,-z,relro`),
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) 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)
} }
var validLinkerFlagsWithNextArg = []string{ var validLinkerFlagsWithNextArg = []string{
"-arch",
"-F", "-F",
"-l", "-l",
"-L", "-L",
"-framework", "-framework",
"-isysroot",
"--sysroot",
"-target",
"-Wl,-framework", "-Wl,-framework",
"-Wl,-rpath",
"-Wl,-undefined",
} }
func checkCompilerFlags(name, source string, list []string) error { func checkCompilerFlags(name, source string, list []string) error {
......
...@@ -140,9 +140,6 @@ var goodLinkerFlags = [][]string{ ...@@ -140,9 +140,6 @@ var goodLinkerFlags = [][]string{
var badLinkerFlags = [][]string{ var badLinkerFlags = [][]string{
{"-DFOO"}, {"-DFOO"},
{"-Dfoo=bar"}, {"-Dfoo=bar"},
{"-O"},
{"-O2"},
{"-Osmall"},
{"-W"}, {"-W"},
{"-Wall"}, {"-Wall"},
{"-fobjc-arc"}, {"-fobjc-arc"},
...@@ -155,7 +152,6 @@ var badLinkerFlags = [][]string{ ...@@ -155,7 +152,6 @@ var badLinkerFlags = [][]string{
{"-fno-stack-xxx"}, {"-fno-stack-xxx"},
{"-mstack-overflow"}, {"-mstack-overflow"},
{"-mno-stack-overflow"}, {"-mno-stack-overflow"},
{"-mmacosx-version"},
{"-mnop-fun-dllimport"}, {"-mnop-fun-dllimport"},
{"-std=c99"}, {"-std=c99"},
{"-xc"}, {"-xc"},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment