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 192BD1381F3 for ; Sat, 22 Dec 2012 01:06:54 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B36A021C03C; Sat, 22 Dec 2012 01:06:35 +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 1E09821C03C for ; Sat, 22 Dec 2012 01:06:35 +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 0FDC133D938 for ; Sat, 22 Dec 2012 01:06:34 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id A2857E543C for ; Sat, 22 Dec 2012 01:06:32 +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: <1356138377.06ff2d1f0fd8041675ed4f928c63bbdb58b7e18c.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: 06ff2d1f0fd8041675ed4f928c63bbdb58b7e18c X-VCS-Branch: master Date: Sat, 22 Dec 2012 01:06:32 +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: df2cfe9e-fe54-4ebc-b4c3-446ff625a268 X-Archives-Hash: d9413c43528163f7e4082b6ebce556bf commit: 06ff2d1f0fd8041675ed4f928c63bbdb58b7e18c Author: Anthony G. Basile gentoo org> AuthorDate: Sat Dec 22 01:06:17 2012 +0000 Commit: Anthony G. Basile gentoo org> CommitDate: Sat Dec 22 01:06:17 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=06ff2d1f misc/alt-revdep-pax: add soname to soname linkings for full linking chain --- misc/alt-revdep-pax | 105 +++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 81 insertions(+), 24 deletions(-) diff --git a/misc/alt-revdep-pax b/misc/alt-revdep-pax index a9445a1..607372a 100755 --- a/misc/alt-revdep-pax +++ b/misc/alt-revdep-pax @@ -10,13 +10,22 @@ # import os +import sys import re import pax -def get_forward_linkings(): +def get_forward_needed(): + """ + Return forward_needed dictionary which has structure + + { full_path_to_ELF_object : [ soname1, soname2, ... ], ... } + + Here the sonames were obtained from the ELF object by readelf -d + """ + var_db_pkg = '/var/db/pkg' - forward_linkings = {} + forward_needed = {} for cat in os.listdir(var_db_pkg): catdir = '%s/%s' % (var_db_pkg, cat) for pkg in os.listdir(catdir): @@ -30,18 +39,27 @@ def get_forward_linkings(): link = re.split(';', line) elf = link[1] sonames = re.split(',', link[4]) - forward_linkings[elf] = sonames + forward_needed[elf] = sonames except IOError: continue #File probably doesn't exist, which is okay - return forward_linkings + return forward_needed + + +def get_library(): + """ + Return library2soname dictionary which has structure + { full_path_to_library : soname, ... } -def get_library_mappings(): + and its inverse which has structure + + { soname : full_path_to_library, ... } + """ var_db_pkg = '/var/db/pkg' - library2soname_mappings = {} - soname2library_mappings = {} + library2soname = {} + soname2library = {} for cat in os.listdir(var_db_pkg): catdir = '%s/%s' % (var_db_pkg, cat) @@ -56,19 +74,56 @@ def get_library_mappings(): link = re.split(';', line) elf = link[1] soname = link[2] - if soname: - library2soname_mappings[elf] = soname - soname2library_mappings[soname] = elf + if soname: #no soname => executable + library2soname[elf] = soname + soname2library[soname] = elf except IOError: continue #File probably doesn't exist, which is okay - return ( library2soname_mappings, soname2library_mappings ) + return ( library2soname, soname2library ) + + +def get_soname2soname_linkings( forward_needed, library2soname ): + """ + Return get_soname2soname_linkings dictionary which has structure: + + { soname : [ soname1, soname2, ... ], .... } + + """ + + soname2soname_linkings = {} + + for elf in forward_needed: + try: + soname = library2soname[elf] + soname2soname_linkings[soname] = forward_needed[elf] + except KeyError: + continue #It doesn't have an soname and prabably isn't a library + + return soname2soname_linkings + def main(): - forward_linkings = get_forward_linkings() - ( library2soname_mappings, soname2library_mappings ) = get_library_mappings() - for elf in forward_linkings: + # Run as root to be able to real all files + uid = os.getuid() + if uid != 0: + print('RUN AS ROOT: cannot read all flags') + sys.exit(0) + + forward_needed = get_forward_needed() + ( library2soname, soname2library ) = get_library() + + soname2soname_linkings = get_soname2soname_linkings( forward_needed, library2soname ) + + 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: try: flags = pax.getflags(elf)[0] if flags: @@ -76,26 +131,28 @@ def main(): else: print("NONE: %s" % elf) except pax.error: - print("BUSY: %s" % elf) + print("CANT: %s" % elf) """ - for soname in sorted(soname2library_mappings): - elf = soname2library_mappings[soname] + + """ Print out all sonames and their library paths + for soname in sorted(soname2library): + elf = soname2library[soname] print("%s : %s" % ( soname, elf )) - """ """ - for elf in forward_linkings: - sonames = forward_linkings[elf] + + """ Print out all ELF objects and the NEEDED sonames and full library paths + for elf in forward_needed: + sonames = forward_needed[elf] print("%s" % elf) - for soname in sorted(forward_linkings[elf]): + for soname in sorted(forward_needed[elf]): try: - print("\t%s\t=> %s" % (soname, soname2library_mappings[soname])) - except KeyError as e: + print("\t%s\t=> %s" % (soname, soname2library[soname])) + except KeyError: print("\t%s\t=> ****" % soname) print("\n\n") """ - if __name__ == '__main__': main()