diff options
| author | Yuzhe Han <hyz0906@gmail.com> | 2017-06-26 16:52:47 +0800 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2017-06-26 10:52:47 +0200 |
| commit | 7077339b7023f597d9d91113974204fbc7ff43cc (patch) | |
| tree | 9282720ad883993598c9c8c621caea53f49ab63f /sys/syz-extract/fetch.go | |
| parent | 9af315342072b6df7f56cf5387534f390c794fa0 (diff) | |
Parse incdir "incdir" in syscall description file to add custom include directories. (#180)
* Parse #incdir "incdir" in syscall description file to add custom include directories.
* add flagLinux
* remove '#' in incdir flag
* Update sys/README.md AUTHORS CONTRIBUTORS.
Diffstat (limited to 'sys/syz-extract/fetch.go')
| -rw-r--r-- | sys/syz-extract/fetch.go | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/sys/syz-extract/fetch.go b/sys/syz-extract/fetch.go index 79c080807..691b64481 100644 --- a/sys/syz-extract/fetch.go +++ b/sys/syz-extract/fetch.go @@ -16,8 +16,8 @@ import ( // fetchValues converts literal constants (e.g. O_APPEND) or any other C expressions // into their respective numeric values. It does so by builting and executing a C program // that prints values of the provided expressions. -func fetchValues(arch string, vals []string, includes []string, defines map[string]string, cflags []string) (map[string]uint64, error) { - bin, out, err := runCompiler(arch, nil, includes, nil, cflags, nil) +func fetchValues(arch string, vals []string, includes []string, incdirs []string, defines map[string]string, cflags []string) (map[string]uint64, error) { + bin, out, err := runCompiler(arch, nil, includes, incdirs, nil, cflags, nil) if err != nil { return nil, fmt.Errorf("failed to run gcc: %v\n%v", err, string(out)) } @@ -29,7 +29,7 @@ func fetchValues(arch string, vals []string, includes []string, defines map[stri } undeclared := make(map[string]bool) - bin, out, err = runCompiler(arch, vals, includes, defines, cflags, undeclared) + bin, out, err = runCompiler(arch, vals, includes, incdirs, defines, cflags, undeclared) if err != nil { for _, errMsg := range []string{ "error: ‘([a-zA-Z0-9_]+)’ undeclared", @@ -45,7 +45,7 @@ func fetchValues(arch string, vals []string, includes []string, defines map[stri } } } - bin, out, err = runCompiler(arch, vals, includes, defines, cflags, undeclared) + bin, out, err = runCompiler(arch, vals, includes, incdirs, defines, cflags, undeclared) if err != nil { return nil, fmt.Errorf("failed to run gcc: %v\n%v", err, string(out)) } @@ -79,7 +79,7 @@ func fetchValues(arch string, vals []string, includes []string, defines map[stri return res, nil } -func runCompiler(arch string, vals []string, includes []string, defines map[string]string, cflags []string, undeclared map[string]bool) (bin string, out []byte, err error) { +func runCompiler(arch string, vals []string, includes []string, incdirs []string, defines map[string]string, cflags []string, undeclared map[string]bool) (bin string, out []byte, err error) { includeText := "" for _, inc := range includes { includeText += fmt.Sprintf("#include <%v>\n", inc) @@ -130,7 +130,9 @@ func runCompiler(arch string, vals []string, includes []string, defines map[stri "-I" + *flagLinux, "-include", *flagLinux + "/include/linux/kconfig.h", }...) - + for _, incdir := range incdirs { + args = append(args, "-I" + *flagLinux + "/" + incdir,) + } cmd := exec.Command("gcc", args...) cmd.Stdin = strings.NewReader(src) out, err = cmd.CombinedOutput() |
