1# REQUIRES: x86 2 3# RUN: rm -rf %t && split-file %s %t && cd %t 4# RUN: llvm-mc -n -filetype=obj -triple=x86_64 spill.s -o spill.o 5 6## An input section spills to a later match when the region of its first match 7## would overflow. The spill uses the alignment of the later match. 8 9# RUN: ld.lld -T spill.ld spill.o -o spill --enable-non-contiguous-regions 10# RUN: llvm-readelf -S spill | FileCheck %s --check-prefix=SPILL 11 12# SPILL: Name Type Address Off Size 13# SPILL: .first_chance PROGBITS 0000000000000000 001000 000001 14# SPILL-NEXT: .last_chance PROGBITS 0000000000000008 001008 000002 15 16## A spill off the end still fails the link. 17 18# RUN: not ld.lld -T spill-fail.ld spill.o --enable-non-contiguous-regions 2>&1 |\ 19# RUN: FileCheck %s --check-prefix=SPILL-FAIL --implicit-check-not=error: 20 21# SPILL-FAIL: error: section '.last_chance' will not fit in region 'b': overflowed by 2 bytes 22 23## The above spill still occurs when the LMA would overflow, even though the 24## VMA would fit. 25 26# RUN: ld.lld -T spill-lma.ld spill.o -o spill-lma --enable-non-contiguous-regions 27# RUN: llvm-readelf -S spill-lma | FileCheck %s --check-prefix=SPILL-LMA 28 29# SPILL-LMA: Name Type Address Off Size 30# SPILL-LMA: .first_chance PROGBITS 0000000000000000 001000 000001 31# SPILL-LMA-NEXT: .last_chance PROGBITS 0000000000000003 001003 000002 32 33## A spill occurs to an additional match after the first. 34 35# RUN: ld.lld -T spill-later.ld spill.o -o spill-later --enable-non-contiguous-regions 36# RUN: llvm-readelf -S spill-later | FileCheck %s --check-prefix=SPILL-LATER 37 38# SPILL-LATER: Name Type Address Off Size 39# SPILL-LATER: .first_chance PROGBITS 0000000000000000 001000 000001 40# SPILL-LATER-NEXT: .second_chance PROGBITS 0000000000000002 001001 000000 41# SPILL-LATER-NEXT: .last_chance PROGBITS 0000000000000003 001003 000002 42 43## A later overflow causes an earlier section to spill. 44 45# RUN: ld.lld -T spill-earlier.ld spill.o -o spill-earlier --enable-non-contiguous-regions 46# RUN: llvm-readelf -S spill-earlier | FileCheck %s --check-prefix=SPILL-EARLIER 47 48# SPILL-EARLIER: Name Type Address Off Size 49# SPILL-EARLIER: .first_chance PROGBITS 0000000000000000 001000 000002 50# SPILL-EARLIER-NEXT: .last_chance PROGBITS 0000000000000002 001002 000001 51 52## An additional match in /DISCARD/ has no effect. 53 54# RUN: not ld.lld -T no-spill-into-discard.ld spill.o --enable-non-contiguous-regions 2>&1 |\ 55# RUN: FileCheck %s --check-prefix=NO-SPILL-INTO-DISCARD --implicit-check-not=error: 56 57# NO-SPILL-INTO-DISCARD: error: section '.osec' will not fit in region 'a': overflowed by 1 bytes 58 59## An additional match after /DISCARD/ has no effect. 60 61# RUN: ld.lld -T no-spill-from-discard.ld spill.o -o no-spill-from-discard --enable-non-contiguous-regions 62# RUN: llvm-readelf -S no-spill-from-discard | FileCheck %s --check-prefix=NO-SPILL-FROM-DISCARD 63 64# NO-SPILL-FROM-DISCARD: Name Type Address Off Size 65# NO-SPILL-FROM-DISCARD-NOT: .osec 66 67## SHF_MERGEd sections are spilled according to the matches of the first merged 68## input section (the one giving the resulting section its name). 69 70# RUN: llvm-mc -n -filetype=obj -triple=x86_64 merge.s -o merge.o 71# RUN: ld.lld -T spill-merge.ld merge.o -o spill-merge --enable-non-contiguous-regions 72# RUN: llvm-readelf -S spill-merge | FileCheck %s --check-prefix=SPILL-MERGE 73 74# SPILL-MERGE: Name Type Address Off Size 75# SPILL-MERGE: .first PROGBITS 0000000000000000 000190 000000 76# SPILL-MERGE-NEXT: .second PROGBITS 0000000000000001 001001 000002 77# SPILL-MERGE-NEXT: .third PROGBITS 0000000000000003 001003 000000 78 79## An error is reported for INSERT. 80 81# RUN: not ld.lld -T insert.ld spill.o --enable-non-contiguous-regions 2>&1 |\ 82# RUN: FileCheck %s --check-prefix=INSERT 83 84# INSERT: error: INSERT cannot be used with --enable-non-contiguous-regions 85 86## An error is reported for OVERWRITE_SECTIONS. 87 88# RUN: not ld.lld -T overwrite-sections.ld spill.o --enable-non-contiguous-regions 2>&1 |\ 89# RUN: FileCheck %s --check-prefix=OVERWRITE_SECTIONS 90 91# OVERWRITE_SECTIONS: error: OVERWRITE_SECTIONS cannot be used with --enable-non-contiguous-regions 92 93## SHF_LINK_ORDER is reordered when spilling changes relative section order. 94 95# RUN: llvm-mc -n -filetype=obj -triple=x86_64 link-order.s -o link-order.o 96# RUN: ld.lld -T link-order.ld link-order.o -o link-order --enable-non-contiguous-regions 97# RUN: llvm-readobj -x .order link-order | FileCheck %s --check-prefix=LINK-ORDER 98 99# LINK-ORDER: 020301 100 101#--- spill.s 102.section .one_byte_section,"a",@progbits 103.fill 1 104 105.section .two_byte_section,"a",@progbits 106.fill 2 107 108#--- spill.ld 109MEMORY { 110 a : ORIGIN = 0, LENGTH = 2 111 b : ORIGIN = 2, LENGTH = 16 112} 113 114SECTIONS { 115 .first_chance : SUBALIGN(1) { *(.one_byte_section) *(.two_byte_section) } >a 116 .last_chance : SUBALIGN(8) { *(.two_byte_section) } >b 117} 118 119#--- spill-fail.ld 120MEMORY { 121 a : ORIGIN = 0, LENGTH = 1 122 b : ORIGIN = 2, LENGTH = 0 123} 124 125SECTIONS { 126 .first_chance : { *(.one_byte_section) *(.two_byte_section) } >a 127 .last_chance : { *(.two_byte_section) } >b 128} 129 130#--- spill-lma.ld 131MEMORY { 132 vma_a : ORIGIN = 0, LENGTH = 3 133 vma_b : ORIGIN = 3, LENGTH = 3 134 lma_a : ORIGIN = 6, LENGTH = 2 135 lma_b : ORIGIN = 8, LENGTH = 2 136} 137 138SECTIONS { 139 .first_chance : { *(.one_byte_section) *(.two_byte_section) } >vma_a AT>lma_a 140 .last_chance : { *(.two_byte_section) } >vma_b AT>lma_b 141} 142 143#--- spill-later.ld 144MEMORY { 145 a : ORIGIN = 0, LENGTH = 2 146 b : ORIGIN = 2, LENGTH = 1 147 c : ORIGIN = 3, LENGTH = 2 148} 149 150SECTIONS { 151 .first_chance : { *(.one_byte_section) *(.two_byte_section) } >a 152 .second_chance : { *(.two_byte_section) } >b 153 .last_chance : { *(.two_byte_section) } >c 154} 155 156#--- spill-earlier.ld 157MEMORY { 158 a : ORIGIN = 0, LENGTH = 2 159 b : ORIGIN = 2, LENGTH = 1 160} 161 162SECTIONS { 163 .first_chance : { *(.one_byte_section) *(.two_byte_section) } >a 164 .last_chance : { *(.one_byte_section) } >b 165} 166 167#--- no-spill-into-discard.ld 168MEMORY { 169 a : ORIGIN = 0, LENGTH = 1 170} 171 172SECTIONS { 173 .osec : { *(.two_byte_section) } >a 174 /DISCARD/ : { *(.one_byte_section) *(.two_byte_section) } 175} 176 177#--- no-spill-from-discard.ld 178MEMORY { 179 a : ORIGIN = 0, LENGTH = 2 180} 181 182SECTIONS { 183 /DISCARD/ : { *(.one_byte_section) *(.two_byte_section) } 184 .osec : { *(.two_byte_section) } >a 185} 186 187#--- merge.s 188.section .a,"aM",@progbits,1 189.byte 0x12, 0x34 190 191.section .b,"aM",@progbits,1 192.byte 0x12 193 194#--- spill-merge.ld 195MEMORY { 196 a : ORIGIN = 0, LENGTH = 1 197 b : ORIGIN = 1, LENGTH = 2 198 c : ORIGIN = 3, LENGTH = 2 199} 200 201SECTIONS { 202 .first : { *(.a) *(.b) } >a 203 .second : { *(.a) } >b 204 .third : { *(.b) } >c 205} 206 207#--- insert.ld 208MEMORY { 209 a : ORIGIN = 0, LENGTH = 1 210} 211 212SECTIONS { 213 .a : { *(.two_byte_section) } >a 214} 215 216SECTIONS { 217 .b : { *(.one_byte_section) } >a 218} INSERT AFTER .a; 219 220#--- overwrite-sections.ld 221MEMORY { 222 a : ORIGIN = 0, LENGTH = 1 223} 224 225SECTIONS { 226 .a : { *(.two_byte_section) } >a 227} 228 229OVERWRITE_SECTIONS { 230 .b : { *(.one_byte_section) } >a 231} 232 233#--- link-order.s 234.section .a,"a",@progbits 235.fill 1 236 237.section .b,"a",@progbits 238.fill 1 239 240.section .c,"a",@progbits 241.fill 1 242 243.section .link_order.a,"ao",@progbits,.a 244.byte 1 245 246.section .link_order.b,"ao",@progbits,.b 247.byte 2 248 249.section .link_order.c,"ao",@progbits,.c 250.byte 3 251 252#--- link-order.ld 253MEMORY { 254 order : ORIGIN = 0, LENGTH = 3 255 potential_a : ORIGIN = 3, LENGTH = 0 256 bc : ORIGIN = 3, LENGTH = 2 257 actual_a : ORIGIN = 5, LENGTH = 1 258} 259 260SECTIONS { 261 .order : { *(.link_order.*) } > order 262 .potential_a : { *(.a) } >potential_a 263 .bc : { *(.b) *(.c) } >bc 264 .actual_a : { *(.a) } >actual_a 265} 266