266 lines · plain
1# REQUIRES: x862 3# RUN: rm -rf %t && split-file %s %t && cd %t4# RUN: llvm-mc -n -filetype=obj -triple=x86_64 spill.s -o spill.o5 6## An input section spills to a later match when the region of its first match7## 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-regions10# RUN: llvm-readelf -S spill | FileCheck %s --check-prefix=SPILL11 12# SPILL: Name Type Address Off Size13# SPILL: .first_chance PROGBITS 0000000000000000 001000 00000114# SPILL-NEXT: .last_chance PROGBITS 0000000000000008 001008 00000215 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 bytes22 23## The above spill still occurs when the LMA would overflow, even though the24## VMA would fit.25 26# RUN: ld.lld -T spill-lma.ld spill.o -o spill-lma --enable-non-contiguous-regions27# RUN: llvm-readelf -S spill-lma | FileCheck %s --check-prefix=SPILL-LMA28 29# SPILL-LMA: Name Type Address Off Size30# SPILL-LMA: .first_chance PROGBITS 0000000000000000 001000 00000131# SPILL-LMA-NEXT: .last_chance PROGBITS 0000000000000003 001003 00000232 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-regions36# RUN: llvm-readelf -S spill-later | FileCheck %s --check-prefix=SPILL-LATER37 38# SPILL-LATER: Name Type Address Off Size39# SPILL-LATER: .first_chance PROGBITS 0000000000000000 001000 00000140# SPILL-LATER-NEXT: .second_chance PROGBITS 0000000000000002 001001 00000041# SPILL-LATER-NEXT: .last_chance PROGBITS 0000000000000003 001003 00000242 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-regions46# RUN: llvm-readelf -S spill-earlier | FileCheck %s --check-prefix=SPILL-EARLIER47 48# SPILL-EARLIER: Name Type Address Off Size49# SPILL-EARLIER: .first_chance PROGBITS 0000000000000000 001000 00000250# SPILL-EARLIER-NEXT: .last_chance PROGBITS 0000000000000002 001002 00000151 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 bytes58 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-regions62# RUN: llvm-readelf -S no-spill-from-discard | FileCheck %s --check-prefix=NO-SPILL-FROM-DISCARD63 64# NO-SPILL-FROM-DISCARD: Name Type Address Off Size65# NO-SPILL-FROM-DISCARD-NOT: .osec66 67## SHF_MERGEd sections are spilled according to the matches of the first merged68## 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.o71# RUN: ld.lld -T spill-merge.ld merge.o -o spill-merge --enable-non-contiguous-regions72# RUN: llvm-readelf -S spill-merge | FileCheck %s --check-prefix=SPILL-MERGE73 74# SPILL-MERGE: Name Type Address Off Size75# SPILL-MERGE: .first PROGBITS 0000000000000000 000190 00000076# SPILL-MERGE-NEXT: .second PROGBITS 0000000000000001 001001 00000277# SPILL-MERGE-NEXT: .third PROGBITS 0000000000000003 001003 00000078 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=INSERT83 84# INSERT: error: INSERT cannot be used with --enable-non-contiguous-regions85 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_SECTIONS90 91# OVERWRITE_SECTIONS: error: OVERWRITE_SECTIONS cannot be used with --enable-non-contiguous-regions92 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.o96# RUN: ld.lld -T link-order.ld link-order.o -o link-order --enable-non-contiguous-regions97# RUN: llvm-readobj -x .order link-order | FileCheck %s --check-prefix=LINK-ORDER98 99# LINK-ORDER: 020301100 101#--- spill.s102.section .one_byte_section,"a",@progbits103.fill 1104 105.section .two_byte_section,"a",@progbits106.fill 2107 108#--- spill.ld109MEMORY {110 a : ORIGIN = 0, LENGTH = 2111 b : ORIGIN = 2, LENGTH = 16112}113 114SECTIONS {115 .first_chance : SUBALIGN(1) { *(.one_byte_section) *(.two_byte_section) } >a116 .last_chance : SUBALIGN(8) { *(.two_byte_section) } >b117}118 119#--- spill-fail.ld120MEMORY {121 a : ORIGIN = 0, LENGTH = 1122 b : ORIGIN = 2, LENGTH = 0123}124 125SECTIONS {126 .first_chance : { *(.one_byte_section) *(.two_byte_section) } >a127 .last_chance : { *(.two_byte_section) } >b128}129 130#--- spill-lma.ld131MEMORY {132 vma_a : ORIGIN = 0, LENGTH = 3133 vma_b : ORIGIN = 3, LENGTH = 3134 lma_a : ORIGIN = 6, LENGTH = 2135 lma_b : ORIGIN = 8, LENGTH = 2136}137 138SECTIONS {139 .first_chance : { *(.one_byte_section) *(.two_byte_section) } >vma_a AT>lma_a140 .last_chance : { *(.two_byte_section) } >vma_b AT>lma_b141}142 143#--- spill-later.ld144MEMORY {145 a : ORIGIN = 0, LENGTH = 2146 b : ORIGIN = 2, LENGTH = 1147 c : ORIGIN = 3, LENGTH = 2148}149 150SECTIONS {151 .first_chance : { *(.one_byte_section) *(.two_byte_section) } >a152 .second_chance : { *(.two_byte_section) } >b153 .last_chance : { *(.two_byte_section) } >c154}155 156#--- spill-earlier.ld157MEMORY {158 a : ORIGIN = 0, LENGTH = 2159 b : ORIGIN = 2, LENGTH = 1160}161 162SECTIONS {163 .first_chance : { *(.one_byte_section) *(.two_byte_section) } >a164 .last_chance : { *(.one_byte_section) } >b165}166 167#--- no-spill-into-discard.ld168MEMORY {169 a : ORIGIN = 0, LENGTH = 1170}171 172SECTIONS {173 .osec : { *(.two_byte_section) } >a174 /DISCARD/ : { *(.one_byte_section) *(.two_byte_section) }175}176 177#--- no-spill-from-discard.ld178MEMORY {179 a : ORIGIN = 0, LENGTH = 2180}181 182SECTIONS {183 /DISCARD/ : { *(.one_byte_section) *(.two_byte_section) }184 .osec : { *(.two_byte_section) } >a185}186 187#--- merge.s188.section .a,"aM",@progbits,1189.byte 0x12, 0x34190 191.section .b,"aM",@progbits,1192.byte 0x12193 194#--- spill-merge.ld195MEMORY {196 a : ORIGIN = 0, LENGTH = 1197 b : ORIGIN = 1, LENGTH = 2198 c : ORIGIN = 3, LENGTH = 2199}200 201SECTIONS {202 .first : { *(.a) *(.b) } >a203 .second : { *(.a) } >b204 .third : { *(.b) } >c205}206 207#--- insert.ld208MEMORY {209 a : ORIGIN = 0, LENGTH = 1210}211 212SECTIONS {213 .a : { *(.two_byte_section) } >a214}215 216SECTIONS {217 .b : { *(.one_byte_section) } >a218} INSERT AFTER .a;219 220#--- overwrite-sections.ld221MEMORY {222 a : ORIGIN = 0, LENGTH = 1223}224 225SECTIONS {226 .a : { *(.two_byte_section) } >a227}228 229OVERWRITE_SECTIONS {230 .b : { *(.one_byte_section) } >a231}232 233#--- link-order.s234.section .a,"a",@progbits235.fill 1236 237.section .b,"a",@progbits238.fill 1239 240.section .c,"a",@progbits241.fill 1242 243.section .link_order.a,"ao",@progbits,.a244.byte 1245 246.section .link_order.b,"ao",@progbits,.b247.byte 2248 249.section .link_order.c,"ao",@progbits,.c250.byte 3251 252#--- link-order.ld253MEMORY {254 order : ORIGIN = 0, LENGTH = 3255 potential_a : ORIGIN = 3, LENGTH = 0256 bc : ORIGIN = 3, LENGTH = 2257 actual_a : ORIGIN = 5, LENGTH = 1258}259 260SECTIONS {261 .order : { *(.link_order.*) } > order262 .potential_a : { *(.a) } >potential_a263 .bc : { *(.b) *(.c) } >bc264 .actual_a : { *(.a) } >actual_a265}266