mirror of
https://github.com/reactos/syzkaller.git
synced 2024-11-23 11:29:46 +00:00
sys/syz-extract: use clang if gcc is broken
On my Debian gcc -m32 is hopelessly broken. Using clang fixes at least arch 386. Arch arm is still broken b/c clang does not like some of kernel arm inline assemly constraints.
This commit is contained in:
parent
a76bf83ffa
commit
edcd9e3c9a
@ -13,6 +13,7 @@ import (
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/google/syzkaller/pkg/ast"
|
||||
"github.com/google/syzkaller/pkg/compiler"
|
||||
@ -38,6 +39,9 @@ type Arch struct {
|
||||
files []*File
|
||||
err error
|
||||
done chan bool
|
||||
// Used by OS implementations:
|
||||
once sync.Once
|
||||
cc string
|
||||
}
|
||||
|
||||
type File struct {
|
||||
|
@ -5,6 +5,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
@ -110,6 +111,13 @@ func (*linux) prepareArch(arch *Arch) error {
|
||||
}
|
||||
|
||||
func (*linux) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]uint64, map[string]bool, error) {
|
||||
arch.once.Do(func() {
|
||||
arch.cc = "gcc"
|
||||
if !checkCompiler("gcc", arch.target.CFlags) &&
|
||||
checkCompiler("clang", arch.target.CFlags) {
|
||||
arch.cc = "clang"
|
||||
}
|
||||
})
|
||||
headerArch := arch.target.KernelHeaderArch
|
||||
sourceDir := arch.sourceDir
|
||||
buildDir := arch.buildDir
|
||||
@ -151,7 +159,7 @@ unsigned long phys_base;
|
||||
unsigned long __phys_addr(unsigned long addr) { return 0; }
|
||||
#endif
|
||||
`
|
||||
res, undeclared, err := extract(info, "gcc", args, addSource, true, false)
|
||||
res, undeclared, err := extract(info, arch.cc, args, addSource, true, false)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -171,3 +179,9 @@ unsigned long __phys_addr(unsigned long addr) { return 0; }
|
||||
}
|
||||
return res, undeclared, nil
|
||||
}
|
||||
|
||||
func checkCompiler(cc string, args []string) bool {
|
||||
cmd := exec.Command(cc, append(args, "-x", "c", "-", "-o", "/dev/null")...)
|
||||
cmd.Stdin = strings.NewReader("int main(){}")
|
||||
return cmd.Run() == nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user