aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2012-12-18 22:51:58 -0500
committerAnthony G. Basile <blueness@gentoo.org>2012-12-24 05:57:56 -0500
commit5e10bc9f36693ac8ec82e0487a33ac5aac99f2f3 (patch)
tree69fe2ea28f02e49471e2b0f5c321e28ae4664cee
parentscripts/migrate: migration script from PT_PAX to XATTR_PAX flags (diff)
downloadelfix-5e10bc9f36693ac8ec82e0487a33ac5aac99f2f3.tar.gz
elfix-5e10bc9f36693ac8ec82e0487a33ac5aac99f2f3.tar.bz2
elfix-5e10bc9f36693ac8ec82e0487a33ac5aac99f2f3.zip
misc/alt-revdep-pax: alternative approache to ELF exec <-> library mappings
-rwxr-xr-xmisc/alt-revdep-pax101
1 files changed, 101 insertions, 0 deletions
diff --git a/misc/alt-revdep-pax b/misc/alt-revdep-pax
new file mode 100755
index 0000000..a9445a1
--- /dev/null
+++ b/misc/alt-revdep-pax
@@ -0,0 +1,101 @@
+#!/usr/bin/env python
+
+#
+# Note: This alternative way of doing revdep-pax only
+# works on Gentoo systems where NEEDED.ELF.2 all the
+# information we need generated by scanelf during emerge.
+#
+# See /usr/lib/portage/bin/misc-functions.sh ~line 520
+# echo "${arch:3};${obj};${soname};${rpath};${needed}" >> "${PORTAGE_BUILDDIR}"/build-info/NEEDED.ELF.2
+#
+
+import os
+import re
+import pax
+
+def get_forward_linkings():
+ var_db_pkg = '/var/db/pkg'
+
+ forward_linkings = {}
+ 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])
+ forward_linkings[elf] = sonames
+ except IOError:
+ continue #File probably doesn't exist, which is okay
+
+ return forward_linkings
+
+
+def get_library_mappings():
+ var_db_pkg = '/var/db/pkg'
+
+ library2soname_mappings = {}
+ soname2library_mappings = {}
+
+ 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:
+ library2soname_mappings[elf] = soname
+ soname2library_mappings[soname] = elf
+ except IOError:
+ continue #File probably doesn't exist, which is okay
+
+ return ( library2soname_mappings, soname2library_mappings )
+
+def main():
+ forward_linkings = get_forward_linkings()
+ ( library2soname_mappings, soname2library_mappings ) = get_library_mappings()
+
+ for elf in forward_linkings:
+ try:
+ flags = pax.getflags(elf)[0]
+ if flags:
+ print("%s %s" % (flags, elf))
+ else:
+ print("NONE: %s" % elf)
+ except pax.error:
+ print("BUSY: %s" % elf)
+
+ """
+ for soname in sorted(soname2library_mappings):
+ elf = soname2library_mappings[soname]
+ print("%s : %s" % ( soname, elf ))
+ """
+
+ """
+ for elf in forward_linkings:
+ sonames = forward_linkings[elf]
+ print("%s" % elf)
+ for soname in sorted(forward_linkings[elf]):
+ try:
+ print("\t%s\t=> %s" % (soname, soname2library_mappings[soname]))
+ except KeyError as e:
+ print("\t%s\t=> ****" % soname)
+ print("\n\n")
+ """
+
+
+if __name__ == '__main__':
+ main()