Commit 6a24de92 authored by Umang Parmar's avatar Umang Parmar Committed by Ian Lance Taylor

cmd/go: allow passing -U flag in cgo CFLAGS

Fixes #34730

Change-Id: I2a16bbbd7af386e0abf59e1cc4b7d6e4ca3047c6
GitHub-Last-Rev: 096ff5a59ace36ac6ed5a0c87b4eef061be6b937
GitHub-Pull-Request: golang/go#34899
Reviewed-on: https://go-review.googlesource.com/c/go/+/201039
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 78c168fc
...@@ -55,7 +55,7 @@ For example: ...@@ -55,7 +55,7 @@ For example:
The default pkg-config tool may be changed by setting the PKG_CONFIG environment variable. The default pkg-config tool may be changed by setting the PKG_CONFIG environment variable.
For security reasons, only a limited set of flags are allowed, notably -D, -I, and -l. For security reasons, only a limited set of flags are allowed, notably -D, -U, -I, and -l.
To allow additional flags, set CGO_CFLAGS_ALLOW to a regular expression To allow additional flags, set CGO_CFLAGS_ALLOW to a regular expression
matching the new flags. To disallow flags that would otherwise be allowed, matching the new flags. To disallow flags that would otherwise be allowed,
set CGO_CFLAGS_DISALLOW to a regular expression matching arguments set CGO_CFLAGS_DISALLOW to a regular expression matching arguments
......
...@@ -43,6 +43,7 @@ var re = lazyregexp.New ...@@ -43,6 +43,7 @@ var re = lazyregexp.New
var validCompilerFlags = []*lazyregexp.Regexp{ var validCompilerFlags = []*lazyregexp.Regexp{
re(`-D([A-Za-z_].*)`), re(`-D([A-Za-z_].*)`),
re(`-U([A-Za-z_]*)`),
re(`-F([^@\-].*)`), re(`-F([^@\-].*)`),
re(`-I([^@\-].*)`), re(`-I([^@\-].*)`),
re(`-O`), re(`-O`),
...@@ -51,6 +52,7 @@ var validCompilerFlags = []*lazyregexp.Regexp{ ...@@ -51,6 +52,7 @@ var validCompilerFlags = []*lazyregexp.Regexp{
re(`-W([^@,]+)`), // -Wall but not -Wa,-foo. re(`-W([^@,]+)`), // -Wall but not -Wa,-foo.
re(`-Wa,-mbig-obj`), re(`-Wa,-mbig-obj`),
re(`-Wp,-D([A-Za-z_].*)`), re(`-Wp,-D([A-Za-z_].*)`),
re(`-Wp, -U([A-Za-z_]*)`),
re(`-ansi`), re(`-ansi`),
re(`-f(no-)?asynchronous-unwind-tables`), re(`-f(no-)?asynchronous-unwind-tables`),
re(`-f(no-)?blocks`), re(`-f(no-)?blocks`),
...@@ -127,6 +129,7 @@ var validCompilerFlags = []*lazyregexp.Regexp{ ...@@ -127,6 +129,7 @@ var validCompilerFlags = []*lazyregexp.Regexp{
var validCompilerFlagsWithNextArg = []string{ var validCompilerFlagsWithNextArg = []string{
"-arch", "-arch",
"-D", "-D",
"-U",
"-I", "-I",
"-framework", "-framework",
"-isysroot", "-isysroot",
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
var goodCompilerFlags = [][]string{ var goodCompilerFlags = [][]string{
{"-DFOO"}, {"-DFOO"},
{"-Dfoo=bar"}, {"-Dfoo=bar"},
{"-Ufoo"},
{"-F/Qt"}, {"-F/Qt"},
{"-I/"}, {"-I/"},
{"-I/etc/passwd"}, {"-I/etc/passwd"},
...@@ -67,6 +68,7 @@ var goodCompilerFlags = [][]string{ ...@@ -67,6 +68,7 @@ var goodCompilerFlags = [][]string{
var badCompilerFlags = [][]string{ var badCompilerFlags = [][]string{
{"-D@X"}, {"-D@X"},
{"-D-X"}, {"-D-X"},
{"-Ufoo=bar"},
{"-F@dir"}, {"-F@dir"},
{"-F-dir"}, {"-F-dir"},
{"-I@dir"}, {"-I@dir"},
......
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