diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2019-12-02 14:36:47 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2019-12-02 14:36:47 +0100 |
| commit | 3aa380090f35529e58e4a393e8e0dee79dd0d491 (patch) | |
| tree | 90f8fd02769965193155c22056f61afcd3786a52 /sys/syz-extract/linux.go | |
| parent | f879db37f90dcefb681897d2e486c11d8298cb72 (diff) | |
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?).
Diffstat (limited to 'sys/syz-extract/linux.go')
| -rw-r--r-- | sys/syz-extract/linux.go | 30 |
1 files changed, 7 insertions, 23 deletions
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 <asm/unistd.h> -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 <asm/unistd.h>", + 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 -} |
