summaryrefslogtreecommitdiff
path: root/tests/no-rpath-pie-powerpc.sh
blob: 963797c600c4b099751d113832cb2cc2b8df833c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /bin/sh -e
set -x
SCRATCH=scratch/no-rpath-pie-powerpc
READELF=${READELF:-readelf}

no_rpath_bin="${srcdir}/no-rpath-prebuild/no-rpath-pie-powerpc"

if [ ! -f $no_rpath_bin ]; then
  echo "no 'no-rpath' binary for '$ARCH' in '${srcdir}/no-rpath-prebuild'"
  exit 1
fi

rm -rf ${SCRATCH}
mkdir -p ${SCRATCH}

cp $no_rpath_bin ${SCRATCH}/no-rpath

oldRPath=$(../src/patchelf --print-rpath ${SCRATCH}/no-rpath)
if test -n "$oldRPath"; then exit 1; fi
../src/patchelf \
  --set-interpreter "$(../src/patchelf --print-interpreter ../src/patchelf)" \
  --set-rpath /foo:/bar:/xxxxxxxxxxxxxxx ${SCRATCH}/no-rpath

newRPath=$(../src/patchelf --print-rpath ${SCRATCH}/no-rpath)
if ! echo "$newRPath" | grep -q '/foo:/bar'; then
    echo "incomplete RPATH"
    exit 1
fi

# Tests for powerpc PIE endianness regressions
readelfData=$(${READELF} -l ${SCRATCH}/no-rpath 2>&1)

if [ $(echo "$readelfData" | grep "PHDR" | wc -l) != 1 ]; then
  # Triggered if PHDR errors appear on stderr
  echo "Unexpected number of occurences of PHDR in readelf results"
  exit 1
fi

virtAddr=$(echo "$readelfData" | grep "PHDR" | awk '{print $3}')
if [ "$virtAddr" != "0x00000034" ]; then
  # Triggered if the virtual address is the incorrect endianness
  echo "Unexpected virt addr, expected [0x00000034] got [$virtAddr]"
  exit 1
fi

echo "$readelfData" | grep "LOAD" | while read -r line ; do
  align=$(echo "$line" | awk '{print $NF}')
  if [ "$align" != "0x10000" ]; then
    # Triggered if the target arch was not detected properly
    echo "Unexpected Align for LOAD segment, expected [0x10000] got [$align]"
    echo "Load segment: [$line]"
    exit 1
  fi
done