Index: pax-utils-0.7/lddtree.py =================================================================== --- pax-utils-0.7.orig/lddtree.py +++ pax-utils-0.7/lddtree.py @@ -179,7 +179,7 @@ def ParseLdSoConf(ldso_conf, root='/', _ return paths -def LoadLdpaths(root='/'): +def LoadLdpaths(root='/', prefix=''): """Load linker paths from common locations This parses the ld.so.conf and LD_LIBRARY_PATH env var. @@ -207,7 +207,7 @@ def LoadLdpaths(root='/'): ldpaths['env'] = ParseLdPaths(env_ldpath, path='') # Load up /etc/ld.so.conf. - ldpaths['conf'] = ParseLdSoConf(root + 'etc/ld.so.conf', root=root) + ldpaths['conf'] = ParseLdSoConf(root + prefix + '/etc/ld.so.conf', root=root) return ldpaths @@ -254,7 +254,7 @@ def FindLib(elf, lib, ldpaths): return None -def ParseELF(path, root='/', ldpaths={'conf':[], 'env':[], 'interp':[]}, +def ParseELF(path, root='/', prefix='', ldpaths={'conf':[], 'env':[], 'interp':[]}, _first=True, _all_libs={}): """Parse the ELF dependency tree of the specified file @@ -262,6 +262,8 @@ def ParseELF(path, root='/', ldpaths={'c path: The ELF to scan root: The root tree to prepend to paths; this applies to interp and rpaths only as |path| and |ldpaths| are expected to be prefixed already + prefix: The EPREFIX for Gentoo Prefix; this aids generating /usr/lib paths + from interp field ldpaths: dict containing library paths to search; should have the keys: conf, env, interp _first: Recursive use only; is this the first ELF ? @@ -304,7 +306,7 @@ def ParseELF(path, root='/', ldpaths={'c if segment.header.p_type != 'PT_INTERP': continue - interp = bstr(segment.get_interp_name()) + interp = normpath(bstr(segment.get_interp_name())) ret['interp'] = normpath(root + interp) ret['libs'][os.path.basename(interp)] = { 'path': ret['interp'], @@ -313,7 +315,7 @@ def ParseELF(path, root='/', ldpaths={'c # XXX: Should read it and scan for /lib paths. ldpaths['interp'] = [ normpath(root + os.path.dirname(interp)), - normpath(root + '/usr' + os.path.dirname(interp)), + normpath(root + prefix + '/usr' + os.path.dirname(interp).lstrip(prefix)), ] break @@ -361,7 +363,7 @@ def ParseELF(path, root='/', ldpaths={'c 'needed': [], } if fullpath: - lret = ParseELF(fullpath, root, ldpaths, False, _all_libs) + lret = ParseELF(fullpath, root, prefix, ldpaths, False, _all_libs) _all_libs[lib]['needed'] = lret['needed'] del elf @@ -541,6 +543,10 @@ they need will be placed into /foo/lib/ default=os.environ.get('ROOT', ''), type='string', action='callback', callback=_NormalizePath, help='Search for all files/dependencies in ROOT') + parser.add_option('-P', '--prefix', + default=os.environ.get('EPREFIX', '@GENTOO_PORTAGE_EPREFIX@'), type='string', + action='callback', callback=_NormalizePath, + help='Specify EPREFIX for binaries from Gentoo Prefix') parser.add_option('--no-auto-root', dest='auto_root', action='store_false', default=True, help='Do not automatically prefix input ELFs with ROOT') @@ -582,6 +588,8 @@ they need will be placed into /foo/lib/ if options.root != '/': options.root += '/' + if options.prefix == '@''GENTOO_PORTAGE_EPREFIX''@': + options.prefix = '' if options.bindir and options.bindir[0] != '/': parser.error('--bindir accepts absolute paths only') @@ -595,7 +603,7 @@ they need will be placed into /foo/lib/ if not paths: err('missing ELF files to scan') - ldpaths = LoadLdpaths(options.root) + ldpaths = LoadLdpaths(options.root, options.prefix) if options.debug: print('ldpaths[conf] =', ldpaths['conf']) print('ldpaths[env] =', ldpaths['env']) @@ -613,7 +621,7 @@ they need will be placed into /foo/lib/ for p in glob.iglob(path): matched = True try: - elf = ParseELF(p, options.root, ldpaths) + elf = ParseELF(p, options.root, options.prefix, ldpaths) except (exceptions.ELFError, IOError) as e: # XXX: Ugly. Should unify with _Action* somehow. if options.dest is not None and options.copy_non_elfs: