From 3aa380090f35529e58e4a393e8e0dee79dd0d491 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 2 Dec 2019 14:36:47 +0100 Subject: sys/syz-extract: extract constants from ELF Add a second mode that extracts constant values from ELF object, instead of running the executable. This allows to not (1) link binaries, (2) use proper cross-compiler. It finally fixes 386/arm extracts for my distro. Hopefully not makes things worse for others, should generally be safer/more reliable. The current mode is left b/c I can't test all OSes, windows binaries are not ELF, so we may need it anyway. But later we may switch more OSes to this new mode if they break (fuchsia?). --- sys/syz-extract/linux.go | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'sys/syz-extract/linux.go') diff --git a/sys/syz-extract/linux.go b/sys/syz-extract/linux.go index 4c759a19d..b4bfd0b1e 100644 --- a/sys/syz-extract/linux.go +++ b/sys/syz-extract/linux.go @@ -5,7 +5,6 @@ package main import ( "fmt" - "os/exec" "path/filepath" "runtime" "strings" @@ -111,13 +110,6 @@ 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 @@ -143,7 +135,7 @@ func (*linux) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]uint "-I" + buildDir + "/syzkaller", "-include", sourceDir + "/include/linux/kconfig.h", } - args = append(args, arch.target.CFlags...) + args = append(args, arch.target.CrossCFlags...) for _, incdir := range info.Incdirs { args = append(args, "-I"+sourceDir+"/"+incdir) } @@ -152,14 +144,12 @@ func (*linux) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]uint args = append(args, "-I"+dir) } } - const addSource = ` -#include -unsigned long phys_base; -#ifndef __phys_addr -unsigned long __phys_addr(unsigned long addr) { return 0; } -#endif -` - res, undeclared, err := extract(info, arch.cc, args, addSource, true, false) + params := &extractParams{ + AddSource: "#include ", + ExtractFromELF: true, + } + cc := arch.target.CCompilerPrefix + "gcc" + res, undeclared, err := extract(info, cc, args, params) if err != nil { return nil, nil, err } @@ -179,9 +169,3 @@ 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 -} -- cgit mrf-deployment