[lld] [LLD] Implement --enable-non-contiguous-regions (PR #90007)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Wed May 1 05:38:17 PDT 2024


================
@@ -0,0 +1,54 @@
+# If a spilling reorders input sections, the .ARM.exidx table must be rebuilt
+# using the new order.
+
+RUN: split-file %s %t
+RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %t/test.s -o %t/test.o
+RUN: ld.lld -T %t/test.ld %t/test.o -o %t/test --enable-non-contiguous-regions
+RUN: llvm-readobj -x .ARM.exidx %t/test | FileCheck %s
+
+CHECK:      20000000 08849780 1c000000 10849880
+CHECK-NEXT: 18000000 20849980 14000000 01000000
+
+#--- test.ld
+MEMORY {
+  exidx : ORIGIN = 0, LENGTH = 32
+  a : ORIGIN = 32, LENGTH = 4
+  b : ORIGIN = 36, LENGTH = 4
+  c : ORIGIN = 40, LENGTH = 4
+}
+
+SECTIONS {
+  .ARM.exidx : { *(.ARM.exidx) } >exidx
+  .first_chance : { *(.text .text.f2) } >a
+  .text.f1 : { *(.text.f1) } >b
+  .last_chance : { *(.text.f2) } >c
+}
+
+#--- test.s
+ .syntax unified
+ .section .text, "ax",%progbits
+ .globl _start
+_start:
+ .fnstart
+ bx lr
+ .save {r7, lr}
+ .setfp r7, sp, #0
+ .fnend
+
+ .section .text.f1, "ax", %progbits
+ .globl f1
+f1:
+ .fnstart
+ bx lr
+ .save {r8, lr}
+ .setfp r8, sp, #0
+ .fnend
+
+ .section .text.f2, "ax", %progbits
+ .globl f2
+f2:
+ .fnstart
+ bx lr
+ .save {r9, lr}
+ .setfp r9, sp, #0
----------------
smithp35 wrote:

I think it could be worth making the unwind instructions identical for at least two of the sections. The .exidx table compression merges identical entries. One of things I was worried about with this patch was whether the table compression would still work properly when the order of sections could change.

I think that there could be corner cases where the table compression changes causes the sizes of the .ARM.exidx to change significantly, which then affects thunks, which then affects spills.

For example if we have sections A, B, C with .ARM.exidx A', B' and C', but with A' and B' identical, but C' different. If on pass 1 we have order A, B, C then A' and B' will be compressed. However if spills cause the order to be A, C, B then the table can no longer be compressed.


However to make a test that actually fails to converge would be difficult and not representative of real world usage. For example .ARM.exidx is ro-data so it tends to be all before or all after.

https://github.com/llvm/llvm-project/pull/90007


More information about the llvm-commits mailing list