[llvm] [BOLT][AArch64] Add support for compact code model (PR #112110)
Paschalis Mpeis via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 14 10:19:55 PDT 2024
================
@@ -0,0 +1,48 @@
+## Check that llvm-bolt successfully relaxes branches for compact (<128MB) code
+## model.
+
+# RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
+# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -static
+# RUN: llvm-bolt %t.exe -o %t.bolt --split-functions --split-strategy=randomN \
+# RUN: --keep-nops --compact-code-model
+# RUN: llvm-objdump -d --disassemble-symbols=_start %t.bolt | FileCheck %s
+# RUN: llvm-nm -n %t.bolt | FileCheck %s --check-prefix=CHECK-NM
+
+## _start will be split and its main fragment will be separated from other
----------------
paschalis-mpeis wrote:
> One possible extension so that this could be used without needing a compact mode, is to write the stub as ADRP, ADD, BR if the destination were greater than 128MB away. LLD will try and use "short" unconditional branches at first, but if these get knocked out of range they are rewritten as "long" sequences. This can add more passes as more instructions are added. We also don't change a long stub back to a short one to make sure we converge.
@smithp35 that must be what the original LongJmp was doing, ie before the `--compact-code-model` extension.
This is the [loop](https://github.com/llvm/llvm-project/blob/9c5b3401612f61cdb473a63ad66fb6fe4d67df71/bolt/lib/Passes/LongJmp.cpp#L909) of the fix point algorithm; if relaxations keep happening (in [relaxStub](https://github.com/llvm/llvm-project/blob/9c5b3401612f61cdb473a63ad66fb6fe4d67df71/bolt/lib/Passes/LongJmp.cpp#L505)) the algorithm [keeps going](https://github.com/llvm/llvm-project/blob/9c5b3401612f61cdb473a63ad66fb6fe4d67df71/bolt/lib/Passes/LongJmp.cpp#L922).
During relaxation:
- When code is beyond br limits (-+128MB with [SingleInstrMask](https://github.com/llvm/llvm-project/blob/9c5b3401612f61cdb473a63ad66fb6fe4d67df71/bolt/lib/Passes/LongJmp.cpp#L491)) but within ADRP/ADD/BR range (-+4GB with [ShortJmpMask](https://github.com/llvm/llvm-project/blob/9c5b3401612f61cdb473a63ad66fb6fe4d67df71/bolt/lib/Passes/LongJmp.cpp#L495)), then it relaxes with a 'short jump' ([relaxStubToShortJmp](https://github.com/llvm/llvm-project/blob/9c5b3401612f61cdb473a63ad66fb6fe4d67df71/bolt/lib/Passes/LongJmp.cpp#L503) that emits the ADRP/ADD/ BR sequence).
- When it does not fit ADRP range (beyond 4GB of text) and given the binary is a non-PIC, it will use the long-jump sequence ([relaxStubToLongJmp](https://github.com/llvm/llvm-project/blob/9c5b3401612f61cdb473a63ad66fb6fe4d67df71/bolt/lib/Passes/LongJmp.cpp#L518C3-L518C21) with absolute addressing).
(the naming is a bit different as long jump refers >4GB addressing and short jump to >128MB)
https://github.com/llvm/llvm-project/pull/112110
More information about the llvm-commits
mailing list