[arch-projects] [PATCH 2/2] avoid touching the linker directly

Dave Reisner d at falconindy.com
Thu Jun 30 20:15:33 EDT 2011


Much to my chagrin, we're going back to using ldd directly, as it's
otherwise too difficult to account for odd setups, such as idiots
wanting to create multilib initramfs images, or more commonly -- a 64
bit kernel on a 32 bit userland. Fortunately, we don't suffer too large
a regression in speed compared to the previous implementation.

Signed-off-by: Dave Reisner <dreisner at archlinux.org>
---
This is one possible solution -- and it's basically what we relied on pre 0.7, but
slightly cleaner. There _is_ a small loss of performance, but it's the price
we pay. I think this is a preferrably alternative to parsing human formatted
output from a tool such as readelf.

 functions  |   10 +++-------
 mkinitcpio |   18 +-----------------
 2 files changed, 4 insertions(+), 24 deletions(-)

diff --git a/functions b/functions
index 706a64f..c3d79b2 100644
--- a/functions
+++ b/functions
@@ -204,10 +204,6 @@ add_module() {
     esac
 }
 
-_ldd() {
-    LD_TRACE_LOADED_OBJECTS=1 "$LD_SO" "$@"
-}
-
 _add_file() {
   # add a file to $BUILDROOT
   #   $1: pathname on initcpio
@@ -264,10 +260,10 @@ add_binary() {
     # always add the binary itself
     _add_file "${dest#$BASEDIR}" "$binary" "$mode"
 
-    $LD_SO --verify "$binary" &>/dev/null || return # not a binary!
+    ldd "$binary" &>/dev/null || return # not a binary!
 
     # resolve sodeps
-    regex='^[[:space:]]*[^/].+ => (.*) \(.*\)'
+    regex='(/.+) \(0x[a-fA-F0-9]+\)'
     while read line; do
         [[ "$line" =~ $regex ]] && sodep=${BASH_REMATCH[1]} || continue
 
@@ -282,7 +278,7 @@ add_binary() {
                 _add_file "${resolved#$BASEDIR}" "$resolved" 755
             fi
         fi
-    done < <(_ldd "$binary")
+    done < <(ldd "$binary")
 
     return 0
 }
diff --git a/mkinitcpio b/mkinitcpio
index 459c828..71d3e0d 100755
--- a/mkinitcpio
+++ b/mkinitcpio
@@ -22,7 +22,7 @@ INSTDIR=install
 PRESETDIR=mkinitcpio.d
 COMPRESSION=gzip
 
-declare TMPDIR BASEDIR MODULE_FILE GENIMG PRESET COMPRESSION_OPTIONS BUILDROOT LD_SO
+declare TMPDIR BASEDIR MODULE_FILE GENIMG PRESET COMPRESSION_OPTIONS BUILDROOT
 declare NC= BOLD= BLUE= GREEN= RED= YELLOW=
 declare -i QUIET=1 SHOW_AUTOMODS=0 SAVELIST=0 COLOR=1
 declare -a SKIPHOOKS ADDED_MODULES
@@ -294,22 +294,6 @@ trap '[[ $FUNCNAME = parse_hook ]] && (( ++builderrors ))' ERR
 #parse 'global' hook, as defined in ${CONFIG}
 parse_hook
 
-# resolve the linker and add it
-case $CARCH in
-  i686) LD_SO=("$BASEDIR"/lib/ld-linux.so.?*) ;;
-  x86_64) LD_SO=("$BASEDIR"/lib/ld-linux-${CARCH//_/-}.so.?*) ;;
-  *) die "unknown architecture: $CARCH" ;;
-esac
-
-if (( ${#LD_SO[*]} != 1 )); then # uh oh...
-  die "failed to resolve the location of /lib/ld.so. Please report this bug."
-fi
-
-resolved=$(readlink -e "$LD_SO")
-_add_file "${resolved#$BASEDIR}" "$resolved" 755
-_add_symlink "${LD_SO#$BASEDIR}" "$resolved"
-unset resolved
-
 for hook in ${HOOKS}; do
     in_array "$hook" "${SKIPHOOKS[@]}" && continue
     unset MODULES BINARIES FILES SCRIPT
-- 
1.7.6



More information about the arch-projects mailing list