[lld] [LLD] Implement --enable-non-contiguous-regions (PR #90007)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri May 10 14:25:48 PDT 2024
================
@@ -0,0 +1,279 @@
+# REQUIRES: x86
+
+# RUN: split-file %s %t
+# RUN: llvm-mc -n -filetype=obj -triple=x86_64 %t/spill.s -o %t/spill.o
+
+## An input section must spill to a later match if the region of its first match
+## would overflow.
+
+# RUN: ld.lld -T %t/spill.ld %t/spill.o -o %t/spill --enable-non-contiguous-regions
+# RUN: llvm-readelf -S %t/spill | FileCheck %s -check-prefix=SPILL
+
+# SPILL: Name Type Address Off Size
+# SPILL: .first_chance PROGBITS 0000000000000000 001000 000001
+# SPILL-NEXT: .last_chance PROGBITS 0000000000000002 001002 000002
+
+## A spill off the end must still fail the link.
+
+# RUN: not ld.lld -T %t/spill-fail.ld %t/spill.o -o %t/spill-fail --enable-non-contiguous-regions 2>&1 |\
+# RUN: FileCheck %s -check-prefix=SPILL-FAIL
+
+# SPILL-FAIL: error: section '.last_chance' will not fit in region 'b': overflowed by 2 bytes
+
+## The above spill must still occur if the LMA would overflow, even if the VMA
+## would fit.
+
+# RUN: ld.lld -T %t/spill-lma.ld %t/spill.o -o %t/spill-lma --enable-non-contiguous-regions
+# RUN: llvm-readelf -S %t/spill-lma | FileCheck %s -check-prefix=SPILL-LMA
+
+# SPILL-LMA: Name Type Address Off Size
+# SPILL-LMA: .first_chance PROGBITS 0000000000000000 001000 000001
+# SPILL-LMA-NEXT: .last_chance PROGBITS 0000000000000003 001003 000002
+
+## A spill must be able to occur to an additional match after the first.
+
+# RUN: ld.lld -T %t/spill-later.ld %t/spill.o -o %t/spill-later --enable-non-contiguous-regions
+# RUN: llvm-readelf -S %t/spill-later | FileCheck %s -check-prefix=SPILL-LATER
+
+# SPILL-LATER: Name Type Address Off Size
+# SPILL-LATER: .first_chance PROGBITS 0000000000000000 001000 000001
+# SPILL-LATER-NEXT: .second_chance PROGBITS 0000000000000002 001001 000000
+# SPILL-LATER-NEXT: .last_chance PROGBITS 0000000000000003 001003 000002
+
+## A later overflow must be able to cause an earlier section to spill.
+
+# RUN: ld.lld -T %t/spill-earlier.ld %t/spill.o -o %t/spill-earlier --enable-non-contiguous-regions
+# RUN: llvm-readelf -S %t/spill-earlier | FileCheck %s -check-prefix=SPILL-EARLIER
+
+# SPILL-EARLIER: Name Type Address Off Size
+# SPILL-EARLIER: .first_chance PROGBITS 0000000000000000 001000 000002
+# SPILL-EARLIER-NEXT: .last_chance PROGBITS 0000000000000002 001002 000001
+
+## An additional match in /DISCARD/ must have no effect.
+
+# RUN: not ld.lld -T %t/no-spill-into-discard.ld %t/spill.o -o %t/no-spill-into-discard --enable-non-contiguous-regions 2>&1 |\
+# RUN: FileCheck %s -check-prefix=NO-SPILL-INTO-DISCARD
+
+# NO-SPILL-INTO-DISCARD: error: section '.osec' will not fit in region 'a': overflowed by 1 bytes
+
+## An additional match after /DISCARD/ must have no effect.
+
+# RUN: ld.lld -T %t/no-spill-from-discard.ld %t/spill.o -o %t/no-spill-from-discard --enable-non-contiguous-regions
+# RUN: llvm-readelf -S %t/no-spill-from-discard | FileCheck %s -check-prefix=NO-SPILL-FROM-DISCARD
+
+# NO-SPILL-FROM-DISCARD: Name Type Address Off Size
+# NO-SPILL-FROM-DISCARD-NOT: .osec
+
+## A spill must use the alignment of the later match.
+
+# RUN: ld.lld -T %t/spill-align.ld %t/spill.o -o %t/spill-align --enable-non-contiguous-regions
----------------
MaskRay wrote:
This subalign test can be merged into the basic `spill.ld` test.
We try to cover every case while using a smaller number of tests.
https://github.com/llvm/llvm-project/pull/90007
More information about the llvm-commits
mailing list