getBinaryDeps: properly handle circular lib dependencies

This moves the recursive bit outside of getBinaryDeps and properly
handles circular dependencies.
This commit is contained in:
Clayton Craft
2023-02-09 12:42:06 -08:00
parent b90624d7dd
commit 731a805a9e

View File

@@ -177,8 +177,11 @@ func getHookFiles(filesdir string) (files []string, err error) {
return files, nil
}
func getDeps(file string, parents map[string]struct{}) (files []string, err error) {
func getDeps(file string) (files []string, err error) {
if _, found := parents[file]; found {
return
}
// get dependencies for binaries
fd, err := elf.Open(file)
@@ -188,6 +191,7 @@ func getDeps(file string) (files []string, err error) {
libs, _ := fd.ImportedLibraries()
fd.Close()
files = append(files, file)
parents[file] = struct{}{}
if len(libs) == 0 {
return
@@ -208,7 +212,7 @@ func getDeps(file string) (files []string, err error) {
for _, libdir := range libdirs {
path := filepath.Join(libdir, lib)
if _, err := os.Stat(path); err == nil {
binaryDepFiles, err := getDeps(path)
binaryDepFiles, err := getDeps(path, parents)
if err != nil {
return nil, err
}