diff options
Diffstat (limited to 'elf')
-rw-r--r-- | elf/ldd.bash.in | 46 | ||||
-rw-r--r-- | elf/ldd.sh.in | 41 | ||||
-rw-r--r-- | elf/rtld.c | 4 |
3 files changed, 67 insertions, 24 deletions
diff --git a/elf/ldd.bash.in b/elf/ldd.bash.in index dd4fc6a..48d5c90 100644 --- a/elf/ldd.bash.in +++ b/elf/ldd.bash.in @@ -69,6 +69,7 @@ Report bugs using the \`glibcbug' script to <bugs@gnu.ai.mit.edu>." esac done +add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now" case $# in 0) echo >&2 $"ldd: missing file arguments" @@ -86,20 +87,29 @@ case $# in elif test -r "$file"; then test -x "$file" || echo $"ldd: warning: you do not have execution permission for" "\`$file'" - if ${RTLD} --verify "$file"; then - LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now \ - exec ${RTLD} ${RELOCS} "$file" || exit 1 - else - echo $" not a dynamic executable" - exit 1 - fi + ${RTLD} --verify "$file" + case $? in + 0) + eval $add_env exec '"$file"' || exit 1 + ;; + 1) + echo $" not a dynamic executable" + exit 1 + ;; + 2) + eval $add_env exec \${RTLD} '"$file"' || exit 1 + ;; + *) + echo $"ldd: ${RTLD} exited with unknown exit code ($?)" >&2 + exit 1 + ;; + esac else echo $"ldd: error: you do not have read permission for" "\`$file'" exit 1 fi exit ;; *) - set -e # Bail out immediately if ${RTLD} loses on any argument. result=0 for file; do echo "${file}:" @@ -113,13 +123,23 @@ case $# in elif test -r "$file"; then test -x "$file" || echo $"\ ldd: warning: you do not have execution permission for" "\`$file'" - if ${RTLD} --verify "$file"; then - LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now \ - ${RTLD} ${RELOCS} "$file" || result=1 - else + ${RTLD} --verify "$file" + case $? in + 0) + eval $add_env '"$file"' || result=1 + ;; + 1) echo $" not a dynamic executable" result=1 - fi + ;; + 2) + eval $add_env ${RTLD} '"$file"' || result=1 + ;; + *) + echo $"ldd: ${RTLD} exited with unknown exit code ($?)" >&2 + exit 1 + ;; + esac else echo $"ldd: error: you do not have read permission for" "\`$file'" result=1 diff --git a/elf/ldd.sh.in b/elf/ldd.sh.in index 0f3ed2e..d5dd54a 100644 --- a/elf/ldd.sh.in +++ b/elf/ldd.sh.in @@ -66,6 +66,7 @@ Try \`ldd --help' for more information." esac done +add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now" case $# in 0) echo >&2 "\ @@ -85,13 +86,23 @@ Try \`ldd --help' for more information." if test -r "$file"; then test -x "$file" || echo "ldd: warning: you do not have execution permission for \`$file'" - if ${RTLD} --verify "$file"; then - LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now \ - exec ${RTLD} "$file" || exit 1 - else + ${RTLD} --verify "$file" + case $? in + 0) + eval $add_env exec '"$file"' || exit 1 + ;; + 1) echo ' not a dynamic executable' exit 1 - fi + ;; + 2) + eval $add_env exec \${RTLD} '"$file"' || exit 1 + ;; + *) + echo "ldd: ${RTLD} exited with unknown exit code ($?)" >&2 + exit 1 + ;; + esac else echo "ldd: error: you do not have read permission for \`$file'" exit 1 @@ -114,13 +125,23 @@ Try \`ldd --help' for more information." if test -r "$file"; then test -x "$file" || echo "\ ldd: warning: you do not have execution permission for \`$file'" - if ${RTLD} --verify "$file"; then - LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now \ - ${RTLD} "$file" || result=1 - else + ${RTLD} --verify "$file" + case $? in + 0) + eval $add_env '"$file"' || result=1 + ;; + 1) echo ' not a dynamic executable' result=1 - fi + ;; + 2) + eval $add_env ${RTLD} '"$file"' || result=1 + ;; + *) + echo "ldd: ${RTLD} exited with unknown exit code ($?)" >&2 + exit 1 + ;; + esac else echo "ldd: error: you do not have read permission for \`$file'" result=1 @@ -155,6 +155,7 @@ dl_main (const ElfW(Phdr) *phdr, const char *preloadlist; size_t file_size; char *file; + int has_interp = 0; mode = getenv ("LD_TRACE_LOADED_OBJECTS") != NULL ? trace : normal; @@ -299,6 +300,7 @@ of this helper program; chances are you did not intend to run this program.\n", _dl_rtld_libname.name = (const char *) l->l_addr + ph->p_vaddr; _dl_rtld_libname.next = NULL; _dl_rtld_map.l_libname = &_dl_rtld_libname; + has_interp = 1; break; } if (! _dl_rtld_map.l_libname && _dl_rtld_map.l_name) @@ -315,7 +317,7 @@ of this helper program; chances are you did not intend to run this program.\n", if (mode == verify) /* We were called just to verify that this is a dynamic executable using us as the program interpreter. */ - _exit (l->l_ld == NULL ? EXIT_FAILURE : EXIT_SUCCESS); + _exit (l->l_ld == NULL ? 1 : has_interp ? 0 : 2); /* Extract the contents of the dynamic section for easy access. */ elf_get_dynamic_info (l->l_ld, l->l_info); |