2022-02-12 06:02:15 +03:00
|
|
|
#!/bin/bash
|
2022-03-09 03:01:04 +03:00
|
|
|
export LC_ALL=C
|
2022-02-12 06:02:15 +03:00
|
|
|
set -e
|
2022-05-11 11:46:19 +03:00
|
|
|
CC="${TEST_CC:-cc}"
|
|
|
|
CXX="${TEST_CXX:-c++}"
|
|
|
|
GCC="${TEST_GCC:-gcc}"
|
|
|
|
GXX="${TEST_GXX:-g++}"
|
2022-04-02 11:12:14 +03:00
|
|
|
OBJDUMP="${OBJDUMP:-objdump}"
|
|
|
|
MACHINE="${MACHINE:-$(uname -m)}"
|
2022-02-12 06:02:15 +03:00
|
|
|
testname=$(basename "$0" .sh)
|
|
|
|
echo -n "Testing $testname ... "
|
2022-07-18 10:25:13 +03:00
|
|
|
t=out/test/elf/$MACHINE/$testname
|
2022-02-12 06:02:15 +03:00
|
|
|
mkdir -p $t
|
|
|
|
|
2022-02-16 09:45:30 +03:00
|
|
|
cat <<EOF | $CC -o $t/a.o -ffunction-sections -c -xc -
|
2022-02-12 06:02:15 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
int main() {
|
|
|
|
printf("Hello world\n");
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
2022-02-16 09:45:30 +03:00
|
|
|
# Create a lot of sections to lower the probability that
|
|
|
|
# we get the identical output as a result of shuffling.
|
|
|
|
for i in `seq 1 1000`; do echo "void fn$i() {}"; done | \
|
|
|
|
$CC -o $t/b.o -ffunction-sections -c -xc -
|
|
|
|
|
|
|
|
$CC -B. -o $t/exe1 $t/a.o $t/b.o
|
2022-04-02 11:12:14 +03:00
|
|
|
$QEMU $t/exe1 | grep -q 'Hello world'
|
2022-02-12 06:02:15 +03:00
|
|
|
|
2022-02-16 09:45:30 +03:00
|
|
|
$CC -B. -o $t/exe2 $t/a.o $t/b.o -Wl,-shuffle-sections
|
2022-04-02 11:12:14 +03:00
|
|
|
$QEMU $t/exe2 | grep -q 'Hello world'
|
2022-02-12 06:02:15 +03:00
|
|
|
|
2022-02-16 09:45:30 +03:00
|
|
|
! diff $t/exe1 $t/exe2 >& /dev/null || false
|
2022-02-12 06:02:15 +03:00
|
|
|
|
|
|
|
echo OK
|