diff options
| author | Alexander Potapenko <glider@google.com> | 2023-02-03 19:05:19 +0100 |
|---|---|---|
| committer | Alexander Potapenko <ramosian.glider@gmail.com> | 2023-02-04 10:52:22 +0100 |
| commit | be607b78d7dea8ef5a0267ae7396fded7dc016d5 (patch) | |
| tree | 6a04379094c6c4d2f81cf5d3cb064a8b982a1a66 | |
| parent | 1b2f701aa9a17abb7e27c7c1170d26398febf247 (diff) | |
sys/targets: use non-optional flags to test for optional flags
The behavior of certain flags (in particular link-time ones) may depend
on the target triple and other compiler options, therefore it's
insufficient to test them in the default host configuration.
Collect all non-optional flags and pass them to checkFlagSupported(), so
that support for optional flags is always tested in the presence of the
non-optional ones.
This is going to fix the problem with Clang 15 not supporting
-static-pie on MIPS, but silently passing the checkFlagSupported()
check, because it used to be performed on x86_64.
| -rw-r--r-- | sys/targets/targets.go | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/sys/targets/targets.go b/sys/targets/targets.go index 71988ea32..da701a7fd 100644 --- a/sys/targets/targets.go +++ b/sys/targets/targets.go @@ -836,11 +836,17 @@ func (target *Target) lazyInit() { } flags := make(map[string]*bool) + commonCFlags := []string{} + uncommonCFlags := []string{} var wg sync.WaitGroup for _, flag := range flagsToCheck { if !optionalCFlags[flag] { + commonCFlags = append(commonCFlags, flag) continue } + uncommonCFlags = append(uncommonCFlags, flag) + } + for _, flag := range uncommonCFlags { _, exists := flags[flag] if exists { continue @@ -850,7 +856,7 @@ func (target *Target) lazyInit() { wg.Add(1) go func(flag string) { defer wg.Done() - *res = checkFlagSupported(target, flag) + *res = checkFlagSupported(target, commonCFlags, flag) }(flag) } wg.Wait() @@ -888,8 +894,10 @@ func (target *Target) lazyInit() { } } -func checkFlagSupported(target *Target, flag string) bool { - cmd := exec.Command(target.CCompiler, "-x", "c++", "-", "-o", "/dev/null", "-Werror", flag) +func checkFlagSupported(target *Target, targetCFlags []string, flag string) bool { + args := []string{"-x", "c++", "-", "-o", "/dev/null", "-Werror", flag} + args = append(args, targetCFlags...) + cmd := exec.Command(target.CCompiler, args...) cmd.Stdin = strings.NewReader(simpleProg) return cmd.Run() == nil } |
