Skip to content

Commit

Permalink
Set a correct value to __iplt_start for statically-linked binaries
Browse files Browse the repository at this point in the history
Fixes #930
  • Loading branch information
rui314 committed Dec 30, 2022
1 parent ad30db1 commit ccd47db
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
5 changes: 4 additions & 1 deletion elf/input-sections.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,17 @@ static void scan_rel(Context<E> &ctx, InputSection<E> &isec, Symbol<E> &sym,
sym.flags |= NEEDS_CPLT;
break;
case DYNREL:
case IFUNC:
dynrel();
break;
case BASEREL:
check_textrel();
if (!isec.is_relr_reloc(ctx, rel))
isec.file.num_dynrel++;
break;
case IFUNC:
dynrel();
ctx.num_ifunc_dynrels.fetch_add(1, std::memory_order_relaxed);
break;
default:
unreachable();
}
Expand Down
1 change: 1 addition & 0 deletions elf/mold.h
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,7 @@ struct Context {
std::atomic_bool needs_tlsld = false;
std::atomic_bool has_gottp_rel = false;
std::atomic_bool has_textrel = false;
std::atomic_uint32_t num_ifunc_dynrels = 0;

tbb::concurrent_hash_map<std::string_view, std::vector<std::string>> undef_errors;

Expand Down
6 changes: 3 additions & 3 deletions elf/passes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2160,9 +2160,9 @@ i64 set_osec_offsets(Context<E> &ctx) {

template <typename E>
static i64 get_num_irelative_relocs(Context<E> &ctx) {
return std::count_if(
ctx.got->got_syms.begin(), ctx.got->got_syms.end(),
[](Symbol<E> *sym) { return sym->is_ifunc(); });
i64 n = std::count_if(ctx.got->got_syms.begin(), ctx.got->got_syms.end(),
[](Symbol<E> *sym) { return sym->is_ifunc(); });
return n + ctx.num_ifunc_dynrels;
}

template <typename E>
Expand Down
27 changes: 27 additions & 0 deletions test/elf/x86_64_ifunc-alias.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
. $(dirname $0)/common.inc

cat <<EOF | $CXX -o $t/a.o -c -xc++ - -fno-PIE
#include <assert.h>
#include <stdio.h>
__attribute__((target("default")))
int foo() {
return 0;
}
__attribute__((target("ssse3,avx2")))
int foo() {
return 1;
}
int (*p)() = foo;
int main() {
int val = foo();
assert(val == p());
}
EOF

$CXX -B. -o $t/exe $t/a.o -static
$QEMU $t/exe

0 comments on commit ccd47db

Please sign in to comment.