1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-29 11:24:36 +03:00

Guarantee function pointer equivalence

This commit is contained in:
Rui Ueyama 2021-03-01 23:33:53 +09:00
parent a3df45cb86
commit 98db1741c4
2 changed files with 31 additions and 0 deletions

View File

@ -653,6 +653,10 @@ void DynsymSection::copy_buf() {
} else if (sym.is_imported() || sym.esym->is_undef()) {
esym.st_shndx = SHN_UNDEF;
esym.st_size = 0;
if (!config.shared && sym.plt_idx != -1) {
// Emit an address for a canonical PLT
esym.st_value = sym.get_plt_addr();
}
} else if (!sym.input_section) {
esym.st_shndx = SHN_ABS;
esym.st_value = sym.get_addr();

27
test/canonical-plt.sh Executable file
View File

@ -0,0 +1,27 @@
#!/bin/bash
set -e
cd $(dirname $0)
echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/tmp/$(basename -s .sh $0)
mkdir -p $t
cat <<EOF | cc -o $t/a.so -fPIC -shared -xc -
void *foo() {
return foo;
}
EOF
cat <<EOF | cc -o $t/b.o -c -xc - -fno-PIC
#include <stdio.h>
void *foo();
int main() {
printf("%d\n", foo == foo());
}
EOF
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/a.so $t/b.o
$t/exe | grep 1
echo OK