Skip to content

Commit a535c78

Browse files
authored
Allow LD_LIBRARY_PATH read from config (#1408)
1 parent 8e0f29f commit a535c78

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

lepton/image.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func BuildManifest(c *types.Config) (*fs.Manifest, error) {
344344
return nil, errors.Wrap(err, 1)
345345
}
346346

347-
deps, err := getSharedLibs(c.TargetRoot, c.Program)
347+
deps, err := getSharedLibs(c.TargetRoot, c.Program, c)
348348
if err != nil {
349349
return nil, errors.Wrap(err, 1)
350350
}

lepton/ldd_darwin.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/nanovms/ops/constants"
1212
"github.com/nanovms/ops/fs"
1313
"github.com/nanovms/ops/log"
14+
"github.com/nanovms/ops/types"
1415
)
1516

1617
// GetElfFileInfo returns an object with elf information of the path program
@@ -75,7 +76,7 @@ func findLib(targetRoot string, origin string, libDirs []string, path string) (s
7576
return "", "", os.ErrNotExist
7677
}
7778

78-
func _getSharedLibs(libs map[string]string, targetRoot string, path string) error {
79+
func _getSharedLibs(libs map[string]string, targetRoot string, path string, c *types.Config) error {
7980
path, err := fs.LookupFile(targetRoot, path)
8081
if err != nil {
8182
return errors.WrapPrefix(err, path, 0)
@@ -120,6 +121,11 @@ func _getSharedLibs(libs map[string]string, targetRoot string, path string) erro
120121
libDirs = append(libDirs, strings.Split(d, ":")...)
121122
}
122123
}
124+
125+
// 3. read LD_LIBRARY_PATH from config
126+
if configEnv, hasLibPaths := c.Env["LD_LIBRARY_PATH"]; hasLibPaths {
127+
libDirs = append(libDirs, strings.Split(configEnv, ":")...)
128+
}
123129
libDirs = append(libDirs, "/lib64", "/lib/x86_64-linux-gnu", "/usr/lib", "/usr/lib64", "/usr/lib/x86_64-linux-gnu")
124130

125131
dtNeeded, err := fd.DynString(elf.DT_NEEDED)
@@ -141,7 +147,7 @@ func _getSharedLibs(libs map[string]string, targetRoot string, path string) erro
141147
libs[libpath] = absLibpath
142148

143149
// append library dependencies
144-
err := _getSharedLibs(libs, targetRoot, absLibpath)
150+
err := _getSharedLibs(libs, targetRoot, absLibpath, c)
145151
if err != nil {
146152
return err
147153
}
@@ -166,7 +172,7 @@ func _getSharedLibs(libs map[string]string, targetRoot string, path string) erro
166172
}
167173
if _, ok := libs[ipath]; !ok {
168174
libs[ipath] = absIpath
169-
err := _getSharedLibs(libs, targetRoot, ipath)
175+
err := _getSharedLibs(libs, targetRoot, ipath, c)
170176
if err != nil {
171177
return err
172178
}
@@ -176,9 +182,9 @@ func _getSharedLibs(libs map[string]string, targetRoot string, path string) erro
176182
return nil
177183
}
178184

179-
func getSharedLibs(targetRoot string, path string) (map[string]string, error) {
185+
func getSharedLibs(targetRoot string, path string, c *types.Config) (map[string]string, error) {
180186
libs := make(map[string]string)
181-
err := _getSharedLibs(libs, targetRoot, path)
187+
err := _getSharedLibs(libs, targetRoot, path, c)
182188
if err != nil {
183189
return nil, err
184190
}

lepton/ldd_freebsd.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package lepton
33
import (
44
"debug/elf"
55
"errors"
6+
"github.com/nanovms/ops/types"
67
)
78

89
// GetElfFileInfo returns an object with elf information of the path program
@@ -22,7 +23,7 @@ func IsDynamicLinked(efd *elf.File) bool {
2223

2324
// works only on linux, need to
2425
// replace looking up in dynamic section in ELF
25-
func getSharedLibs(targetRoot string, path string) (map[string]string, error) {
26+
func getSharedLibs(targetRoot string, path string, c *types.Config) (map[string]string, error) {
2627
return nil, nil
2728
}
2829

lepton/ldd_linux.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111

1212
"github.com/go-errors/errors"
13+
"github.com/nanovms/ops/types"
1314
)
1415

1516
// GetElfFileInfo returns an object with elf information of the path program
@@ -47,7 +48,7 @@ func IsDynamicLinked(efd *elf.File) bool {
4748

4849
// works only on linux, need to
4950
// replace looking up in dynamic section in ELF
50-
func getSharedLibs(targetRoot string, path string) (map[string]string, error) {
51+
func getSharedLibs(targetRoot string, path string, c *types.Config) (map[string]string, error) {
5152
var notExistLib []string
5253
var absTargetRoot string
5354
if targetRoot != "" {

lepton/ldd_windows.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package lepton
33
import (
44
"debug/elf"
55
"errors"
6+
"github.com/nanovms/ops/types"
67
)
78

89
// IsDynamicLinked stub
@@ -21,7 +22,7 @@ func GetElfFileInfo(path string) (*elf.File, error) {
2122
}
2223

2324
// stub
24-
func getSharedLibs(targetRoot string, path string) (map[string]string, error) {
25+
func getSharedLibs(targetRoot string, path string, c *types.Config) (map[string]string, error) {
2526
var deps = make(map[string]string)
2627
return deps, nil
2728
}

0 commit comments

Comments
 (0)