1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-04 16:48:04 +03:00
mold/test/elf/executable-dso.sh
Rui Ueyama d1b9549817 [ELF] Do not ignore --dynamic-linker even if --shared is given
It is very rare, but technically you can create a shared object that
can also be executed directly. You can do that by giving a dynamic
linker path to the linker.

https://github.com/rui314/mold/issues/422
2022-04-09 18:35:04 +08:00

46 lines
870 B
Bash
Executable File

#!/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
echo 'int main() {}' | $CC -o $t/exe -xc -
dyld=$(readelf -Wl $t/exe | grep 'program interpreter:' | sed -e 's!.*: \(.*\)\]!\1!')
cat <<EOF | $CC -o $t/a.o -c -xc -fPIC -
#include <stdio.h>
#include <stdlib.h>
void hello() {
puts("Hello world");
}
void _start() {
hello();
exit(0);
}
EOF
$CC -B. -o $t/b.so $t/a.o -shared -Wl,--dynamic-linker=$dyld
$QEMU $t/b.so | grep -q 'Hello world'
cat <<EOF | $CC -o $t/c.o -c -xc -
void hello();
int main() { hello(); }
EOF
$CC -B. -o $t/exe $t/c.o $t/b.so
$QEMU $t/exe | grep -q 'Hello world'
echo OK