144 lines · plain
1# REQUIRES: x862# RUN: rm -rf %t && split-file %s %t && cd %t3# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o4# RUN: ld.lld a.o -T a.t -o a5 6## Here we check that can handle OVERLAY which will produce sections7## .out.big and .out.small with the same starting VAs, but different LMAs.8## Section .big is larger than .small, we check that placing of section9## .text does not cause overlapping error and that10## .text's VA is 0x1000 + max(sizeof(.out.big), sizeof(.out.small)).11 12# RUN: llvm-readelf --sections -l a | FileCheck %s13 14# CHECK: Name Type Address Off Size15# CHECK: .big1 PROGBITS 0000000000001000 001000 00000816# CHECK-NEXT: .small1 PROGBITS 0000000000001000 002000 00000417# CHECK-NEXT: .small2 PROGBITS 0000000000001008 002008 00000418# CHECK-NEXT: .big2 PROGBITS 0000000000001008 003008 00000819# CHECK-NEXT: .empty3 PROGBITS 0000000000001010 003010 00000020# CHECK-NEXT: .small3 PROGBITS 0000000000001010 003010 00000421# CHECK-NEXT: .big3 PROGBITS 0000000000001010 004010 00000822# CHECK-NEXT: .text PROGBITS 0000000000001018 004018 00000123 24# CHECK: Program Headers:25# CHECK: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align26# CHECK-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000001000 0x000008 0x000008 R 0x100027# CHECK-NEXT: LOAD 0x002000 0x0000000000001000 0x0000000000001008 0x000004 0x000004 R 0x100028# CHECK-NEXT: LOAD 0x002008 0x0000000000001008 0x0000000000002008 0x000004 0x000004 R 0x100029# CHECK-NEXT: LOAD 0x003008 0x0000000000001008 0x000000000000200c 0x000008 0x000008 R 0x100030# CHECK-NEXT: LOAD 0x003010 0x0000000000001010 0x0000000000002014 0x000004 0x000004 R 0x100031# CHECK-NEXT: LOAD 0x004010 0x0000000000001010 0x0000000000002018 0x000008 0x000008 R 0x100032# CHECK-NEXT: LOAD 0x004018 0x0000000000001018 0x0000000000002020 0x000001 0x000001 R E 0x100033 34# RUN: not ld.lld a.o -T err1.t 2>&1 | FileCheck %s --check-prefix=ERR1 --match-full-lines --strict-whitespace35# ERR1:{{.*}}error: err1.t:3: { expected, but got 0x300036# ERR1-NEXT:>>> .out.aaa 0x3000 : { *(.aaa) }37# ERR1-NEXT:>>> ^38 39# RUN: not ld.lld a.o -T err2.t 2>&1 | FileCheck %s --check-prefix=ERR2 --match-full-lines --strict-whitespace40# ERR2:{{.*}}error: err2.t:{{.*}}: { expected, but got AX41# ERR2-NEXT:>>> .out.aaa { *(.aaa) } > AX AT>FLASH42# ERR2-NEXT:>>> ^43 44# RUN: ld.lld a.o -T region.t -o region45# RUN: llvm-readelf --sections -l region | FileCheck --check-prefix=REGION %s46 47# REGION: Name Type Address Off Size48# REGION: .big1 PROGBITS 0000000000001000 001000 00000849# REGION-NEXT: .small1 PROGBITS 0000000000001000 002000 00000450# REGION: .big2 PROGBITS 0000000000001008 002008 00000851# REGION-NEXT: .small2 PROGBITS 0000000000001008 003008 00000452# REGION-NEXT: .text PROGBITS 0000000000001010 003010 00000153 54# REGION: Program Headers:55# REGION: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align56# REGION-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000001000 0x000008 0x000008 R 0x100057# REGION-NEXT: LOAD 0x002000 0x0000000000001000 0x0000000000001008 0x000010 0x000010 R 0x100058# REGION-NEXT: LOAD 0x003008 0x0000000000001008 0x0000000000001018 0x000004 0x000004 R 0x100059# REGION-NEXT: LOAD 0x003010 0x0000000000001010 0x0000000000001020 0x000001 0x000001 R E 0x100060 61#--- a.s62.globl _start63_start:64 nop65 66.section .small1, "a"; .long 067.section .big1, "a"; .quad 168 69.section .small2, "a"; .long 070.section .big2, "a"; .quad 171 72.section .small3, "a"; .long 073.section .big3, "a"; .quad 174 75#--- a.t76SECTIONS {77## LMA defaults to VMA78 OVERLAY 0x1000 : {79 ".big1" { *(".big1") }80 .small1 { *(.small1) }81 }82## .big2 starts at ADDR(.small2)83 OVERLAY : AT (0x2008) {84 .small2 { *(.small2) }85 ".big2" { *(.big2) }86 }87## .empty3 is not discarded. .small3 and .big3 share its address.88 OVERLAY . : AT (0x2014) {89 .empty3 { *(.empty3) }90 .small3 { *(.small3) }91 .big3 { *(.big3) }92 }93 .text : { *(.text) }94}95 96#--- region.t97MEMORY { region : ORIGIN = 0x1000, LENGTH = 0x1000 }98SECTIONS {99## Memory region instead of explicit address.100 OVERLAY : {101 .big1 { *(.big1) }102 .small1 { *(.small1) }103 } >region104 OVERLAY : {105 .big2 { *(.big2) }106 .small2 { *(.small2) }107 } >region108 .text : { *(.text) } >region109 /DISCARD/ : { *(.big* .small*) }110}111 112#--- err1.t113SECTIONS {114 OVERLAY 0x1000 : AT ( 0x2000 ) {115 .out.aaa 0x3000 : { *(.aaa) }116 }117}118 119#--- err2.t120MEMORY {121 AX (ax) : ORIGIN = 0x3000, LENGTH = 0x4000122}123SECTIONS {124 OVERLAY 0x1000 : AT ( 0x2000 ) {125 .out.aaa { *(.aaa) } > AX AT>FLASH126 }127}128 129#--- unclosed.lds130SECTIONS {131 OVERLAY 0x1000 : AT ( 0x2000 ) {132 133# RUN: not ld.lld a.o -T unclosed.lds 2>&1 | FileCheck %s --check-prefix=UNCLOSED134# UNCLOSED: error: unclosed.lds:2: unexpected EOF135# UNCLOSED-NOT: {{.}}136 137#--- at-nocrossrefs-order.lds138SECTIONS { OVERLAY 0x1000 : AT(0x1234) NOCROSSREFS {} }139 140# RUN: not ld.lld a.o -T at-nocrossrefs-order.lds 2>&1 | FileCheck %s --check-prefix=AT-NOCROSSREFS-ORDER --strict-whitespace141# AT-NOCROSSREFS-ORDER:{{.*}}error: at-nocrossrefs-order.lds:1: { expected, but got NOCROSSREFS142# AT-NOCROSSREFS-ORDER-NEXT:>>> SECTIONS { OVERLAY 0x1000 : AT(0x1234) NOCROSSREFS {} }143# AT-NOCROSSREFS-ORDER-NEXT:>>> ^144