3 # NON-CONFIGURABLE STUFF!
5 version="@@CT_VERSION@@"
10 my_name="$( basename "${0}" )"
13 readelf="${prefix}-readelf"
14 fake_load_addr="$((0xdeadbeef))"
15 fake_load_addr_sys="$((0x8badf00d))"
16 ld_library_path="/lib:/usr/lib"
19 printf "%s: %s\n" "${my_name}" "$*" >&2
24 printf "Try \`%s --help' for more information\n" >&2
28 # Fake a real ldd, just in case some dumb script would check
30 ldd (crosstool-NG) ${version}
31 Copyright (C) 2010 "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
32 This is free software; see the source for copying conditions. There is NO
33 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
34 Licensed under the GPLv2, see the file LICENSES in the top-directory of the
35 sources for this package.
41 Usage: ${my_name} [OPTION]... --root DIR FILE...
42 --help print this help and exit
43 --version print version information and exit
44 --root dir treat dir as being the root of the target
45 -s, --show-system mark libs from the sysroot with a trailing '[*]'
49 ${my_name} tries to mimick the behavior of a real native ldd, but can be
50 used in a cross-development environment. Here is how it differs from a
53 The LD_LIBRARY_PATH variable is not used, as it can not reliably be
54 guessed except at runtime, and we can't run.
56 ${my_name} does not scan /etc/ld.so.cache, but instead uses /etc/ld.so.conf
57 (it understands the include directives therein for libces that have that).
58 [Note: this is missing for now...]
60 ${my_name} will search the directory specified with --root for libraries
61 to resolve the NEEDED tags. If --root is not set, then ${my_name} will
62 use the value in the environment variable \${CT_XLDD_ROOT}. If neither
63 is set, then this is an error.
65 If NEEDED libraries can't be found in the specified root directory, then
66 ${my_name} will also look in the sysroot of the toolchain to see if it
69 For NEEDED libraries that were found, the output will look like:
70 libneeded.so => /path/to/libneeded.so (0xloadaddr)
72 and for those that were not found, the output will look like:
73 libneeded.so not found
75 The paths are relative to the specified root directory, or to the sysroot
76 (eg. /lib/libneeded.so, /usr/lib/libneeded.so, and so on...).
78 The expected load address 'loadaddr' is a faked address to match the output
79 of the real ldd, but has no actual meaning (set to some constants for now,
80 0x8badf00d for libraries from the sysroot, 0xdeadbeef for others).
84 # -d, --data-relocs process data relocations
85 # -r, --function-relocs process data and function relocations
86 # -u, --unused print unused direct dependencies
87 # -v, --verbose print all information
89 # See also this thread:
90 # http://sourceware.org/ml/crossgcc/2008-09/msg00057.html
93 # Parse command line options
94 root="${CT_XLDD_ROOT}"
117 do_opt_error "unrecognized option \`${1}'"
128 if [ -z "${root}" ]; then
129 do_opt_error "no root given"
132 if [ ! -d "${root}" ]; then
133 do_error "\`${root}': no such file or directory"
137 sysroot="$( "${gcc}" -print-sysroot )"
139 do_report_needed_found() {
146 if [ -z "${system}" ]; then
147 loadaddr="${fake_load_addr}"
149 loadaddr="${fake_load_addr_sys}"
150 if [ -n "${show_system}" ]; then
155 printf "%8s%s => %s (0x%0*x)%s\n" \
164 # Search a needed file, scanning ${lib_dir} in the root directory
171 for d in "${needed_search_path[@]}"; do
172 if [ -f "${root}${d}/${needed}" ]; then
173 found="${d}/${needed}"
177 if [ -z "${found}" ]; then
178 for d in "${needed_search_path[@]}"; do
179 if [ -f "${sysroot}${d}/${needed}" ]; then
180 found_sysroot="${d}/${needed}"
186 if [ -n "${found}" ]; then
187 do_report_needed_found "${needed}" "${found}"
188 do_process_file "${root}${found}"
189 elif [ -n "${found_sysroot}" ]; then
190 do_report_needed_found "${needed}" "${found_sysroot}" "sys"
191 do_process_file "${sysroot}${found_sysroot}"
193 printf "%8c%s not found\n" "" "${needed}"
197 # Scan a file for all NEEDED tags
201 "${readelf}" -d "${file}" \
202 |"${grep}" -E '\(NEEDED\)' \
203 |"${sed}" -r -e 's/^.*Shared library:[[:space:]]+\[(.*)\]$/\1/;' \
204 |while read needed; do
205 do_find_needed "${needed}"
209 # Build up the full list of search directories
210 declare -a needed_search_path
211 ld_library_path="${ld_library_path}:"
212 while [ -n "${ld_library_path}" ]; do
213 d="${ld_library_path%%:*}"
214 [ -n "${d}" ] && needed_search_path+=( "${d}" )
215 ld_library_path="${ld_library_path#*:}"
218 do_process_file "${1}"