brintos

brintos / llvm-project-archived public Read only

0
0
Text · 17.5 KiB · 27273f3 Raw
553 lines · plain
1# REQUIRES: x862 3# RUN: rm -rf %t && split-file %s %t && cd %t4 5#--- matching.s6.section .rodata.a,"a",@progbits7.byte 18 9.section .rodata.b,"a",@progbits10.byte 211 12.section .rodata.c,"ax",@progbits13.byte 314 15.section .rodata.d,"a",@progbits16.byte 417 18.section .rodata.e,"a",@progbits19.byte 520 21.section .rodata.f,"a",@progbits22.balign 223.byte 624 25.section .rodata.g,"a",@progbits26.byte 727 28.section .rodata.h,"a",@progbits29.byte 830 31# RUN: llvm-mc -n -filetype=obj -triple=x86_64 matching.s -o matching.o32 33#--- matching.lds34## CLASS definitions match sections in linker script order. The sections may be35## placed in a different order. Classes may derive from one another. Class36## references can be restricted by INPUT_SECTION_FLAGS. Classes can be referenced37## in /DISCARD/ and INSERT.38SECTIONS {39  CLASS(a) { *(.rodata.a) }40  CLASS(cd) { *(.rodata.c) *(.rodata.d) }41  CLASS(ef) { *(SORT_BY_ALIGNMENT(.rodata.e .rodata.f)) }42  CLASS(g) { *(.rodata.g) }43  CLASS("h)") { *(.rodata.h) }44  .rodata : {45    *(.rodata.*)46    INPUT_SECTION_FLAGS(SHF_EXECINSTR) CLASS( cd)47    CLASS(a)CLASS(ef )48  }49  OVERLAY : { .rodata.d { INPUT_SECTION_FLAGS(!SHF_EXECINSTR) CLASS(cd) } }50  /DISCARD/ : { CLASS(g) }51}52 53SECTIONS {54  .rodata.h : { CLASS("h)") }55} INSERT AFTER .rodata;56 57# RUN: ld.lld -T matching.lds matching.o -o matching58# RUN: llvm-objdump -s matching |\59# RUN:   FileCheck %s --check-prefix=MATCHING60# MATCHING:      .rodata61# MATCHING-NEXT: 020301cc 0605 ......{{$}}62# MATCHING:      .rodata.h63# MATCHING-NEXT: 08 .{{$}}64# MATCHING:      .rodata.d65# MATCHING-NEXT: 04 .{{$}}66 67#--- already-defined.lds68## A section class has more than one description.69SECTIONS {70  CLASS(a) { *(.rodata.a) }71  CLASS(a) { *(.rodata.b) }72  CLASS(b) { *(.rodata.c) }73  CLASS(b) { *(.rodata.d) }74}75 76# RUN: not ld.lld -T already-defined.lds matching.o 2>&1 | \77# RUN:   FileCheck %s --check-prefix=ALREADY-DEFINED --implicit-check-not=error:78 79# ALREADY-DEFINED: error: already-defined.lds:4: section class 'a' already defined80 81#--- missing-filename-pattern-1.lds82## A filename pattern is missing in a section class description.83SECTIONS {84  CLASS(a) { (.rodata.a) }85}86#--- missing-filename-pattern-2.lds87## A filename pattern is missing in a section class description.88SECTIONS {89  CLASS(a) { .rodata.a) }90}91 92# RUN: not ld.lld -T missing-filename-pattern-1.lds matching.o 2>&1 | \93# RUN:   FileCheck %s --check-prefix=MISSING-FILENAME-PATTERN --implicit-check-not=error:94# RUN: not ld.lld -T missing-filename-pattern-2.lds matching.o 2>&1 | \95# RUN:   FileCheck %s --check-prefix=MISSING-FILENAME-PATTERN --implicit-check-not=error:96 97# MISSING-FILENAME-PATTERN: error: missing-filename-pattern-{{[1-2]}}.lds:3: expected filename pattern98 99#--- multiple-class-names.lds100## More than one class is mentioned in a reference.101SECTIONS {102  CLASS(a) { *(.rodata.a) }103  CLASS(b) { *(.rodata.b) }104  .rodata : { CLASS(a b) }105}106 107# RUN: not ld.lld -T multiple-class-names.lds matching.o 2>&1 | \108# RUN:   FileCheck %s --check-prefix=MULTIPLE-CLASS-NAMES --implicit-check-not=error:109 110# MULTIPLE-CLASS-NAMES: error: multiple-class-names.lds:5: ) expected, but got b111 112#--- undefined.lds113## A section class is referenced but never defined114SECTIONS {115  .rodata : { CLASS(a) }116}117 118# RUN: not ld.lld -T undefined.lds matching.o 2>&1 | \119# RUN:   FileCheck %s --check-prefix=UNDEFINED --implicit-check-not=error:120 121# UNDEFINED: error: undefined section class 'a'122 123#--- referenced-before-defined.lds124## The content of section classes is demanded before its definition is processed.125SECTIONS {126  .rodata : { CLASS(a) }127  CLASS(a) { *(.rodata.a) }128}129 130# RUN: not ld.lld -T referenced-before-defined.lds matching.o 2>&1 | \131# RUN:   FileCheck %s --check-prefix=REFERENCED-BEFORE-DEFINED132# RUN: ld.lld -T referenced-before-defined.lds matching.o -o out --noinhibit-exec 2>&1 | \133# RUN:   FileCheck %s --check-prefix=REFERENCED-BEFORE-DEFINED-WARN134 135# REFERENCED-BEFORE-DEFINED: error: section class 'a' referenced by '.rodata' before class definition136# REFERENCED-BEFORE-DEFINED-WARN: warning: section class 'a' referenced by '.rodata' before class definition137 138#--- unreferenced.lds139## An input section is bound to a section class but is not referenced.140SECTIONS {141  CLASS(a) { *(.rodata.*) }142}143 144# RUN: not ld.lld -T unreferenced.lds matching.o 2>&1 | \145# RUN:   FileCheck %s --check-prefix=UNREFERENCED -implicit-check-not=error:146# RUN: ld.lld -T unreferenced.lds matching.o -o out --noinhibit-exec 2>&1 | \147# RUN:   FileCheck %s --check-prefix=UNREFERENCED-WARN -implicit-check-not=error:148 149# UNREFERENCED: error: section class 'a' is unreferenced150# UNREFERENCED-WARN: warning: section class 'a' is unreferenced151 152#--- class-references-class.lds153## One section class references another.154SECTIONS {155  CLASS(a) { *(.rodata.a) }156  CLASS(b) { CLASS(a) }157}158 159# RUN: not ld.lld -T class-references-class.lds matching.o 2>&1 | \160# RUN:   FileCheck %s --check-prefix=CLASS-REFERENCES-CLASS --implicit-check-not=error:161 162# CLASS-REFERENCES-CLASS: error: class-references-class.lds:4: section class 'b' references class 'a'163 164#--- spill.s165.section .one_byte_section,"a",@progbits166.fill 1167 168.section .two_byte_section,"a",@progbits169.fill 2170 171# RUN: llvm-mc -n -filetype=obj -triple=x86_64 spill.s -o spill.o172 173#--- spill.lds174## An input section in a class spills to a later class ref when the region of175## its first ref would overflow. The spill uses the alignment of the later ref.176MEMORY {177  a : ORIGIN = 0, LENGTH = 2178  b : ORIGIN = 2, LENGTH = 16179}180 181SECTIONS {182  CLASS(c) { *(.two_byte_section) }183  .first_chance : SUBALIGN(1) { *(.one_byte_section) CLASS(c) } >a184  .last_chance : SUBALIGN(8) { CLASS (c) } >b185}186 187# RUN: ld.lld -T spill.lds spill.o -o spill188# RUN: llvm-readelf -S spill | FileCheck %s --check-prefix=SPILL189 190# SPILL:      Name          Type     Address          Off    Size191# SPILL:      .first_chance PROGBITS 0000000000000000 001000 000001192# SPILL-NEXT: .last_chance  PROGBITS 0000000000000008 001008 000002193 194#--- spill-fail.lds195## A spill off the end still fails the link.196MEMORY {197  a : ORIGIN = 0, LENGTH = 1198  b : ORIGIN = 2, LENGTH = 0199}200 201SECTIONS {202  CLASS(c) { *(.two_byte_section) }203  .first_chance : { *(.one_byte_section) CLASS(c) } >a204  .last_chance : { CLASS(c) } >b205}206 207# RUN: not ld.lld -T spill-fail.lds spill.o 2>&1 |\208# RUN:   FileCheck %s --check-prefix=SPILL-FAIL --implicit-check-not=error:209 210# SPILL-FAIL: error: section '.last_chance' will not fit in region 'b': overflowed by 2 bytes211 212#--- spill-lma.lds213## The above spill still occurs when the LMA would overflow, even though the214## VMA would fit.215MEMORY {216  vma_a : ORIGIN = 0, LENGTH = 3217  vma_b : ORIGIN = 3, LENGTH = 3218  lma_a : ORIGIN = 6, LENGTH = 2219  lma_b : ORIGIN = 8, LENGTH = 2220}221 222SECTIONS {223  CLASS(c) { *(.two_byte_section) }224  .first_chance : { *(.one_byte_section) CLASS(c) } >vma_a AT>lma_a225  .last_chance : { CLASS(c) } >vma_b AT>lma_b226}227 228# RUN: ld.lld -T spill-lma.lds spill.o -o spill-lma229# RUN: llvm-readelf -S spill-lma | FileCheck %s --check-prefix=SPILL-LMA230 231# SPILL-LMA:      Name          Type     Address          Off    Size232# SPILL-LMA:      .first_chance PROGBITS 0000000000000000 001000 000001233# SPILL-LMA-NEXT: .last_chance  PROGBITS 0000000000000003 001003 000002234 235#--- spill-later.lds236## A spill occurs to an additional class ref after the first.237MEMORY {238  a : ORIGIN = 0, LENGTH = 2239  b : ORIGIN = 2, LENGTH = 1240  c : ORIGIN = 3, LENGTH = 2241}242 243SECTIONS {244  CLASS(c) { *(.two_byte_section) }245  .first_chance : { *(.one_byte_section) CLASS(c) } >a246  .second_chance : { CLASS(c) } >b247  .last_chance : { CLASS(c) } >c248}249 250# RUN: ld.lld -T spill-later.lds spill.o -o spill-later251# RUN: llvm-readelf -S spill-later | FileCheck %s --check-prefix=SPILL-LATER252 253# SPILL-LATER:      Name            Type     Address          Off    Size254# SPILL-LATER:      .first_chance   PROGBITS 0000000000000000 001000 000001255# SPILL-LATER-NEXT: .second_chance  PROGBITS 0000000000000002 001001 000000256# SPILL-LATER-NEXT: .last_chance    PROGBITS 0000000000000003 001003 000002257 258#--- spill-earlier.lds259## A later overflow causes an earlier section to spill.260MEMORY {261  a : ORIGIN = 0, LENGTH = 2262  b : ORIGIN = 2, LENGTH = 1263}264 265SECTIONS {266  CLASS(c) { *(.one_byte_section) }267  .first_chance : { CLASS(c) *(.two_byte_section) } >a268  .last_chance : { CLASS(c) } >b269}270 271# RUN: ld.lld -T spill-earlier.lds spill.o -o spill-earlier272# RUN: llvm-readelf -S spill-earlier | FileCheck %s --check-prefix=SPILL-EARLIER273 274# SPILL-EARLIER:      Name          Type     Address          Off    Size275# SPILL-EARLIER:      .first_chance PROGBITS 0000000000000000 001000 000002276# SPILL-EARLIER-NEXT: .last_chance  PROGBITS 0000000000000002 001002 000001277 278#--- enable-non-contiguous-regions.lds279## Class definitions do not preclude additional matches when used with280## --enable-non-contiguous-regions, and additional matches in class281## definitions become spills at class references.282MEMORY {283  a : ORIGIN = 0, LENGTH = 1284  b : ORIGIN = 1, LENGTH = 2285  c : ORIGIN = 3, LENGTH = 1286}287 288SECTIONS {289  .first_chance : { *(.two_byte_section) } >a290  /* An additional match in a class defers a spill. */291  CLASS(two) { *(.two_byte_section) }292  /* A class references actualizes deferred spills. */293  .last_chance : { CLASS(two) } >b294 295  /* Section classes do not preclude other matches. */296  CLASS(one) { *(.one_byte_section) }297  .one_byte_section : { *(.one_byte_section) } >c298}299 300# RUN: ld.lld -T enable-non-contiguous-regions.lds spill.o -o enable-non-contiguous-regions --enable-non-contiguous-regions301# RUN: llvm-readelf -S enable-non-contiguous-regions | FileCheck %s --check-prefix=ENABLE-NON-CONTIGUOUS-REGIONS302 303# ENABLE-NON-CONTIGUOUS-REGIONS:      Name          Type     Address          Off    Size304# ENABLE-NON-CONTIGUOUS-REGIONS:      .first_chance     PROGBITS 0000000000000000 000190 000000305# ENABLE-NON-CONTIGUOUS-REGIONS-NEXT: .last_chance      PROGBITS 0000000000000001 001001 000002306# ENABLE-NON-CONTIGUOUS-REGIONS-NEXT: .one_byte_section PROGBITS 0000000000000003 001003 000001307 308#--- merge.s309.section .a,"aM",@progbits,1310.byte 0x12, 0x34311 312.section .b,"aM",@progbits,1313.p2align 3314.byte 0x12315 316# RUN: llvm-mc -n -filetype=obj -triple=x86_64 merge.s -o merge.o317 318#--- spill-merge.lds319## SHF_MERGE sections are spilled according to the class refs of the first320## merged input section (the one giving the resulting section its name).321## Spills take into account increases in section alignment due to merging.322MEMORY {323  a : ORIGIN = 0, LENGTH = 1324  b : ORIGIN = 1, LENGTH = 16325  c : ORIGIN = 17, LENGTH = 16326}327 328SECTIONS {329  CLASS(a) { *(.a) }330  CLASS(b) { *(.b) }331  .first : { CLASS(a) CLASS(b) } >a332  .second : { CLASS(a) } >b333  .third : { CLASS(b) } >c334}335 336# RUN: ld.lld -T spill-merge.lds merge.o -o spill-merge337# RUN: llvm-readelf -S -x .second spill-merge | FileCheck %s --check-prefix=SPILL-MERGE338 339# SPILL-MERGE:      Name    Type     Address          Off    Size340# SPILL-MERGE:      .first  PROGBITS 0000000000000000 000190 000000341# SPILL-MERGE-NEXT: .second PROGBITS 0000000000000008 001008 000009342# SPILL-MERGE-NEXT: .third  PROGBITS 0000000000000018 001018 000000343# SPILL-MERGE:      Hex dump of section '.second':344# SPILL-MERGE-NEXT: 0x00000008 12000000 00000000 34 .345 346#--- link-order.s347.section .a,"a",@progbits348.fill 1349 350.section .b,"a",@progbits351.fill 1352 353.section .c,"a",@progbits354.fill 1355 356.section .link_order.a,"ao",@progbits,.a357.byte 1358 359.section .link_order.b,"ao",@progbits,.b360.byte 2361 362.section .link_order.c,"ao",@progbits,.c363.byte 3364 365# RUN: llvm-mc -n -filetype=obj -triple=x86_64 link-order.s -o link-order.o366 367#--- link-order.lds368## SHF_LINK_ORDER is reordered when spilling changes relative section order.369MEMORY {370  order : ORIGIN = 0, LENGTH = 3371  potential_a : ORIGIN = 3, LENGTH = 0372  bc : ORIGIN = 3, LENGTH = 2373  actual_a : ORIGIN = 5, LENGTH = 1374}375 376SECTIONS {377  CLASS(a) { *(.a) }378  .order :  { *(.link_order.*) } > order379  .potential_a : { CLASS(a) } >potential_a380  .bc : { *(.b) *(.c) } >bc381  .actual_a : { CLASS(a) } >actual_a382}383 384# RUN: ld.lld -T link-order.lds link-order.o -o link-order385# RUN: llvm-objdump -s link-order | FileCheck %s --check-prefix=LINK-ORDER386 387# LINK-ORDER: 020301 ...{{$}}388 389#--- from-insert.lds390## A section might spill from INSERT.391SECTIONS {392  CLASS(class) { *(.two_byte_section) }393  .a : { *(.one_byte_section) }394}395SECTIONS { .b : { CLASS(class) } } INSERT AFTER .a;396SECTIONS { .c : { CLASS(class) } }397 398# RUN: not ld.lld -T from-insert.lds spill.o 2>&1 |\399# RUN:   FileCheck %s --check-prefix=FROM-INSERT400# RUN: ld.lld -T from-insert.lds spill.o -o out --noinhibit-exec 2>&1 |\401# RUN:   FileCheck %s --check-prefix=FROM-INSERT-WARN402 403# FROM-INSERT: error: section '.two_byte_section' cannot spill from/to INSERT section '.b'404# FROM-INSERT-WARN: warning: section '.two_byte_section' cannot spill from/to INSERT section '.b'405 406#--- to-insert.lds407## A section might spill to INSERT.408SECTIONS {409  CLASS(class) { *(.two_byte_section) }410  .a : { CLASS(class) *(.one_byte_section) }411}412SECTIONS { .b : { CLASS(class) } } INSERT AFTER .a;413 414# RUN: not ld.lld -T to-insert.lds spill.o 2>&1 |\415# RUN:   FileCheck %s --check-prefix=TO-INSERT416# RUN:  ld.lld -T to-insert.lds spill.o -o out --noinhibit-exec 2>&1 |\417# RUN:   FileCheck %s --check-prefix=TO-INSERT-WARN418 419# TO-INSERT: error: section '.two_byte_section' cannot spill from/to INSERT section '.b'420# TO-INSERT-WARN: warning: section '.two_byte_section' cannot spill from/to INSERT section '.b'421 422#--- from-discard.lds423## A section might spill from /DISCARD/.424SECTIONS {425  CLASS(class) { *(.two_byte_section) }426  /DISCARD/ : { CLASS(class) }427  .c : { CLASS(class) }428}429 430# RUN: not ld.lld -T from-discard.lds spill.o 2>&1 |\431# RUN:   FileCheck %s --check-prefix=FROM-DISCARD432# RUN: ld.lld -T from-discard.lds spill.o -o out --noinhibit-exec 2>&1 |\433# RUN:   FileCheck %s --check-prefix=FROM-DISCARD-WARN434 435# FROM-DISCARD: error: section '.two_byte_section' cannot spill from/to /DISCARD/436# FROM-DISCARD-WARN: warning: section '.two_byte_section' cannot spill from/to /DISCARD/437 438#--- to-discard.lds439## A section might spill to /DISCARD/.440SECTIONS {441  CLASS(class) { *(.two_byte_section) }442  .a : { CLASS(class) }443  /DISCARD/ : { CLASS(class) }444}445 446# RUN: not ld.lld -T to-discard.lds spill.o 2>&1 |\447# RUN:   FileCheck %s --check-prefix=TO-DISCARD448# RUN: ld.lld -T to-discard.lds spill.o -o out --noinhibit-exec 2>&1 |\449# RUN:   FileCheck %s --check-prefix=TO-DISCARD-WARN450 451# TO-DISCARD: error: section '.two_byte_section' cannot spill from/to /DISCARD/452# TO-DISCARD-WARN: warning: section '.two_byte_section' cannot spill from/to /DISCARD/453 454#--- same-mem-region.lds455## Spills to the same memory region that overflowed do not consume address assignment passes.456MEMORY {457  a : ORIGIN = 0, LENGTH = 0458  b : ORIGIN = 0, LENGTH = 3459  c : ORIGIN = 3, LENGTH = 3460  d : ORIGIN = 6, LENGTH = 3461}462SECTIONS {463  CLASS(class) { *(.one_byte_section .two_byte_section) }464  .a00 : { CLASS(class) } >a AT>c465  .a01 : { CLASS(class) } >a AT>d466  .a02 : { CLASS(class) } >a AT>d467  .a03 : { CLASS(class) } >a AT>d468  .a04 : { CLASS(class) } >a AT>d469  .a05 : { CLASS(class) } >a AT>d470  .a06 : { CLASS(class) } >a AT>d471  .a07 : { CLASS(class) } >a AT>d472  .a08 : { CLASS(class) } >a AT>d473  .a09 : { CLASS(class) } >a AT>d474  .a10 : { CLASS(class) } >a AT>d475  .a11 : { CLASS(class) } >a AT>d476  .a12 : { CLASS(class) } >a AT>d477  .a13 : { CLASS(class) } >a AT>d478  .a14 : { CLASS(class) } >a AT>d479  .a15 : { CLASS(class) } >a AT>d480  .a16 : { CLASS(class) } >a AT>d481  .a17 : { CLASS(class) } >a AT>d482  .a18 : { CLASS(class) } >a AT>d483  .a19 : { CLASS(class) } >a AT>d484  .a20 : { CLASS(class) } >a AT>d485  .a21 : { CLASS(class) } >a AT>d486  .a22 : { CLASS(class) } >a AT>d487  .a23 : { CLASS(class) } >a AT>d488  .a24 : { CLASS(class) } >a AT>d489  .a25 : { CLASS(class) } >a AT>d490  .a26 : { CLASS(class) } >a AT>d491  .a27 : { CLASS(class) } >a AT>d492  .a28 : { CLASS(class) } >a AT>d493  .a29 : { CLASS(class) } >a AT>d494  .a30 : { CLASS(class) } >a AT>d495  .b : { CLASS(class) } >b AT>d496}497 498# RUN: ld.lld -T same-mem-region.lds -o same-mem-region spill.o499# RUN: llvm-readelf -S same-mem-region | FileCheck %s --check-prefix=SAME-MEM-REGION500 501# SAME-MEM-REGION:      Name          Type     Address          Off    Size502# SAME-MEM-REGION:      .b PROGBITS 0000000000000000 001000 000003503 504#--- same-lma-region.lds505## Spills to the same load region that overflowed do not consume address assignment passes.506MEMORY {507  a : ORIGIN = 0, LENGTH = 0508  b : ORIGIN = 0, LENGTH = 3509  c : ORIGIN = 3, LENGTH = 3510  d : ORIGIN = 6, LENGTH = 3511}512SECTIONS {513  CLASS(class) { *(.one_byte_section .two_byte_section) }514  .a00 : { CLASS(class) } >c AT>a515  .a01 : { CLASS(class) } >d AT>a516  .a02 : { CLASS(class) } >d AT>a517  .a03 : { CLASS(class) } >d AT>a518  .a04 : { CLASS(class) } >d AT>a519  .a05 : { CLASS(class) } >d AT>a520  .a06 : { CLASS(class) } >d AT>a521  .a07 : { CLASS(class) } >d AT>a522  .a08 : { CLASS(class) } >d AT>a523  .a09 : { CLASS(class) } >d AT>a524  .a10 : { CLASS(class) } >d AT>a525  .a11 : { CLASS(class) } >d AT>a526  .a12 : { CLASS(class) } >d AT>a527  .a13 : { CLASS(class) } >d AT>a528  .a14 : { CLASS(class) } >d AT>a529  .a15 : { CLASS(class) } >d AT>a530  .a16 : { CLASS(class) } >d AT>a531  .a17 : { CLASS(class) } >d AT>a532  .a18 : { CLASS(class) } >d AT>a533  .a19 : { CLASS(class) } >d AT>a534  .a20 : { CLASS(class) } >d AT>a535  .a21 : { CLASS(class) } >d AT>a536  .a22 : { CLASS(class) } >d AT>a537  .a23 : { CLASS(class) } >d AT>a538  .a24 : { CLASS(class) } >d AT>a539  .a25 : { CLASS(class) } >d AT>a540  .a26 : { CLASS(class) } >d AT>a541  .a27 : { CLASS(class) } >d AT>a542  .a28 : { CLASS(class) } >d AT>a543  .a29 : { CLASS(class) } >d AT>a544  .a30 : { CLASS(class) } >d AT>a545  .b : { CLASS(class) } >d AT>b546}547 548# RUN: ld.lld -T same-lma-region.lds -o same-lma-region spill.o549# RUN: llvm-readelf -S same-lma-region | FileCheck %s --check-prefix=SAME-LMA-REGION550 551# SAME-LMA-REGION:      Name          Type     Address          Off    Size552# SAME-LMA-REGION:      .b PROGBITS 0000000000000006 001006 000003553