From be607b78d7dea8ef5a0267ae7396fded7dc016d5 Mon Sep 17 00:00:00 2001 From: Alexander Potapenko Date: Fri, 3 Feb 2023 19:05:19 +0100 Subject: 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. --- sys/targets/targets.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'sys') 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 } -- cgit mrf-deployment