diff --git a/mold.h b/mold.h index 51b578da..16803747 100644 --- a/mold.h +++ b/mold.h @@ -1770,8 +1770,12 @@ public: : ctx.dynbss->shdr.sh_addr + value; } - if (has_plt(ctx) && esym().st_type == STT_GNU_IFUNC) - return get_plt_addr(ctx); + if (has_plt(ctx)) { + if (esym().st_type == STT_GNU_IFUNC) + return get_plt_addr(ctx); + if (is_imported) + return get_plt_addr(ctx); + } if (input_section) { if (input_section->is_ehframe) { @@ -1793,12 +1797,8 @@ public: // relocations. return 0; } - return input_section->get_addr() + value; } - - if (has_plt(ctx)) - return get_plt_addr(ctx); return value; } diff --git a/test/plt-dso.sh b/test/plt-dso.sh new file mode 100755 index 00000000..fd046c75 --- /dev/null +++ b/test/plt-dso.sh @@ -0,0 +1,40 @@ +#!/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 < + +void world() { + printf("world\n"); +} + +void hello() { + printf("Hello "); + world(); +} +EOF + +clang -fuse-ld=`pwd`/../mold -shared -o $t/b.so $t/a.o + +cat < + +void world() { + printf("WORLD\n"); +} + +void hello(); + +int main() { + hello(); +} +EOF + +clang -fuse-ld=`pwd`/../mold -o $t/exe -Wl,-rpath=$t $t/c.o $t/b.so +$t/exe | grep -q 'Hello WORLD' + +echo OK