• 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
Yann E. MORINYann E. MORIN committed c1cfee290e124 Sep 2017
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)/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
        is_elf "${file}" || continue
22
        elf_needs_rpath "${file}" "${hostdir}" || continue
23
        check_elf_has_rpath "${file}" "${hostdir}" && continue
24
        if [ ${ret} -eq 0 ]; then
25
            ret=1
26
            printf "***\n"
27
            printf "*** ERROR: package %s installs executables without proper RPATH:\n" "${pkg}"
28
        fi
29
        printf "***   %s\n" "${file}"
30
    done < <( find "${hostdir}"/{bin,sbin} -type f 2>/dev/null )
31
​
32
    return ${ret}
33
}
34
​
35
is_elf() {
36
    local f="${1}"
37
​
38
    readelf -l "${f}" 2>/dev/null \
39
    |grep -E 'Requesting program interpreter:' >/dev/null 2>&1
40
}
41
​
42
elf_needs_rpath() {
43
    local file="${1}"
44
    local hostdir="${2}"
45
    local lib
46
​
47
    while read lib; do
48
        [ -e "${hostdir}/lib/${lib}" ] && return 0
49
    done < <( readelf -d "${file}"                                         \
50
              |sed -r -e '/^.* \(NEEDED\) .*Shared library: \[(.+)\]$/!d;' \
51
                     -e 's//\1/;'                                          \
52
            )
53
​
54
    return 1
55
}
56
​
57
check_elf_has_rpath() {
58
    local file="${1}"
59
    local hostdir="${2}"
60
    local rpath dir
61
​
62
    while read rpath; do
63
        for dir in ${rpath//:/ }; do
  • 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.