syzkaller/sys/syz-extract/fuchsia.go
Dmitry Vyukov 3aa380090f 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?).
2019-12-02 14:36:47 +01:00

46 lines
1.4 KiB
Go

// Copyright 2017 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package main
import (
"fmt"
"path/filepath"
"github.com/google/syzkaller/pkg/compiler"
"github.com/google/syzkaller/sys/fuchsia/layout"
)
type fuchsia struct{}
func (*fuchsia) prepare(sourcedir string, build bool, arches []string) error {
if sourcedir == "" {
return fmt.Errorf("provide path to kernel checkout via -sourcedir flag (or make extract SOURCEDIR)")
}
return nil
}
func (*fuchsia) prepareArch(arch *Arch) error {
return nil
}
func (*fuchsia) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]uint64, map[string]bool, error) {
dir := arch.sourceDir
headerArch := arch.target.KernelHeaderArch
cc := filepath.Join(dir, "prebuilt", "third_party", "clang", "linux-x64", "bin", "clang")
includeDir := filepath.Join(dir, "out", headerArch, "sdk", "exported",
"zircon_sysroot", "arch", headerArch, "sysroot", "include")
args := []string{"-fmessage-length=0", "-I" + includeDir}
for _, fidlLib := range layout.AllFidlLibraries {
args = append(args, "-I"+filepath.Join(dir, "out", headerArch, fidlLib.PathToCompiledDir()))
}
for _, incdir := range info.Incdirs {
args = append(args, "-I"+filepath.Join(dir, incdir))
}
params := &extractParams{
DeclarePrintf: true,
DefineGlibcUse: true,
}
return extract(info, cc, args, params)
}