Skip to content

Commit

Permalink
Allow LD_LIBRARY_PATH read from config (#1408)
Browse files Browse the repository at this point in the history
  • Loading branch information
am11 committed Jan 17, 2023
1 parent 8e0f29f commit a535c78
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lepton/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func BuildManifest(c *types.Config) (*fs.Manifest, error) {
return nil, errors.Wrap(err, 1)
}

deps, err := getSharedLibs(c.TargetRoot, c.Program)
deps, err := getSharedLibs(c.TargetRoot, c.Program, c)
if err != nil {
return nil, errors.Wrap(err, 1)
}
Expand Down
16 changes: 11 additions & 5 deletions lepton/ldd_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/nanovms/ops/constants"
"github.com/nanovms/ops/fs"
"github.com/nanovms/ops/log"
"github.com/nanovms/ops/types"
)

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

func _getSharedLibs(libs map[string]string, targetRoot string, path string) error {
func _getSharedLibs(libs map[string]string, targetRoot string, path string, c *types.Config) error {
path, err := fs.LookupFile(targetRoot, path)
if err != nil {
return errors.WrapPrefix(err, path, 0)
Expand Down Expand Up @@ -120,6 +121,11 @@ func _getSharedLibs(libs map[string]string, targetRoot string, path string) erro
libDirs = append(libDirs, strings.Split(d, ":")...)
}
}

// 3. read LD_LIBRARY_PATH from config
if configEnv, hasLibPaths := c.Env["LD_LIBRARY_PATH"]; hasLibPaths {
libDirs = append(libDirs, strings.Split(configEnv, ":")...)
}
libDirs = append(libDirs, "/lib64", "/lib/x86_64-linux-gnu", "/usr/lib", "/usr/lib64", "/usr/lib/x86_64-linux-gnu")

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

// append library dependencies
err := _getSharedLibs(libs, targetRoot, absLibpath)
err := _getSharedLibs(libs, targetRoot, absLibpath, c)
if err != nil {
return err
}
Expand All @@ -166,7 +172,7 @@ func _getSharedLibs(libs map[string]string, targetRoot string, path string) erro
}
if _, ok := libs[ipath]; !ok {
libs[ipath] = absIpath
err := _getSharedLibs(libs, targetRoot, ipath)
err := _getSharedLibs(libs, targetRoot, ipath, c)
if err != nil {
return err
}
Expand All @@ -176,9 +182,9 @@ func _getSharedLibs(libs map[string]string, targetRoot string, path string) erro
return nil
}

func getSharedLibs(targetRoot string, path string) (map[string]string, error) {
func getSharedLibs(targetRoot string, path string, c *types.Config) (map[string]string, error) {
libs := make(map[string]string)
err := _getSharedLibs(libs, targetRoot, path)
err := _getSharedLibs(libs, targetRoot, path, c)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion lepton/ldd_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lepton
import (
"debug/elf"
"errors"
"github.com/nanovms/ops/types"
)

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

// works only on linux, need to
// replace looking up in dynamic section in ELF
func getSharedLibs(targetRoot string, path string) (map[string]string, error) {
func getSharedLibs(targetRoot string, path string, c *types.Config) (map[string]string, error) {
return nil, nil
}

Expand Down
3 changes: 2 additions & 1 deletion lepton/ldd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

"github.com/go-errors/errors"
"github.com/nanovms/ops/types"
)

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

// works only on linux, need to
// replace looking up in dynamic section in ELF
func getSharedLibs(targetRoot string, path string) (map[string]string, error) {
func getSharedLibs(targetRoot string, path string, c *types.Config) (map[string]string, error) {
var notExistLib []string
var absTargetRoot string
if targetRoot != "" {
Expand Down
3 changes: 2 additions & 1 deletion lepton/ldd_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lepton
import (
"debug/elf"
"errors"
"github.com/nanovms/ops/types"
)

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

// stub
func getSharedLibs(targetRoot string, path string) (map[string]string, error) {
func getSharedLibs(targetRoot string, path string, c *types.Config) (map[string]string, error) {
var deps = make(map[string]string)
return deps, nil
}

0 comments on commit a535c78

Please sign in to comment.