#!/bin/bash export LC_ALL=C set -e CC="${CC:-cc}" CXX="${CXX:-c++}" GCC="${GCC:-gcc}" GXX="${GXX:-g++}" OBJDUMP="${OBJDUMP:-objdump}" MACHINE="${MACHINE:-$(uname -m)}" testname=$(basename "$0" .sh) echo -n "Testing $testname ... " cd "$(dirname "$0")"/../.. mold="$(pwd)/mold" t=out/test/elf/$testname mkdir -p $t cat < int main() { printf("Hello world\n"); } EOF # 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 $QEMU $t/exe1 | grep -q 'Hello world' $CC -B. -o $t/exe2 $t/a.o $t/b.o -Wl,-shuffle-sections $QEMU $t/exe2 | grep -q 'Hello world' ! diff $t/exe1 $t/exe2 >& /dev/null || false echo OK