#!/bin/sh set -eu : "${PACKAGE_VERSION:?}" : "${CPU_AS:?}" "${CPU_LD:?}" "${CPU_READELF:?}" "${TEST_SRCDIR:?}" TMP=${TMPDIR:-/tmp}/libmcpu-readelf-$$ mkdir -p "$TMP" trap 'rm -rf "$TMP"' EXIT HUP INT TERM EXAMPLES=`cd "$TEST_SRCDIR/fixtures/shared-libs" && pwd` "$CPU_AS" -o "$TMP/main.o" "$EXAMPLES/dynamic-main.s" "$CPU_AS" -o "$TMP/liba.o" "$EXAMPLES/dynamic-liba.s" "$CPU_LD" --dynamic --stack-size=4096 --no-heap \ -o "$TMP/main" "$TMP/main.o" "$CPU_LD" --shared --soname=liba.so.1 -o "$TMP/liba.so" "$TMP/liba.o" "$CPU_READELF" -h -S -s -r "$TMP/main.o" > "$TMP/rel.txt" grep -q 'REL (Relocatable file)' "$TMP/rel.txt" grep -q "Symbol table '.symtab'" "$TMP/rel.txt" grep -q "Relocation section '.rela.text'" "$TMP/rel.txt" grep -q 'R_MCPU_CODE64' "$TMP/rel.txt" "$CPU_READELF" -a "$TMP/main" > "$TMP/exec.txt" grep -q 'ABI Version: 3' "$TMP/exec.txt" grep -q 'EXEC (Executable file)' "$TMP/exec.txt" grep -q 'Program Headers:' "$TMP/exec.txt" grep -q 'MCPU_STACK' "$TMP/exec.txt" grep -q "Symbol table '.dynsym'" "$TMP/exec.txt" grep -q 'MCPU target attributes:' "$TMP/exec.txt" grep -q 'MCPU lifecycle attributes:' "$TMP/exec.txt" grep -q "Dynamic section '.dynamic'" "$TMP/exec.txt" grep -q 'NULL' "$TMP/exec.txt" "$CPU_READELF" -hSlrsdA "$TMP/liba.so" > "$TMP/dyn.txt" grep -q 'DYN (Shared object file)' "$TMP/dyn.txt" grep -q "Symbol table '.dynsym'" "$TMP/dyn.txt" grep -q 'foo' "$TMP/dyn.txt" grep -q 'MCPU target attributes:' "$TMP/dyn.txt" grep -q 'ABI Version: 3' "$TMP/dyn.txt" grep -q "Dynamic section '.dynamic'" "$TMP/dyn.txt" grep -q 'SONAME' "$TMP/dyn.txt" grep -q 'Library soname: \[liba.so.1\]' "$TMP/dyn.txt" # Section Headers are intentionally wide: one section occupies exactly one # physical output line rather than a wrapped two-line record. "$CPU_READELF" -S "$TMP/main" > "$TMP/sections.txt" grep -q '^ \[Nr\] Name.*Size.*EntSize.*Flags Link Info Align$' "$TMP/sections.txt" section_count=`grep -c '^ \[[ 0-9][ 0-9]\] ' "$TMP/sections.txt"` test "$section_count" -gt 0 if grep -q '^ [0-9a-f][0-9a-f]* ' "$TMP/sections.txt"; then echo "mcpu-readelf unexpectedly wrapped a section header" >&2 exit 1 fi "$CPU_READELF" --version | grep -Fq "$PACKAGE_VERSION" "$CPU_READELF" --help | grep -q -- '--arch-specific' "$CPU_READELF" --help | grep -q -- '--dynamic' printf 'not MELF\n' > "$TMP/bad" if "$CPU_READELF" -h "$TMP/bad" >/dev/null 2>&1; then echo "mcpu-readelf unexpectedly accepted a non-MELF file" >&2 exit 1 fi exit 0