in pkg/tools/profiling/go_library.go [75:118]
func (l *GoLibrary) ToModule(pid int32, modName, modPath string, moduleRange []*ModuleRange) (*Module, error) {
res := &Module{}
res.Name = modName
res.Path = modPath
res.Ranges = moduleRange
file, err := elf.Open(modPath)
if err != nil {
return nil, err
}
defer file.Close()
header := file.FileHeader
mType := ModuleTypeUnknown
switch header.Type {
case elf.ET_EXEC:
mType = ModuleTypeExec
case elf.ET_DYN:
mType = ModuleTypeSo
}
if mType == ModuleTypeUnknown {
if strings.HasSuffix(modPath, ".map") && path.Exists(modPath) {
mType = ModuleTypePerfMap
} else if modName == "[vdso]" {
mType = ModuleTypeVDSO
}
} else if mType == ModuleTypeSo {
section := file.Section(".text")
if section == nil {
return nil, fmt.Errorf("could not found .text section in so file: %s", modName)
}
res.SoAddr = section.Addr
res.SoOffset = section.Offset
}
res.Type = mType
// load all symbols
res.Symbols, err = l.AnalyzeSymbols(modPath)
if err != nil {
return nil, err
}
return res, nil
}