scripts/xldd.in
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Thu Jan 13 23:20:39 2011 +0100 (2011-01-13)
branch1.9
changeset 2263 2b25e1dab615
parent 2186 78d2f99d403f
permissions -rwxr-xr-x
complibs/cloog: regenerate autostuff files

Latest version of CLooG does not have properly generated autoconf files,
so they need to be regenerated before the call to ./configure

Signed-off-by: "Ilya A. Volynets-Evenbakh" <ilya@total-knowlege.com>
[yann.morin.1998@anciens.enib.fr: make it conditional on 0.15.10 only]
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
(transplanted from 32c7bbfa3f6514a0fbd5a7388d33e664ba62ed89)
yann@2034
     1
#!@@CT_bash@@
yann@2034
     2
yann@2034
     3
# NON-CONFIGURABLE STUFF!
yann@2034
     4
export LC_ALL=C
yann@2184
     5
version="@@CT_VERSION@@"
yann@2034
     6
sed="@@CT_sed@@"
yann@2034
     7
grep="@@CT_grep@@"
yann@2034
     8
my_name="$( basename "${0}" )"
yann@2034
     9
prefix="${0%-ldd}"
yann@2034
    10
gcc="${prefix}-gcc"
yann@2034
    11
readelf="${prefix}-readelf"
yann@2034
    12
fake_load_addr="$((0xdeadbeef))"
yann@2034
    13
fake_load_addr_sys="$((0x8badf00d))"
yann@2034
    14
ld_library_path="/lib:/usr/lib"
yann@2034
    15
yann@2034
    16
do_error() {
yann@2034
    17
    printf "%s: %s\n" "${my_name}" "$*" >&2
yann@2034
    18
}
yann@2034
    19
yann@2034
    20
do_opt_error() {
yann@2034
    21
    do_error "$@"
yann@2183
    22
    printf "Try \`%s --help' for more information\n" >&2
yann@2034
    23
}
yann@2034
    24
yann@2034
    25
show_version() {
yann@2034
    26
    # Fake a real ldd, just in case some dumb script would check
yann@2034
    27
    cat <<_EOF_
yann@2184
    28
ldd (crosstool-NG) ${version}
yann@2034
    29
Copyright (C) 2010 "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
yann@2034
    30
This is free software; see the source for copying conditions.  There is NO
yann@2034
    31
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
yann@2034
    32
Licensed under the GPLv2, see the file LICENSES in the top-directory of the
yann@2034
    33
sources for this package.
yann@2034
    34
_EOF_
yann@2034
    35
}
yann@2034
    36
yann@2034
    37
show_help() {
yann@2034
    38
    cat <<_EOF_
yann@2034
    39
Usage: ${my_name} [OPTION]... --root DIR FILE...
yann@2034
    40
      --help              print this help and exit
yann@2034
    41
      --version           print version information and exit
yann@2034
    42
      --root dir          treat dir as being the root of the target
yann@2034
    43
  -s, --show-system       mark libs from the sysroot with a trailing '[*]'
yann@2034
    44
yann@2034
    45
_EOF_
yann@2034
    46
    cat <<_EOF_ |fmt
yann@2034
    47
${my_name} tries to mimick the behavior of a real native ldd, but can be
yann@2034
    48
used in a cross-development environment. Here is how it differs from a
yann@2034
    49
real native ldd:
yann@2034
    50
yann@2034
    51
The LD_LIBRARY_PATH variable is not used, as it can not reliably be
yann@2034
    52
guessed except at runtime, and we can't run.
yann@2034
    53
yann@2034
    54
${my_name} does not scan /etc/ld.so.cache, but instead uses /etc/ld.so.conf
yann@2034
    55
(it understands the include directives therein for libces that have that).
yann@2034
    56
[Note: this is missing for now...]
yann@2034
    57
yann@2034
    58
${my_name} will search the directory specified with --root for libraries
yann@2034
    59
to resolve the NEEDED tags. If --root is not set, then ${my_name} will
yann@2034
    60
use the value in the environment variable \${CT_XLDD_ROOT}. If neither
yann@2034
    61
is set, then this is an error.
yann@2034
    62
yann@2034
    63
If NEEDED libraries can't be found in the specified root directory, then
yann@2034
    64
${my_name} will also look in the sysroot of the toolchain to see if it
yann@2034
    65
can find them.
yann@2034
    66
yann@2034
    67
For NEEDED libraries that were found, the output will look like:
yann@2034
    68
        libneeded.so => /path/to/libneeded.so (0xloadaddr)
yann@2034
    69
yann@2034
    70
and for those that were not found, the output will look like:
yann@2034
    71
        libneeded.so not found
yann@2034
    72
yann@2034
    73
The paths are relative to the specified root directory, or to the sysroot
yann@2034
    74
(eg. /lib/libneeded.so, /usr/lib/libneeded.so, and so on...).
yann@2034
    75
yann@2034
    76
The expected load address 'loadaddr' is a faked address to match the output
yann@2034
    77
of the real ldd, but has no actual meaning (set to some constants for now,
yann@2183
    78
0x8badf00d for libraries from the sysroot, 0xdeadbeef for others).
yann@2034
    79
_EOF_
yann@2034
    80
yann@2034
    81
# Unimplemeted yet:
yann@2034
    82
#  -d, --data-relocs       process data relocations
yann@2034
    83
#  -r, --function-relocs   process data and function relocations
yann@2034
    84
#  -u, --unused            print unused direct dependencies
yann@2034
    85
#  -v, --verbose           print all information
yann@2034
    86
yann@2034
    87
# See also this thread:
yann@2034
    88
#  http://sourceware.org/ml/crossgcc/2008-09/msg00057.html
yann@2034
    89
}
yann@2034
    90
yann@2034
    91
# Parse command line options
yann@2034
    92
root="${CT_XLDD_ROOT}"
yann@2034
    93
show_system=
yann@2034
    94
while true; do
yann@2034
    95
    case "${1}" in
yann@2034
    96
        --help)
yann@2034
    97
            show_help
yann@2034
    98
            exit 0
yann@2034
    99
            ;;
yann@2034
   100
        --version)
yann@2034
   101
            show_version
yann@2034
   102
            exit 0
yann@2034
   103
            ;;
yann@2034
   104
        --root)
yann@2034
   105
            root="$2"
yann@2034
   106
            shift
yann@2034
   107
            ;;
yann@2034
   108
        --root=*)
yann@2034
   109
            root="${1#--root=}"
yann@2034
   110
            ;;
yann@2034
   111
        --show-system|-s)
yann@2034
   112
            show_system=1
yann@2034
   113
            ;;
yann@2034
   114
        -*)
yann@2034
   115
            do_opt_error "unrecognized option \`${1}'"
yann@2034
   116
            exit 1
yann@2034
   117
            ;;
yann@2034
   118
        *)
yann@2034
   119
            break
yann@2034
   120
            ;;
yann@2034
   121
    esac
yann@2034
   122
    shift
yann@2034
   123
done
yann@2034
   124
yann@2034
   125
# Sanity checks
yann@2034
   126
if [ -z "${root}" ]; then
yann@2034
   127
    do_opt_error "no root given"
yann@2034
   128
    exit 1
yann@2034
   129
fi
yann@2034
   130
if [ ! -d "${root}" ]; then
yann@2034
   131
    do_error "\`${root}': no such file or directory"
yann@2034
   132
    exit 1
yann@2034
   133
fi
yann@2034
   134
yann@2198
   135
sysroot="$( "${gcc}" -print-sysroot 2>/dev/null )"
yann@2198
   136
if [ -z "${sysroot}" ]; then
yann@2198
   137
    sysroot="$( "${gcc}" -print-file-name=libc.so 2>/dev/null   \
yann@2198
   138
                |sed -r -e 's:/usr/lib/libc.so$::;'             \
yann@2198
   139
              )"
yann@2198
   140
fi
yann@2198
   141
if [ -z "${sysroot}" ]; then
yann@2198
   142
    do_error "unable to find sysroot for \`${gcc}'"
yann@2198
   143
fi
yann@2034
   144
yann@2034
   145
do_report_needed_found() {
yann@2034
   146
    local needed="${1}"
yann@2034
   147
    local path="${2}"
yann@2034
   148
    local system="${3}"
yann@2034
   149
    local loadaddr
yann@2034
   150
    local sys
yann@2034
   151
yann@2034
   152
    if [ -z "${system}" ]; then
yann@2034
   153
        loadaddr="${fake_load_addr}"
yann@2034
   154
    else
yann@2034
   155
        loadaddr="${fake_load_addr_sys}"
yann@2034
   156
        if [ -n "${show_system}" ]; then
yann@2034
   157
            sys=" [*]"
yann@2034
   158
        fi
yann@2034
   159
    fi
yann@2034
   160
yann@2034
   161
    # 8 to fake a 32-bit load address
yann@2034
   162
    printf "%8s%s => %s (0x%0*x)%s\n"   \
yann@2034
   163
           ""                           \
yann@2034
   164
           "${needed}"                  \
yann@2034
   165
           "${path}"                    \
yann@2034
   166
           8                            \
yann@2034
   167
           "${loadaddr}"                \
yann@2034
   168
           "${sys}"
yann@2034
   169
}
yann@2034
   170
yann@2034
   171
# Search a needed file, scanning ${lib_dir} in the root directory
yann@2034
   172
do_find_needed() {
yann@2034
   173
    local needed="${1}"
yann@2034
   174
    local found
yann@2034
   175
    local found_sysroot
yann@2034
   176
    local d
yann@2034
   177
yann@2034
   178
    for d in "${needed_search_path[@]}"; do
yann@2034
   179
        if [ -f "${root}${d}/${needed}" ]; then
yann@2034
   180
            found="${d}/${needed}"
yann@2186
   181
            break
yann@2034
   182
        fi
yann@2034
   183
    done
yann@2034
   184
    if [ -z "${found}" ]; then
yann@2034
   185
    for d in "${needed_search_path[@]}"; do
yann@2034
   186
        if [ -f "${sysroot}${d}/${needed}" ]; then
yann@2034
   187
            found_sysroot="${d}/${needed}"
yann@2186
   188
            break
yann@2034
   189
        fi
yann@2034
   190
    done
yann@2034
   191
    fi
yann@2034
   192
yann@2034
   193
    if [ -n "${found}" ]; then
yann@2034
   194
        do_report_needed_found "${needed}" "${found}"
yann@2034
   195
        do_process_file "${root}${found}"
yann@2034
   196
    elif [ -n "${found_sysroot}" ]; then
yann@2034
   197
        do_report_needed_found "${needed}" "${found_sysroot}" "sys"
yann@2034
   198
        do_process_file "${sysroot}${found_sysroot}"
yann@2034
   199
    else
yann@2034
   200
        printf "%8c%s not found\n" "" "${needed}"
yann@2034
   201
    fi
yann@2034
   202
}
yann@2034
   203
yann@2034
   204
# Scan a file for all NEEDED tags
yann@2034
   205
do_process_file() {
yann@2034
   206
    local file="${1}"
yann@2034
   207
yann@2034
   208
    "${readelf}" -d "${file}"                                           \
yann@2034
   209
    |"${grep}" -E '\(NEEDED\)'                                          \
yann@2034
   210
    |"${sed}" -r -e 's/^.*Shared library:[[:space:]]+\[(.*)\]$/\1/;'    \
yann@2034
   211
    |while read needed; do
yann@2034
   212
        do_find_needed "${needed}"
yann@2034
   213
     done
yann@2034
   214
}
yann@2034
   215
yann@2034
   216
# Build up the full list of search directories
yann@2034
   217
declare -a needed_search_path
yann@2034
   218
ld_library_path="${ld_library_path}:"
yann@2034
   219
while [ -n "${ld_library_path}" ]; do
yann@2034
   220
    d="${ld_library_path%%:*}"
yann@2034
   221
    [ -n "${d}" ] && needed_search_path+=( "${d}" )
yann@2034
   222
    ld_library_path="${ld_library_path#*:}"
yann@2034
   223
done
yann@2034
   224
yann@2034
   225
do_process_file "${1}"