syz-manager: Improve the computation of getVMOffset() on FreeBSD

On FreeBSD getVMOffset() always returned 0 instead of 0xffffffff.
This breaks the usage of addr2line. For now, just return always
0xffffffff on FreeBSD, since a more sophisticated logic doesn't
seem to be required by now.

Thanks to Dmitry for pointing out that this functions provides
the prefix address.
This commit is contained in:
Michael Tuexen 2018-12-31 19:07:41 +01:00 committed by Dmitry Vyukov
parent d580c113aa
commit 3d85f48c14
2 changed files with 10 additions and 7 deletions

View File

@ -25,7 +25,7 @@ var (
reportGenerator *cover.ReportGenerator
)
func initCover(kernelObj, kernelObjName, kernelSrc, arch string) error {
func initCover(kernelObj, kernelObjName, kernelSrc, arch, OS string) error {
if kernelObj == "" {
return fmt.Errorf("kernel_obj is not specified")
}
@ -35,15 +35,15 @@ func initCover(kernelObj, kernelObjName, kernelSrc, arch string) error {
if err != nil {
return err
}
initCoverVMOffset, err = getVMOffset(vmlinux)
initCoverVMOffset, err = getVMOffset(vmlinux, OS)
return err
}
func generateCoverHTML(w io.Writer, kernelObj, kernelObjName, kernelSrc, arch string, cov cover.Cover) error {
func generateCoverHTML(w io.Writer, kernelObj, kernelObjName, kernelSrc, arch, OS string, cov cover.Cover) error {
if len(cov) == 0 {
return fmt.Errorf("no coverage data available")
}
initCoverOnce.Do(func() { initCoverError = initCover(kernelObj, kernelObjName, kernelSrc, arch) })
initCoverOnce.Do(func() { initCoverError = initCover(kernelObj, kernelObjName, kernelSrc, arch, OS) })
if initCoverError != nil {
return initCoverError
}
@ -54,7 +54,10 @@ func generateCoverHTML(w io.Writer, kernelObj, kernelObjName, kernelSrc, arch st
return reportGenerator.Do(w, pcs)
}
func getVMOffset(vmlinux string) (uint32, error) {
func getVMOffset(vmlinux, OS string) (uint32, error) {
if OS == "freebsd" {
return 0xffffffff, nil
}
out, err := osutil.RunCmd(time.Hour, "", "readelf", "-SW", vmlinux)
if err != nil {
return 0, err

View File

@ -248,7 +248,7 @@ func (mgr *Manager) httpCoverCover(w http.ResponseWriter, r *http.Request) {
}
if err := generateCoverHTML(w, mgr.cfg.KernelObj, mgr.sysTarget.KernelObject,
mgr.cfg.KernelSrc, mgr.cfg.TargetVMArch, cov); err != nil {
mgr.cfg.KernelSrc, mgr.cfg.TargetVMArch, mgr.cfg.TargetOS, cov); err != nil {
http.Error(w, fmt.Sprintf("failed to generate coverage profile: %v", err), http.StatusInternalServerError)
return
}
@ -400,7 +400,7 @@ func (mgr *Manager) httpRawCover(w http.ResponseWriter, r *http.Request) {
initCoverOnce.Do(func() {
initCoverError = initCover(mgr.cfg.KernelObj, mgr.sysTarget.KernelObject,
mgr.cfg.KernelSrc, mgr.cfg.TargetArch)
mgr.cfg.KernelSrc, mgr.cfg.TargetArch, mgr.cfg.TargetOS)
})
if initCoverError != nil {
http.Error(w, initCoverError.Error(), http.StatusInternalServerError)