golang/go

debug/macho: no SymtabCmd data in *macho.Symtab Load after calling macho.Open()

Open

#38,556 opened on Apr 21, 2020

View on GitHub
 (4 comments) (0 reactions) (0 assignees)Go (19,008 forks)batch import
NeedsInvestigationhelp wanted

Repository metrics

Stars
 (133,883 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

What version of Go are you using (go version)?

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

What did you do?

file, _ := macho.Open("xxx.o")    // which has Mach-O format with MH_OBJECT type
for i, l := range file.Loads {
    switch lo := l.(type) {
        case *macho.Symtab:
            fmt.Println(lo.SymtabCmd)    // nothing but zero value
    }
}

What did you expect to see?

Non-zero value of lo.SymtabCmd.

What did you see instead?

Zero value of lo.SymtabCmd.

Possible causes

parseSymtab() function in debug/macho/file.go:

        ...
	st := new(Symtab)
	st.LoadBytes = LoadBytes(cmddat)
	st.Syms = symtab
	return st, nil
}

ignore st.SymtabCmd ? It cound be:

        ...
	st := new(Symtab)
	st.LoadBytes = LoadBytes(cmddat)
	st.Syms = symtab
        st.SymtabCmd = *hdr
	return st, nil
}

Contributor guide