Skip to content
Browse files

elf2pkgs: add new script

  • Loading branch information...
1 parent 17ff53a commit 29b32b8910911d68e83b60bbfa46a314ab64ddb6 @falconindy committed Mar 4, 2012
Showing with 28 additions and 0 deletions.
  1. +28 −0 elf2pkgs
View
28 elf2pkgs
@@ -0,0 +1,28 @@
+#!/bin/bash
+#
+# resolve ELF library deps to pacman packages
+#
+
+declare -r lddregex=$'(.+) => (.+) \(0x[a-fA-F0-9]+\)'
+
+resolve_bin() {
+ declare -A depmap
+ declare -a linkage
+
+ local lddout=$(ldd "$1" 2>/dev/null) || return
+
+ # leverage the linker to do lib resolution
+ while read -r line; do
+ [[ $line =~ $lddregex ]] || continue
+ depmap["${BASH_REMATCH[1]}"]=${BASH_REMATCH[2]}
+ done <<< "$lddout"
+
+ pacman -Ql | grep -Ff \
+ <(objdump -p "$1" | while read section soname; do
+ [[ $section == NEEDED && ${depmap[$soname]} ]] && printf '%s\n' "${depmap[$soname]}"
+ done) | cut '-d ' -f1 | sort -u
+}
+
+for bin; do
+ resolve_bin "$bin"
+done | sort -u

0 comments on commit 29b32b8

Please sign in to comment.
Something went wrong with that request. Please try again.