syz-extract: select declaring printf or not

Kernels are standalone implementations and can have their own
implementations of functions that have different prototypes than
the standard ones. In the NetBSD case the kernel printf returns
void, and it is declared in <sys/systm.h> so avoid re-declaring it.
Select if we are going to declare printf or not depending on the OS.
This commit is contained in:
zoulasc 2017-10-28 13:43:21 -04:00 committed by Dmitry Vyukov
parent 7afa56efb4
commit 3520854be0
7 changed files with 19 additions and 15 deletions

View File

@ -30,5 +30,5 @@ func (*akaros) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]uin
for _, incdir := range info.Incdirs {
args = append(args, "-I"+filepath.Join(dir, incdir))
}
return extract(info, "gcc", args, "")
return extract(info, "gcc", args, "", true)
}

View File

@ -17,12 +17,13 @@ import (
"github.com/google/syzkaller/pkg/compiler"
)
func extract(info *compiler.ConstInfo, cc string, args []string, addSource string) (map[string]uint64, map[string]bool, error) {
func extract(info *compiler.ConstInfo, cc string, args []string, addSource string, declarePrintf bool) (map[string]uint64, map[string]bool, error) {
data := &CompileData{
AddSource: addSource,
Defines: info.Defines,
Includes: info.Includes,
Values: info.Consts,
AddSource: addSource,
Defines: info.Defines,
Includes: info.Includes,
Values: info.Consts,
DeclarePrintf: declarePrintf,
}
undeclared := make(map[string]bool)
bin, out, err := compile(cc, args, data)
@ -88,10 +89,11 @@ func extract(info *compiler.ConstInfo, cc string, args []string, addSource strin
}
type CompileData struct {
AddSource string
Defines map[string]string
Includes []string
Values []string
AddSource string
Defines map[string]string
Includes []string
Values []string
DeclarePrintf bool
}
func compile(cc string, args []string, data *CompileData) (bin string, out []byte, err error) {
@ -144,7 +146,9 @@ var srcTemplate = template.Must(template.New("").Parse(`
{{.AddSource}}
{{.DeclarePrintf}}
int printf(const char *format, ...);
{{end}}
int main() {
int i;

View File

@ -67,7 +67,7 @@ func (*freebsd) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]ui
info.Consts = append(info.Consts, compat)
}
}
res, undeclared, err := extract(info, "gcc", args, "#include <sys/syscall.h>")
res, undeclared, err := extract(info, "gcc", args, "#include <sys/syscall.h>", true)
for orig, compats := range compatNames {
for _, compat := range compats {
if undeclared[orig] && !undeclared[compat] {

View File

@ -31,5 +31,5 @@ func (*fuchsia) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]ui
for _, incdir := range info.Incdirs {
args = append(args, "-I"+filepath.Join(dir, incdir))
}
return extract(info, cc, args, "")
return extract(info, cc, args, "", true)
}

View File

@ -103,5 +103,5 @@ unsigned long phys_base;
unsigned long __phys_addr(unsigned long addr) { return 0; }
#endif
`
return extract(info, "gcc", args, addSource)
return extract(info, "gcc", args, addSource, true)
}

View File

@ -85,7 +85,7 @@ func (*netbsd) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]uin
info.Consts = append(info.Consts, compat)
}
}
res, undeclared, err := extract(info, "gcc", args, "#include <sys/syscall.h>")
res, undeclared, err := extract(info, "gcc", args, "#include <sys/syscall.h>", false)
for orig, compats := range compatNames {
for _, compat := range compats {
if undeclared[orig] && !undeclared[compat] {

View File

@ -18,5 +18,5 @@ func (*windows) prepareArch(arch *Arch) error {
}
func (*windows) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]uint64, map[string]bool, error) {
return extract(info, "cl", nil, "")
return extract(info, "cl", nil, "", true)
}