Skip to content

Commit

Permalink
Allow larger range extension thunks
Browse files Browse the repository at this point in the history
Fixes #1224
  • Loading branch information
rui314 committed May 27, 2024
1 parent 08b0a16 commit c7c8583
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
6 changes: 4 additions & 2 deletions elf/mold.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ class Thunk<E> {
};

struct ThunkRef {
i16 thunk_idx = -1;
i16 sym_idx = -1;
static constexpr i64 MAX_SYM_IDX = (1 << 17) - 1;

i32 thunk_idx : 14 = -1;
i32 sym_idx : 18 = -1;
};

//
Expand Down
6 changes: 3 additions & 3 deletions elf/thunks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ static consteval i64 max_distance() {
// ARM64/ARM32/PPC, respectively.
static constexpr i64 batch_size = max_distance() / 10;

// We assume that a single thunk group is smaller than 100 KiB.
static constexpr i64 max_thunk_size = 102400;
// We assume that a single thunk group is smaller than 900 KiB.
static constexpr i64 max_thunk_size = 900 * 1024;

static_assert(max_thunk_size / E::thunk_size < INT16_MAX);
static_assert(max_thunk_size / E::thunk_size < ThunkRef::MAX_SYM_IDX);

template <typename E>
static bool is_reachable(Context<E> &ctx, InputSection<E> &isec,
Expand Down
17 changes: 17 additions & 0 deletions test/elf/range-extension-thunk3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
. $(dirname $0)/common.inc

[ $MACHINE = alpha ] && skip
[ $MACHINE = sh4 ] && skip

seq 1 10000 | sed 's/.*/void func\0() {}/' > $t/a.c
$CC -B. -o $t/b.so -shared $t/a.c

seq 1 10000 | sed 's/.*/void func\0();/' > $t/c.c
echo 'int main() {' >> $t/c.c
seq 1 10000 | sed 's/.*/func\0();/' >> $t/c.c
echo '}' >> $t/c.c

$CC -c -o $t/d.o $t/c.c
$CC -B. -o $t/exe $t/d.o $t/b.so
$QEMU $t/exe

0 comments on commit c7c8583

Please sign in to comment.