From 5046fae0cf89d9e2d79c935501f25e16b45519b1 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 25 Jun 2021 00:57:48 +0900 Subject: [PATCH] Do not directly call imported functions This is needed by Gentoo's sci-libs/lapack-3.9.0-r1 package. --- mold.h | 12 ++++++------ test/plt-dso.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 6 deletions(-) create mode 100755 test/plt-dso.sh 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