• Skip to sidebar navigation
  • Skip to content

Bitbucket

  • More
    ProjectsRepositories
  • Help
    • Online help
    • Learn Git
    • Welcome to Bitbucket
    • Keyboard shortcuts
  • Log In
Alexander Dahl
  1. Alexander Dahl

buildroot

Public
Actions
  • Clone
  • Compare

Learn more about cloning repositories

You have read-only access

Navigation
  • Source
  • Commits
  • Branches
  • All Branches Graph
  • Forks
  1. Alexander Dahl
  2. buildroot

Source

buildroot/support/scripts/check-host-rpath
Samuel MartinSamuel Martin committed bf8f0136e9719 Apr 2016
Raw file
Source viewDiff to previous
 
1
#!/usr/bin/env bash
2
​
3
# This script scans $(HOST_DIR)/{bin,sbin} for all ELF files, and checks
4
# they have an RPATH to $(HOST_DIR)/usr/lib if they need libraries from
5
# there.
6
​
7
# Override the user's locale so we are sure we can parse the output of
8
# readelf(1) and file(1)
9
export LC_ALL=C
10
​
11
main() {
12
    local pkg="${1}"
13
    local hostdir="${2}"
14
    local file ret
15
​
16
    # Remove duplicate and trailing '/' for proper match
17
    hostdir="$( sed -r -e 's:/+:/:g; s:/$::;' <<<"${hostdir}" )"
18
​
19
    ret=0
20
    while read file; do
21
        elf_needs_rpath "${file}" "${hostdir}" || continue
22
        check_elf_has_rpath "${file}" "${hostdir}" && continue
23
        if [ ${ret} -eq 0 ]; then
24
            ret=1
25
            printf "***\n"
26
            printf "*** ERROR: package %s installs executables without proper RPATH:\n" "${pkg}"
27
        fi
28
        printf "***   %s\n" "${file}"
29
    done < <( find "${hostdir}"/{,usr/}{bin,sbin} -type f -exec file {} + 2>/dev/null \
30
              |sed -r -e '/^([^:]+):.*\<ELF\>.*\<executable\>.*/!d'                \
31
                      -e 's//\1/'                                                  \
32
            )
33
​
34
    return ${ret}
35
}
36
​
37
elf_needs_rpath() {
38
    local file="${1}"
39
    local hostdir="${2}"
40
    local lib
41
​
42
    while read lib; do
43
        [ -e "${hostdir}/usr/lib/${lib}" ] && return 0
44
    done < <( readelf -d "${file}"                                         \
45
              |sed -r -e '/^.* \(NEEDED\) .*Shared library: \[(.+)\]$/!d;' \
46
                     -e 's//\1/;'                                          \
47
            )
48
​
49
    return 1
50
}
51
​
52
check_elf_has_rpath() {
53
    local file="${1}"
54
    local hostdir="${2}"
55
    local rpath dir
56
​
57
    while read rpath; do
58
        for dir in ${rpath//:/ }; do
59
            # Remove duplicate and trailing '/' for proper match
60
            dir="$( sed -r -e 's:/+:/:g; s:/$::;' <<<"${dir}" )"
61
            [ "${dir}" = "${hostdir}/usr/lib" ] && return 0
62
        done
63
    done < <( readelf -d "${file}"                                              \
  • Git repository management for enterprise teams powered by Atlassian Bitbucket
  • Atlassian Bitbucket v6.7.2
  • Documentation
  • Request a feature
  • About
  • Contact Atlassian
Atlassian

Everything looks good. We'll let you know here if there's anything you should know about.