Skip to content

Commit

Permalink
Tweaks (#10)
Browse files Browse the repository at this point in the history
* tweaks
* change import style
* version bump

Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed Aug 31, 2022
1 parent 0ff6e06 commit a7e11d5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
The versions coincide with releases on pip. Only major versions will be released as tags on Github.

## [0.0.x](https://github.scom/vsoch/elfcall/tree/main) (0.0.x)
- tweaks to ld library path logic (0.0.15)
- typo use_versions instead of user_versions (0.0.14)
- add default argument to not use symbol versions (0.0.13)
- add support to provide custom LD_LIBRARY_PATH (0.0.12)
Expand Down
29 changes: 18 additions & 11 deletions elfcall/main/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import os
from copy import deepcopy

import elfcall.main.elf as elf
import elfcall.main.graph as graph
import elfcall.main.ld as ld
from . import elf, graph, ld
from elfcall.logger import logger


Expand Down Expand Up @@ -203,11 +201,12 @@ def gen_output(
logger.exit("A binary is required.")
self.reset()

self.ld.parse(secure=secure, no_default_libs=no_default_libs)

# If we are adding lb_library_libs manually
if ld_library_paths:
self.ld.prepend_ld_library_paths(ld_library_paths)

self.ld.parse(secure=secure, no_default_libs=no_default_libs)
return self.parse_binary(binary, use_versions=use_versions)

def gen(self, binary=None, fmt=None, secure=False, no_default_libs=False):
Expand Down Expand Up @@ -354,7 +353,7 @@ def find_library(self, name, paths, match_to=None, use_versions=False):
"""
Given a listing of paths, look for a library by name
"""
logger.debug("Looking for %s" % name)
logger.info("Looking for %s" % name)

# More rare case - the name is a path and it exists
# If a shared object name has one or more slash (/) characters anywhere in the name
Expand Down Expand Up @@ -415,8 +414,13 @@ def parse_dir(self, path):
"""
# Lookup of name to fullpath
libs = {}

for root, dirs, files in os.walk(path):
for filename in files:

# We need to save all indices to any symlink as an entry
symlinks = set()

fullpath = os.path.join(root, filename)
if not fullpath:
continue
Expand All @@ -426,18 +430,21 @@ def parse_dir(self, path):
continue

# NOTE the link name may be different than first one!
if os.path.islink(fullpath):
# We need to follow symlinks until we don't have anymore
realpath = fullpath
while os.path.islink(realpath):
symlinks.add(realpath)
realpath = os.path.realpath(fullpath)
else:
realpath = fullpath
symlinks.add(realpath)

# Ignore anything that isn't a file
if not os.path.isfile(fullpath):
continue

# Can we have repeated libs? This assumes we only grab the first
basename = os.path.basename(fullpath)
if basename not in libs:
libs[basename] = {"realpath": realpath, "fullpath": fullpath}
for symlink_path in symlinks:
basename = os.path.basename(symlink_path)
if basename not in libs:
libs[basename] = {"realpath": realpath, "fullpath": fullpath}

return libs
4 changes: 1 addition & 3 deletions elfcall/main/ld.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ def prepend_ld_library_paths(self, paths):
Prepend ld library paths we are emulating to be in the environment.
"""
self.library_paths = self.library_paths or []
self.library_paths = [
x for x in paths if x not in self.library_paths
] + self.library_paths
self.library_paths += [x for x in paths if x not in self.library_paths]

def find_source(self, name):
"""
Expand Down
2 changes: 1 addition & 1 deletion elfcall/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__copyright__ = "Copyright 2022, Vanessa Sochat"
__license__ = "GPL-3.0"

__version__ = "0.0.14"
__version__ = "0.0.15"
AUTHOR = "Vanessa Sochat"
EMAIL = "vsoch@users.noreply.github.io"
NAME = "elfcall"
Expand Down

0 comments on commit a7e11d5

Please sign in to comment.