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 EFD681381F3 for ; Mon, 24 Dec 2012 11:01:08 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 296D621C0A5; Mon, 24 Dec 2012 10:59:18 +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 74C6B21C0A3 for ; Mon, 24 Dec 2012 10:59:17 +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 539E033DA01 for ; Mon, 24 Dec 2012 10:59:11 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 162E7E5459 for ; Mon, 24 Dec 2012 10:59:09 +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: <1356346677.bbed69289001490eb792727262035ff696c8fc44.blueness@gentoo> Subject: [gentoo-commits] proj/elfix:elfix-0.7.x commit in: misc/ X-VCS-Repository: proj/elfix X-VCS-Files: misc/link_maps misc/link_maps_portage X-VCS-Directories: misc/ X-VCS-Committer: blueness X-VCS-Committer-Name: Anthony G. Basile X-VCS-Revision: bbed69289001490eb792727262035ff696c8fc44 X-VCS-Branch: elfix-0.7.x Date: Mon, 24 Dec 2012 10:59:09 +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: 09468b6f-82c3-49ca-8a60-f3e8fc878529 X-Archives-Hash: 3c131556ebd1e0ece8461c8a77ed32d3 commit: bbed69289001490eb792727262035ff696c8fc44 Author: Anthony G. Basile gentoo org> AuthorDate: Mon Dec 24 01:54:10 2012 +0000 Commit: Anthony G. Basile gentoo org> CommitDate: Mon Dec 24 10:57:57 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=bbed6928 misc/link_maps{,_portage}: compare reading /var/db/pkg directly and via portage --- misc/link_maps | 60 ++++------------ misc/{link_maps => link_maps_portage} | 122 +++++++++++---------------------- 2 files changed, 56 insertions(+), 126 deletions(-) diff --git a/misc/link_maps b/misc/link_maps index a6adacd..3e4e3cb 100755 --- a/misc/link_maps +++ b/misc/link_maps @@ -168,57 +168,27 @@ def main(): object_reverse_linkings = get_object_reverse_linkings( object_linkings ) - """ Print out all ELF objects and their PaX flags - for elf in object_needed: - try: - flags = pax.getflags(elf)[0] - if flags: - print("%s %s" % (flags, elf)) - else: - print("NONE: %s" % elf) - except pax.error: - print("CANT: %s" % elf) - - """ - - """ Print out all sonames and their library paths - for soname in sorted(soname2library): - elf = soname2library[soname] - print("%s : %s" % ( soname, elf )) - """ - - - """ Print out all ELF objects and the NEEDED sonames and full library paths - for elf in object_needed: - sonames = object_needed[elf] + """ Print out all ELF objects and the NEEDED sonames and full library paths """ + for elf in object_linkings: + sonames = object_linkings[elf] print("%s" % elf) - for soname in sorted(object_needed[elf]): + for soname in sorted(object_linkings[elf]): try: print("\t%s\t=> %s" % (soname, soname2library[soname])) except KeyError: - print("\t%s\t=> ****" % soname) + print("%s\t=>%s " % (soname, '***')) + print("\n\n") + + """ Print out all ELF objects and the NEEDED sonames and full library paths """ + for soname in object_reverse_linkings: + try: + print("%s\t=> %s" % (soname, soname2library[soname])) + except KeyError: + print("%s\t=>%s " % (soname, '***')) + for elf in sorted(object_reverse_linkings[soname]): + print("\t%s" % elf) 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() diff --git a/misc/link_maps b/misc/link_maps_portage similarity index 61% copy from misc/link_maps copy to misc/link_maps_portage index a6adacd..bf5b447 100755 --- a/misc/link_maps +++ b/misc/link_maps_portage @@ -13,6 +13,7 @@ import os import sys import re import pax +import portage """ @@ -25,25 +26,20 @@ Here the sonames were obtained from the ELF object by scanelf -nm """ def get_object_needed(): - var_db_pkg = '/var/db/pkg' + vardb = portage.db[portage.root]["vartree"].dbapi object_needed = {} - for cat in os.listdir(var_db_pkg): - catdir = '%s/%s' % (var_db_pkg, cat) - for pkg in os.listdir(catdir): - pkgdir = '%s/%s' % (catdir, pkg) - need = '%s/%s' % (pkgdir, 'NEEDED.ELF.2') - try: - g = open(need, 'r') - needs = g.readlines() - for line in needs: - line = line.strip() - link = re.split(';', line) - elf = link[1] - sonames = re.split(',', link[4]) - object_needed[elf] = sonames - except IOError: - continue #File probably doesn't exist, which is okay + + for pkg in vardb.cpv_all(): + needs = vardb.aux_get(pkg, ['NEEDED.ELF.2'])[0].strip() + if not needs: #skip empty lines + continue + lines = re.split('\n', needs) + for line in lines: + link = re.split(';', line) + elf = link[1] + sonames = re.split(',', link[4]) + object_needed[elf] = sonames return object_needed @@ -59,29 +55,23 @@ and its inverse which has structure """ def get_libraries(): - var_db_pkg = '/var/db/pkg' + vardb = portage.db[portage.root]["vartree"].dbapi library2soname = {} soname2library = {} - for cat in os.listdir(var_db_pkg): - catdir = '%s/%s' % (var_db_pkg, cat) - for pkg in os.listdir(catdir): - pkgdir = '%s/%s' % (catdir, pkg) - need = '%s/%s' % (pkgdir, 'NEEDED.ELF.2') - try: - g = open(need, 'r') - needs = g.readlines() - for line in needs: - line = line.strip() - link = re.split(';', line) - elf = link[1] - soname = link[2] - if soname: #no soname => executable - library2soname[elf] = soname - soname2library[soname] = elf - except IOError: - continue #File probably doesn't exist, which is okay + for pkg in vardb.cpv_all(): + needs = vardb.aux_get(pkg, ['NEEDED.ELF.2'])[0].strip() + if not needs: #skip empty lines + continue + lines = re.split('\n', needs) + for line in lines: + link = re.split(';', line) + elf = link[1] + soname = link[2] + if soname: #no soname => executable + library2soname[elf] = soname + soname2library[soname] = elf return ( library2soname, soname2library ) @@ -168,57 +158,27 @@ def main(): object_reverse_linkings = get_object_reverse_linkings( object_linkings ) - """ Print out all ELF objects and their PaX flags - for elf in object_needed: - try: - flags = pax.getflags(elf)[0] - if flags: - print("%s %s" % (flags, elf)) - else: - print("NONE: %s" % elf) - except pax.error: - print("CANT: %s" % elf) - - """ - - """ Print out all sonames and their library paths - for soname in sorted(soname2library): - elf = soname2library[soname] - print("%s : %s" % ( soname, elf )) - """ - - - """ Print out all ELF objects and the NEEDED sonames and full library paths - for elf in object_needed: - sonames = object_needed[elf] + """ Print out all ELF objects and the NEEDED sonames and full library paths """ + for elf in object_linkings: + sonames = object_linkings[elf] print("%s" % elf) - for soname in sorted(object_needed[elf]): + for soname in sorted(object_linkings[elf]): try: print("\t%s\t=> %s" % (soname, soname2library[soname])) except KeyError: - print("\t%s\t=> ****" % soname) + print("%s\t=>%s " % (soname, '***')) + print("\n\n") + + """ Print out all ELF objects and the NEEDED sonames and full library paths """ + for soname in object_reverse_linkings: + try: + print("%s\t=> %s" % (soname, soname2library[soname])) + except KeyError: + print("%s\t=>%s " % (soname, '***')) + for elf in sorted(object_reverse_linkings[soname]): + print("\t%s" % elf) 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()