summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmisc/alt-revdep-pax149
1 files changed, 80 insertions, 69 deletions
diff --git a/misc/alt-revdep-pax b/misc/alt-revdep-pax
index b46fe23..6fb88fa 100755
--- a/misc/alt-revdep-pax
+++ b/misc/alt-revdep-pax
@@ -128,37 +128,47 @@ def get_soname_needed( object_needed, library2soname ):
try:
soname = library2soname[elf]
soname_needed[soname] = object_needed[elf]
- #soname_needed[soname] = copy(object_needed[elf]) #copy the list
except KeyError:
continue # no soname, its probably an executable
return soname_needed
-
+"""
+Run through the entire chain of sonameX -> sonameY ... -> sonameZ chain.
+We do this by continuously expanding the list pointed to by the dictionary
+entry until there are no new soname's found.
+"""
def get_soname_linkings( soname_needed, soname2library ):
+
for soname in soname_needed:
while True:
- count = 0
- for s in soname_needed[soname]:
+ found_new_soname = False
+ for s in soname_needed[soname]: # For all the next links ...
try:
- for sf in soname_needed[s]:
- if sf in soname_needed[soname]: # Skip it if we already included it
+ for sf in soname_needed[s]: # ... go one step ahead in the chain
+ if sf in soname_needed[soname]: # ... skip it if we already included it
continue
- if not sf in soname2library: #Skip if its a vdso
+ if not sf in soname2library: # ... skip if its a vdso
continue
- # This appends to the object_needed and soname_needed list.
- # No copy was done so its the same list in memory for both.
- soname_needed[soname].append(sf)
- count = 1
- except KeyError:
+ # This appends to the object_needed
+ # and soname_needed lists. No copy
+ # was done so its the same lists in
+ # memory for both, and its modified
+ # for both.
+ soname_needed[soname].append(sf) # ... otherwise collapse it back into
+ found_new_soname = True # first node of the chain.
+
+ except KeyError: # Not all nodes in the chain have a next node
continue
- if count == 0:
- break
- return
+ if not found_new_soname: # We're done, that last iteration found
+ break # no new nodes
+
+
def get_object_linkings():
+
object_needed = get_object_needed()
( library2soname, soname2library ) = get_libraries()
soname_needed = get_soname_needed( object_needed, library2soname )
@@ -166,21 +176,22 @@ def get_object_linkings():
return ( object_needed, soname2library )
-def get_object_reverse_linkings( object_linkings ):
- object_reverse_linkings = {}
-
- for elf in object_linkings:
- for soname in object_linkings[elf]:
- object_reverse_linkings.setdefault(soname,[]).append(elf)
+def print_problems( elfs_without_flags, sonames_without_flags, sonames_missing_library):
- return object_reverse_linkings
+ elfs_without_flags = set(elfs_without_flags)
+ print('\n**** ELF objections without any PAX flags ****\n')
+ for m in elfs_without_flags:
+ print('\t%s' % m)
+ sonames_without_flags = set(sonames_without_flags)
+ print('\n**** SONAMEs with library files without PAX flags ****\n')
+ for m in sonames_without_flags:
+ print('\t%s' % m)
-#XXXXXXXXXXXXXXXX
-def invert_linkings( forward_linkings ):
- reverse_linkings = {}
- return reverse_linkings
-#XXXXXXXXXXXXXXXX
+ sonames_missing_library = set(sonames_missing_library)
+ print('\n**** SONAMES without any library files ****\n')
+ for m in sonames_missing_library:
+ print('\t%s' % m)
def print_object_linkings( object_linkings, soname2library, verbose ):
@@ -223,59 +234,65 @@ def print_object_linkings( object_linkings, soname2library, verbose ):
if count != 0:
print('%s\n\n' % s)
- elfs_without_flags = set(elfs_without_flags)
- print('\n**** ELF objections without any PAX flags ****')
- for m in elfs_without_flags:
- print('\t%s' % m)
-
- sonames_without_flags = set(sonames_without_flags)
- print('\n**** SONAMEs with library files without PAX flags ****')
- for m in sonames_without_flags:
- print('\t%s' % m)
+ print_problems( elfs_without_flags, sonames_without_flags, sonames_missing_library)
- sonames_missing_library = set(sonames_missing_library)
- print('\n**** SONAMES without any library files ****')
- for m in sonames_missing_library:
- print('\t%s' % m)
def run_forward(verbose):
+
( object_linkings, soname2library ) = get_object_linkings()
print_object_linkings( object_linkings, soname2library, verbose)
-def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, executable_only ):
+
+
+def get_object_reverse_linkings( object_linkings ):
+
+ object_reverse_linkings = {}
+
+ for elf in object_linkings:
+ for soname in object_linkings[elf]:
+ object_reverse_linkings.setdefault(soname,[]).append(elf)
+
+ return object_reverse_linkings
+
+
+def print_object_reverse_linkings( object_reverse_linkings, soname2library, verbose, executable_only):
+
shell_path = path = os.getenv('PATH').split(':')
- missing_sonames = []
- missing_links = []
- for soname in reverse_linkings:
+ elfs_without_flags = []
+ sonames_without_flags = []
+ sonames_missing_library = []
+
+ for soname in object_reverse_linkings:
try:
- library = so2library_mappings[soname]
+ library = soname2library[soname]
( library_str_flags, library_bin_flags ) = pax.getflags(library)
sv = '%s\t%s ( %s )\n' % ( soname, library, library_str_flags )
s = sv
+ except KeyError:
+ sonames_missing_library.append(soname)
except pax.PaxError:
- missing_sonames.append(soname)
- continue
+ sonames_without_flags.append(soname)
count = 0
- for binary in reverse_linkings[soname]:
+ for elf in object_reverse_linkings[soname]:
try:
- ( binary_str_flags, binary_bin_flags ) = pax.getflags(binary)
+ ( elf_str_flags, elf_bin_flags ) = pax.getflags(elf)
if executable_only:
- if os.path.dirname(binary) in shell_path:
- sv = '%s\n\t%s ( %s )' % ( sv, binary, binary_str_flags )
- if library_str_flags != binary_str_flags:
- s = '%s\n\t%s ( %s )' % ( s, binary, binary_str_flags )
+ if os.path.dirname(elf) in shell_path:
+ sv = '%s\n\t%s ( %s )' % ( sv, elf, elf_str_flags )
+ if library_str_flags != elf_str_flags:
+ s = '%s\n\t%s ( %s )' % ( s, elf, elf_str_flags )
count = count + 1
else:
- sv = '%s\n\t%s ( %s )' % ( sv, binary, binary_str_flags )
- if library_str_flags != binary_str_flags:
- s = '%s\n\t%s ( %s )' % ( s, binary, binary_str_flags )
+ sv = '%s\n\t%s ( %s )' % ( sv, elf, elf_str_flags )
+ if library_str_flags != elf_str_flags:
+ s = '%s\n\t%s ( %s )' % ( s, elf, elf_str_flags )
count = count + 1
except pax.PaxError:
- missing_links.append(binary)
+ elfs_without_flags.append(elf)
if verbose:
print('%s\n' % sv)
@@ -287,21 +304,15 @@ def print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, exec
if count != 0:
print('%s\n\n' % s)
- missing_sonames = set(missing_sonames)
- print('\n**** Missing sonames ****\n')
- for m in missing_sonames:
- print('\t%s\n' % m)
-
- missing_links = set(missing_links)
- print('\n**** Missing reverse linkings ****\n')
- for m in missing_links:
- print('\t%s\n' % m)
+ print_problems( elfs_without_flags, sonames_without_flags, sonames_missing_library)
def run_reverse(verbose, executable_only):
- ( forward_linkings, so2library_mappings ) = get_object_linkings()
- reverse_linkings = invert_linkings( forward_linkings )
- print_reverse_linkings( reverse_linkings, so2library_mappings, verbose, executable_only)
+ ( object_linkings, soname2library ) = get_object_linkings()
+ object_reverse_linkings = get_object_reverse_linkings( object_linkings )
+ print_object_reverse_linkings( object_reverse_linkings, soname2library, verbose, executable_only)
+
+
def migrate_flags(importer, exporter_str_flags, exporter_bin_flags):