58 lines · plain
1# REQUIRES: aarch642# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %s -o %t.o3# RUN: %lld -arch arm64 -lSystem -o %t.out %t.o4 5## Regression test for PR51578.6 7.subsections_via_symbols8 9.globl _f1, _f2, _f3, _f4, _f5, _f610.p2align 211_f1: b _fn112_f2: b _fn213_f3: b _fn314_f4: b _fn415_f5: b _fn516_f6: b _fn617## 6 * 4 = 24 bytes for branches18## Currently leaves 12 bytes for one thunk, so 36 bytes.19## Uses < instead of <=, so 40 bytes.20 21.global _spacer1, _spacer222## 0x8000000 is 128 MiB, one more than the forward branch limit,23## distributed over two functions since our thunk insertion algorithm24## can't deal with a single function that's 128 MiB.25## We leave just enough room so that the old thunking algorithm finalized26## both spacers when processing _f1 (24 bytes for the 4 bytes code for each27## of the 6 _f functions, 12 bytes for one thunk, 4 bytes because the forward28## branch range is 128 Mib - 4 bytes, and another 4 bytes because the algorithm29## uses `<` instead of `<=`, for a total of 44 bytes slop.) Of the slop, 2030## bytes are actually room for thunks.31## _fn1-_fn6 aren't finalized because then there wouldn't be room for a thunk.32## But when a thunk is inserted to jump from _f1 to _fn1, that needs 12 bytes33## but _f2 is only 4 bytes later, so after _f1 there are only34## 20-(12-4) = 12 bytes left, after _f2 only 12-(12-4) 4 bytes, and after35## _f3 there's no more room for thunks and we can't make progress.36## The fix is to leave room for many more thunks.37## The same construction as this test case can defeat that too with enough38## consecutive jumps, but in practice there aren't hundreds of consecutive39## jump instructions.40 41_spacer1:42.space 0x400000043_spacer2:44.space 0x4000000 - 4445 46.globl _fn1, _fn2, _fn3, _fn4, _fn5, _fn647.p2align 248_fn1: ret49_fn2: ret50_fn3: ret51_fn4: ret52_fn5: ret53_fn6: ret54 55.globl _main56_main:57 ret58