From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 999AD1381F3 for ; Sat, 22 Dec 2012 03:58:53 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 70C0521C00B; Sat, 22 Dec 2012 03:58:46 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id DF21D21C00B for ; Sat, 22 Dec 2012 03:58:45 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id D63CC33D966 for ; Sat, 22 Dec 2012 03:58:44 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 28586E543C for ; Sat, 22 Dec 2012 03:58:43 +0000 (UTC) From: "Anthony G. Basile" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Anthony G. Basile" Message-ID: <1356148714.8f5c0363ecd8716c5d03bb55940ac15e7cc07334.blueness@gentoo> Subject: [gentoo-commits] proj/elfix:master commit in: misc/ X-VCS-Repository: proj/elfix X-VCS-Files: misc/alt-revdep-pax X-VCS-Directories: misc/ X-VCS-Committer: blueness X-VCS-Committer-Name: Anthony G. Basile X-VCS-Revision: 8f5c0363ecd8716c5d03bb55940ac15e7cc07334 X-VCS-Branch: master Date: Sat, 22 Dec 2012 03:58:43 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 314668c2-a56e-42e8-a3f2-4db98caf4dd4 X-Archives-Hash: 4f6f493d89bb77cda243a92af13a97e5 commit: 8f5c0363ecd8716c5d03bb55940ac15e7cc07334 Author: Anthony G. Basile gentoo org> AuthorDate: Sat Dec 22 03:58:34 2012 +0000 Commit: Anthony G. Basile gentoo org> CommitDate: Sat Dec 22 03:58:34 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=8f5c0363 misc/alt-revdep-pax: follow NEEDED to end of linking chain --- misc/alt-revdep-pax | 89 +++++++++++++++++++++++++++++++++++++------------- 1 files changed, 66 insertions(+), 23 deletions(-) diff --git a/misc/alt-revdep-pax b/misc/alt-revdep-pax index 607372a..fcf63b6 100755 --- a/misc/alt-revdep-pax +++ b/misc/alt-revdep-pax @@ -13,10 +13,11 @@ import os import sys import re import pax +from copy import copy -def get_forward_needed(): +def get_object_needed(): """ - Return forward_needed dictionary which has structure + Return object_needed dictionary which has structure { full_path_to_ELF_object : [ soname1, soname2, ... ], ... } @@ -25,7 +26,7 @@ def get_forward_needed(): var_db_pkg = '/var/db/pkg' - forward_needed = {} + object_needed = {} for cat in os.listdir(var_db_pkg): catdir = '%s/%s' % (var_db_pkg, cat) for pkg in os.listdir(catdir): @@ -39,11 +40,11 @@ def get_forward_needed(): link = re.split(';', line) elf = link[1] sonames = re.split(',', link[4]) - forward_needed[elf] = sonames + object_needed[elf] = sonames except IOError: continue #File probably doesn't exist, which is okay - return forward_needed + return object_needed def get_library(): @@ -83,24 +84,48 @@ def get_library(): return ( library2soname, soname2library ) -def get_soname2soname_linkings( forward_needed, library2soname ): +def get_soname_needed( object_needed, library2soname ): """ - Return get_soname2soname_linkings dictionary which has structure: + Return get_soname_needed dictionary which has structure: { soname : [ soname1, soname2, ... ], .... } + Here the soname1,2,... were obtained from soname's corresponding ELF library by readelf -d """ - soname2soname_linkings = {} + soname_needed = {} - for elf in forward_needed: + for elf in object_needed: try: soname = library2soname[elf] - soname2soname_linkings[soname] = forward_needed[elf] + soname_needed[soname] = copy(object_needed[elf]) #copy the list except KeyError: - continue #It doesn't have an soname and prabably isn't a library + continue # no soname, its probably an executable - return soname2soname_linkings + return soname_needed + + +def get_soname_linkings( soname_needed ): + soname_linkings = {} + for soname in soname_needed: + needed = copy(soname_needed[soname]) + while True: + count = 0 + for s in needed: + try: + for sf in soname_needed[s]: + if not sf in needed: + needed.append(sf) + count = 1 + except KeyError: + continue + + if count == 0: + break + + soname_linkings[soname] = needed + + return soname_linkings def main(): @@ -111,19 +136,17 @@ def main(): print('RUN AS ROOT: cannot read all flags') sys.exit(0) - forward_needed = get_forward_needed() + object_needed = get_object_needed() ( library2soname, soname2library ) = get_library() + soname_needed = get_soname_needed( object_needed, library2soname ) + soname_linkings = get_soname_linkings( soname_needed ) + print soname_linkings - soname2soname_linkings = get_soname2soname_linkings( forward_needed, library2soname ) + #forward_linkings = get_forward_linkings( object_needed, soname_linkings ) - for soname in soname2soname_linkings: - print("%s" % soname) - for s in soname2soname_linkings[soname]: - print("\t%s" % s ) - print('') """ Print out all ELF objects and their PaX flags - for elf in forward_needed: + for elf in object_needed: try: flags = pax.getflags(elf)[0] if flags: @@ -143,10 +166,10 @@ def main(): """ """ Print out all ELF objects and the NEEDED sonames and full library paths - for elf in forward_needed: - sonames = forward_needed[elf] + for elf in object_needed: + sonames = object_needed[elf] print("%s" % elf) - for soname in sorted(forward_needed[elf]): + for soname in sorted(object_needed[elf]): try: print("\t%s\t=> %s" % (soname, soname2library[soname])) except KeyError: @@ -154,5 +177,25 @@ def main(): print("\n\n") """ + """ Print out all the soname to soname NEEDED + for soname in soname_needed: + print("%s" % soname) + for s in soname_needed[soname]: + print("\t%s" % s ) + print('') + """ + + + """ Print out all the soname to soname linkings + for soname in soname_linkings: + print("%s => %s" % (soname, soname2library[soname])) + for s in soname_linkings[soname]: + if s in soname2library: + print("\t%s => %s" % (s, soname2library[s])) + else: + print("\t%s => ****" %s ) + print('') + """ + if __name__ == '__main__': main()