我已經創建了一個交叉編譯的arm可執行文件。我想找到可執行文件的庫依賴項。我使用的是ubuntu natty並安裝了arm-linux-gnueabi工具鏈,它不包含ldd。有沒有一種工具可用於在Linux中查看ARM可執行文件庫依賴性。交叉編譯ldd
Q
交叉編譯ldd
33
A
回答
54
這是一個kruge,但它是我能找到的最好的解決方案,它對於基本的使用非常有效 - 只需將這個腳本保存爲「arm-none-linux-gnueabi-ldd」十字工具。
#!/bin/sh
arm-none-linux-gnueabi-readelf -a $1 | grep "Shared library:"
14
你也可以使用objdump的並以只轉儲和搜索二進制文件的標題部分。這可以節省你一些毫秒...
#!/bin/sh
arm-none-linux-gnueabi-objdump -x $1 | grep NEEDED
4
這裏是另一種選擇,你可以LD_TRACE_LOADED_OBJECTS環境變量設置爲任意值,比如說1,然後只需運行可執行文件,輸出應該是它的動態依賴。
1
如前所述,設計ldd
can only been executed on target。但是,使用readelf
可以模擬ldd
行爲。在crosstool-ng
項目中開發了一個名爲xldd
的腳本。這個腳本的獨立版本,請訪問:
https://gist.github.com/jerome-pouiller/c403786c1394f53f44a3b61214489e6f
0
我發現這一點,並希望它能夠幫助很多人誰仍在尋找真正的LDD解決方案。 ldd只是一個支持ld-linux庫的腳本。那麼爲什麼不製作自己的ldd腳本呢?首先你需要在你的系統中找到ld-linux庫,它應該是可用的。在我的情況下,它是/lib/ld-linux-armhf.so.3,所以我把它放到RTLDLIST中,你可以在下面的腳本中看到。
然後把這個腳本放到你的設備或者主板上,你可以使用ldd來查找可執行文件的依賴庫。
祝你好運!
#! /bin/bash
# Copyright (C) 1996-2011, 2012 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with the GNU C Library; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA.
# This is the `ldd' command, which lists what shared libraries are
# used by given dynamically-linked executables. It works by invoking the
# run-time dynamic linker as a command and setting the environment
# variable LD_TRACE_LOADED_OBJECTS to a non-empty value.
# We should be able to find the translation right at the beginning.
TEXTDOMAIN=libc
TEXTDOMAINDIR=/usr/share/locale
RTLDLIST="/lib/ld-linux.so.2 /lib64/ld-linux-x86-64.so.2 /lib/ld-linux-armhf.so.3"
warn=
bind_now=
verbose=
while test $# -gt 0; do
case "$1" in
--vers | --versi | --versio | --version)
echo 'ldd (Ubuntu EGLIBC 2.15-0ubuntu10.3) 2.15'
printf $"Copyright (C) %s Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
" "2012"
printf $"Written by %s and %s.
" "Roland McGrath" "Ulrich Drepper"
exit 0
;;
--h | --he | --hel | --help)
printf $"Usage: ldd [OPTION]... FILE...
--help print this help and exit
--version print version information and exit
-d, --data-relocs process data relocations
-r, --function-relocs process data and function relocations
-u, --unused print unused direct dependencies
-v, --verbose print all information
"
printf $"For bug reporting instructions, please see:
%s.
" "<http://www.debian.org/Bugs/>"
exit 0
;;
-d | --d | --da | --dat | --data | --data- | --data-r | --data-re | \
--data-rel | --data-relo | --data-reloc | --data-relocs)
warn=yes
shift
;;
-r | --f | --fu | --fun | --func | --funct | --functi | --functio | \
--function | --function- | --function-r | --function-re | --function-rel | \
--function-relo | --function-reloc | --function-relocs)
warn=yes
bind_now=yes
shift
;;
-v | --verb | --verbo | --verbos | --verbose)
verbose=yes
shift
;;
-u | --u | --un | --unu | --unus | --unuse | --unused)
unused=yes
shift
;;
--v | --ve | --ver)
echo >&2 $"ldd: option \`$1' is ambiguous"
exit 1
;;
--) # Stop option processing.
shift; break
;;
-*)
echo >&2 'ldd:' $"unrecognized option" "\`$1'"
echo >&2 $"Try \`ldd --help' for more information."
exit 1
;;
*)
break
;;
esac
done
nonelf()
{
# Maybe extra code for non-ELF binaries.
return 1;
}
add_env="LD_TRACE_LOADED_OBJECTS=1 LD_WARN=$warn LD_BIND_NOW=$bind_now"
add_env="$add_env LD_LIBRARY_VERSION=\$verify_out"
add_env="$add_env LD_VERBOSE=$verbose"
if test "$unused" = yes; then
add_env="$add_env LD_DEBUG=\"$LD_DEBUG${LD_DEBUG:+,}unused\""
fi
# The following use of cat is needed to make ldd work in SELinux
# environments where the executed program might not have permissions
# to write to the console/tty. But only bash 3.x supports the pipefail
# option, and we don't bother to handle the case for older bash versions.
if x=`set -o` && test "$x" != "${x#*pipefail}" && set -o pipefail ; then
try_trace() {
eval $add_env '"[email protected]"' | cat
}
else
try_trace() {
eval $add_env '"[email protected]"'
}
fi
case $# in
0)
echo >&2 'ldd:' $"missing file arguments"
echo >&2 $"Try \`ldd --help' for more information."
exit 1
;;
1)
single_file=t
;;
*)
single_file=f
;;
esac
result=0
for file do
# We don't list the file name when there is only one.
test $single_file = t || echo "${file}:"
case $file in
*/*) :
;;
*) file=./$file
;;
esac
if test ! -e "$file"; then
echo "ldd: ${file}:" $"No such file or directory" >&2
result=1
elif test ! -f "$file"; then
echo "ldd: ${file}:" $"not regular file" >&2
result=1
elif test -r "$file"; then
RTLD=
ret=1
for rtld in ${RTLDLIST}; do
if test -x $rtld; then
verify_out=`${rtld} --verify "$file"`
ret=$?
case $ret in
[02]) RTLD=${rtld}; break;;
esac
fi
done
case $ret in
0|2)
try_trace "$RTLD" "$file" || result=1
;;
1|126)
# This can be a non-ELF binary or no binary at all.
nonelf "$file" || {
echo $" not a dynamic executable"
result=1
}
;;
*)
echo 'ldd:' ${RTLD} $"exited with unknown exit code" "($ret)" >&2
exit 1
;;
esac
else
echo 'ldd:' $"error: you do not have read permission for" "\`$file'" >&2
result=1
fi
done
exit $result
# Local Variables:
# mode:ksh
# End:
相關問題
- 1. cmake交叉編譯
- 2. Beaglebone交叉編譯
- 3. Qt - 交叉編譯
- 4. 交叉編譯器
- 5. Android交叉編譯
- 6. QTcreator交叉編譯
- 7. 爲arm編譯交叉編譯e2fsprogs
- 8. 編譯GMP的交叉編譯問題
- 9. 交叉編譯Python擴展
- 10. 與GHC交叉編譯
- 11. CMake CMAKE_AUTOMOC交叉編譯
- 12. 交叉編譯JRE/JDK
- 13. 在Windows上交叉編譯?
- 14. 交叉編譯器d-bus
- 15. 與SBCL交叉編譯
- 16. 交叉編譯glibc for arm
- 17. 交叉編譯教程
- 18. 交叉編譯和庫
- 19. 交叉編譯azure iot sdk
- 20. 交叉編譯Perl的ARM
- 21. 交叉編譯的手臂
- 22. Linux交叉編譯庫
- 23. GPU的Halide交叉編譯
- 24. 與庫交叉編譯
- 25. Buildroot裏面交叉編譯
- 26. 交叉編譯iOS的libogg
- 27. 交叉編譯freetype爲Android
- 28. Android和交叉編譯
- 29. 交叉編譯代碼
- 30. 交叉編譯ARM的ActiveMQ
即使我的本地binutils的readelf做的工作(本地objdump不)。 – 2013-08-15 05:58:25
-a選項有點矯枉過正,共享庫引用都在動態部分,-d選項。此外,像這樣的工具或objdump答案是正確的,因爲交叉編譯器ldd不會工作,這是由於ldd的工作原理:它試圖半運行可執行跟蹤庫加載,這對於外部來說不起作用二進制文件。 – Cheetah 2013-12-06 16:52:59
對不起,但readelf無法替換ldd。請參閱此http://stackoverflow.com/questions/11524820/what-is-the-difference-between-ldd-and-objdump。 readelf -d類似於objdump的輸出。任何人都可以有更好的答案嗎? – longbkit 2016-08-04 05:21:36