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.
This commit is contained in:
Yuzhe Han 2017-06-26 16:52:47 +08:00 committed by Dmitry Vyukov
parent 9af3153420
commit 7077339b70
6 changed files with 28 additions and 8 deletions

View File

@ -12,3 +12,4 @@ Jeremy Huang
Shuai Bai
Alexander Popov
Jean-Baptiste Cayrou
Yuzhe Han

View File

@ -17,3 +17,4 @@ Jeremy Huang
Shuai Bai
Alexander Popov
Jean-Baptiste Cayrou
Yuzhe Han

View File

@ -159,5 +159,5 @@ As a result the executor number `n` will get values in the `[20000 + n * 4, 2000
## Misc
Description files also contain `include` directives that refer to Linux kernel header files
Description files also contain `include` directives that refer to Linux kernel header files, `incdir` directives that refer to custom Linux kernel header directories
and `define` directives that define symbolic constant values. See the following section for details.

View File

@ -14,6 +14,7 @@ import (
type Description struct {
Includes []string
Incdirs []string
Defines map[string]string
Syscalls []Syscall
Structs map[string]*Struct
@ -48,6 +49,7 @@ type Resource struct {
func Parse(in io.Reader) *Description {
p := newParser(in)
var includes []string
var incdirs []string
defines := make(map[string]string)
var syscalls []Syscall
structs := make(map[string]*Struct)
@ -164,6 +166,19 @@ func Parse(in io.Reader) *Description {
failf("struct '%v' is redefined as resource", name)
}
resources[id] = Resource{id, base, vals}
} else if name == "incdir" {
p.Parse('"')
var incdir []byte
for {
ch := p.Char()
if ch == '"' {
break
}
p.Parse(ch)
incdir = append(incdir, ch)
}
p.Parse('"')
incdirs = append(incdirs, string(incdir))
} else {
switch ch := p.Char(); ch {
case '(':
@ -237,6 +252,7 @@ func Parse(in io.Reader) *Description {
sort.Sort(syscallArray(syscalls))
return &Description{
Includes: includes,
Incdirs: incdirs,
Defines: defines,
Syscalls: syscalls,
Structs: structs,

View File

@ -121,7 +121,7 @@ func compileConsts(arch *Arch, desc *Description) map[string]uint64 {
return nil
}
consts, err := fetchValues(arch.KernelHeaderArch, valArr, append(desc.Includes, arch.KernelInclude), desc.Defines, arch.CFlags)
consts, err := fetchValues(arch.KernelHeaderArch, valArr, append(desc.Includes, arch.KernelInclude), desc.Incdirs, desc.Defines, arch.CFlags)
if err != nil {
failf("%v", err)
}

View File

@ -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()