Skip to content

Commit 58fd7d2

Browse files
authored
Merge pull request #22 from andreabolognani/ldd-usr-lib
Look for libraries in /usr/lib too
2 parents 2d3e53c + 8893816 commit 58fd7d2

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

cmd/ldd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func NewLddCmd() *cobra.Command {
4848
}
4949

5050
files := []string{}
51-
dependencies, err := ldd.Resolve(objects, filepath.Join(tmpRoot, "/usr/lib64"))
51+
dependencies, err := ldd.Resolve(objects, []string{filepath.Join(tmpRoot, "/usr/lib64"), filepath.Join(tmpRoot, "/usr/lib")})
5252
if err != nil {
5353
return err
5454
}

pkg/ldd/ldd.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package ldd
22

33
import (
44
"debug/elf"
5+
"fmt"
56
"os"
67
"path/filepath"
78
)
89

9-
func Resolve(objects []string, library_path string) (finalFiles []string, err error) {
10+
func Resolve(objects []string, library_path []string) (finalFiles []string, err error) {
1011
discovered := map[string]struct{}{}
1112
for _, obj := range objects {
1213
if files, err := resolve(obj, library_path); err != nil {
@@ -23,7 +24,7 @@ func Resolve(objects []string, library_path string) (finalFiles []string, err er
2324
return
2425
}
2526

26-
func resolve(library string, library_path string) ([]string, error) {
27+
func resolve(library string, library_path []string) ([]string, error) {
2728

2829
next := []string{library}
2930
processed := map[string]struct{}{}
@@ -61,7 +62,7 @@ func resolve(library string, library_path string) ([]string, error) {
6162
return finalFiles, nil
6263
}
6364

64-
func ldd(library string, library_path string) (discovered []string, err error) {
65+
func ldd(library string, library_path []string) (discovered []string, err error) {
6566
bin, err := elf.Open(library)
6667
if err != nil {
6768
return nil, err
@@ -71,16 +72,27 @@ func ldd(library string, library_path string) (discovered []string, err error) {
7172
return nil, err
7273
}
7374
for _, l := range libs {
74-
_, err := os.Stat(filepath.Join(library_path, l))
75-
if err != nil {
76-
return nil, err
75+
found := false
76+
for _, dir := range library_path {
77+
_, err := os.Stat(filepath.Join(dir, l))
78+
if err != nil {
79+
if os.IsNotExist(err) {
80+
continue
81+
}
82+
return nil, err
83+
}
84+
discovered = append(discovered, filepath.Join(dir, l))
85+
symlinks, err := followSymlinks(filepath.Join(dir, l))
86+
if err != nil {
87+
return nil, err
88+
}
89+
discovered = append(discovered, symlinks...)
90+
found = true
91+
break
7792
}
78-
discovered = append(discovered, filepath.Join(library_path, l))
79-
symlinks, err := followSymlinks(filepath.Join(library_path, l))
80-
if err != nil {
81-
return nil, err
93+
if !found {
94+
return nil, fmt.Errorf("%v not found in any of %v", l, library_path)
8295
}
83-
discovered = append(discovered, symlinks...)
8496
}
8597
return discovered, nil
8698
}

0 commit comments

Comments
 (0)