2 # RUN: rm -rf %t && split-file %s %t && cd %t
3 # RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
6 PHDRS
{all PT_LOAD FILEHDR PHDRS ;
}
9 .text : {*(.text*)} :all
10 .foo : {*(.foo.*)} :"all"
11 .data : {*(.data.*)} : "all"}
13 # RUN: ld.lld -o 1 -T 1.lds a.o
14 # RUN: llvm-readelf -Sl 1 | FileCheck %s
15 # CHECK: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
16 # CHECK: [ 1] .text PROGBITS 0000000010000200 000200 000001 00 AX 0 0 4
17 # CHECK-NEXT: [ 2] .foo PROGBITS 0000000010000201 000201 000008 00 WA 0 0 1
19 # CHECK: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
20 # CHECK-NEXT: LOAD 0x000000 0x0000000010000000 0x0000000010000000 0x000209 0x000209 RWE 0x1000
23 ## Check that program headers are not written, unless we explicitly tell
28 /DISCARD
/ : {*(.text*)}
29 .foo : {*(.foo.*)} :all
32 # RUN: ld.lld -o 2 -T 2.lds a.o
33 # RUN: llvm-readelf -l 2 | FileCheck --check-prefix=NOPHDR %s
34 # NOPHDR: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
35 # NOPHDR-NEXT: LOAD 0x000200 0x0000000010000200 0x0000000010000200 0x000008 0x000008 RW 0x1000
38 PHDRS
{all PT_LOAD FILEHDR PHDRS ;
}
41 .text : {*(.text*)} :all
43 .data : {*(.data.*)} }
45 # RUN: ld.lld -o 3 -T 3.lds a.o
46 # RUN: llvm-readelf -l 3 | FileCheck --check-prefix=DEFHDR %s
47 # DEFHDR: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
48 # DEFHDR-NEXT: LOAD 0x000000 0x0000000010000000 0x0000000010000000 0x000209 0x000209 RWE 0x1000
52 PHDRS
{all PT_LOAD FILEHDR PHDRS AT
(0x500 + 0x500) ;
}
55 .text : {*(.text*)} :all
56 .foo : {*(.foo.*)} :all
57 .data : {*(.data.*)} :all}
59 # RUN: ld.lld -o at -T at.lds a.o
60 # RUN: llvm-readelf -l at | FileCheck --check-prefix=AT %s
61 # AT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
62 # AT-NEXT: LOAD 0x000000 0x0000000010000000 0x0000000000000a00 0x000209 0x000209 RWE 0x1000
65 ## Check the numetic values for PHDRS.
66 PHDRS
{text PT_LOAD FILEHDR PHDRS; foo
0x11223344;
}
67 SECTIONS
{ . = SIZEOF_HEADERS; .foo : { *(.foo* .text*) } : text : foo}
69 # RUN: ld.lld -o int -T int.lds a.o
70 # RUN: llvm-readelf -l int | FileCheck --check-prefix=INT-PHDRS %s
71 # INT-PHDRS: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
72 # INT-PHDRS-NEXT: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x0000b9 0x0000b9 RWE 0x1000
73 # INT-PHDRS-NEXT: <unknown>: 0x11223344 0x0000b0 0x00000000000000b0 0x00000000000000b0 0x000009 0x000009 RWE 0x4
76 ## Check that error is reported when trying to use phdr which is not listed
77 ## inside PHDRS {} block
78 ## TODO: If script doesn't contain PHDRS {} block then default phdr is always
79 ## created and error is not reported.
80 PHDRS
{ all PT_LOAD;
}
81 SECTIONS
{ .baz : {*(.foo.*)} :bar }
83 # RUN: not ld.lld -T unspecified.lds a.o 2>&1 | FileCheck --check-prefix=UNSPECIFIED %s
84 # UNSPECIFIED: unspecified.lds:6: program header 'bar' is not listed in PHDRS
87 PHDRS
{ text PT_LOAD FOOHDR;
}
89 # RUN: not ld.lld -T foohdr.lds a.o 2>&1 | FileCheck --check-prefix=FOOHDR %s
90 # FOOHDR: error: foohdr.lds:1: unexpected header attribute: FOOHDR
93 PHDRS
{ text PT_FOO FOOHDR;
}
95 # RUN: not ld.lld -T pt_foo.lds a.o 2>&1 | FileCheck --check-prefix=PTFOO %s --strict-whitespace
96 # PTFOO:{{.*}}error: pt_foo.lds:1: invalid program header type: PT_FOO
97 # PTFOO-NEXT:>>> PHDRS { text PT_FOO FOOHDR; }
101 PHDRS
{ text PT_LOAD ;
103 # RUN: not ld.lld -T unclosed.lds a.o 2>&1 | FileCheck --check-prefix=UNCLOSED %s
104 # UNCLOSED:error: unclosed.lds:1: unexpected EOF
110 # RUN: not ld.lld -T unclosed2.lds a.o 2>&1 | FileCheck --check-prefix=UNCLOSED2 %s
111 # UNCLOSED2: error: unclosed2.lds:1: unexpected header attribute: