1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-04 08:37:28 +03:00
mold/test/elf/x86_64_pltgot.sh
Rui Ueyama 1b86708683 [ELF] Resurrect .plt.got
This reverts commit ef04befcba and
6c964df459.

Even though these commits are not technically wrong, they caused a
regression on ARM32 and PPC64LE. It is because glibc cannot handle
IRELATIVE relocations in .rela.plt on these targets. Compare the
following two source source files:

  https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/x86_64/dl-machine.h;h=005d089501fa78654e16103de9ec901af7be4ff2;hb=HEAD#l530

  https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/arm/dl-machine.h;h=b0521c15496b9967a1c00a0ca7214bad2337be14;hb=HEAD#l464

ARM doesn't handle IRELATIVE for some reason, though x86-64 does.
I guess this is glibc's bug, but apparently we can't create IRELATIVE
relocations in .rela.plt. So we need to create it in .rela.dyn.
2022-10-03 21:45:15 +08:00

40 lines
750 B
Bash
Executable File

#!/bin/bash
export LC_ALL=C
set -e
CC="${TEST_CC:-cc}"
CXX="${TEST_CXX:-c++}"
GCC="${TEST_GCC:-gcc}"
GXX="${TEST_GXX:-g++}"
MACHINE="${MACHINE:-$(uname -m)}"
testname=$(basename "$0" .sh)
echo -n "Testing $testname ... "
t=out/test/elf/$MACHINE/$testname
mkdir -p $t
[ $MACHINE = x86_64 ] || { echo skipped; exit; }
cat <<EOF | $CC -fPIC -shared -Wl,-z,noexecstack -o $t/a.so -x assembler -
.globl ext1, ext2
ext1:
nop
ext2:
nop
EOF
cat <<EOF | $CC -c -o $t/b.o -x assembler -
.globl _start
_start:
call ext1@PLT
call ext2@PLT
mov ext2@GOTPCREL(%rip), %rax
ret
EOF
./mold -z separate-loadable-segments -pie -o $t/exe $t/b.o $t/a.so
${TEST_TRIPLE}objdump -d -j .plt.got $t/exe > $t/log
grep -Eq '1034:.*jmp.* <ext2>' $t/log
echo OK