1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-04 16:48:04 +03:00
mold/test/elf/shuffle-sections-seed.sh
Rui Ueyama bb5a596bc5 Set LC_ALL=C to get consistent output from shell comands
We unset `LANG`, but it looks like `LC_ALL` takes precedence over `LANG`,
so we should set `LC_ALL` to `C`.

Reported at https://github.com/rui314/mold/pull/385
2022-03-09 09:03:22 +09:00

42 lines
1011 B
Bash
Executable File

#!/bin/bash
export LC_ALL=C
set -e
CC="${CC:-cc}"
CXX="${CXX:-c++}"
testname=$(basename "$0" .sh)
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
mold="$(pwd)/mold"
t=out/test/elf/$testname
mkdir -p $t
cat <<EOF | $CC -o $t/a.o -ffunction-sections -c -xc -
#include <stdio.h>
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
$t/exe1 | grep -q 'Hello world'
$CC -B. -o $t/exe2 $t/a.o $t/b.o -Wl,-shuffle-sections=42
$t/exe2 | grep -q 'Hello world'
$CC -B. -o $t/exe3 $t/a.o $t/b.o -Wl,-shuffle-sections=42
$t/exe3 | grep -q 'Hello world'
$CC -B. -o $t/exe4 $t/a.o $t/b.o -Wl,-shuffle-sections=5
$t/exe4 | grep -q 'Hello world'
! diff $t/exe1 $t/exe2 >& /dev/null || false
diff $t/exe2 $t/exe3
! diff $t/exe3 $t/exe4 >& /dev/null || false
echo OK