2 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
3 # RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS ;} \
5 # RUN: . = 0x10000200; \
6 # RUN: .text : {*(.text*)} :all \
7 # RUN: .foo : {*(.foo.*)} :all \
8 # RUN: .data : {*(.data.*)} :all}" > %t.script
9 # RUN: ld.lld -o %t1 --script %t.script %t
10 # RUN: llvm-readobj -l %t1 | FileCheck %s
12 ## Check that program headers are not written, unless we explicitly tell
14 # RUN: echo "PHDRS {all PT_LOAD;} \
16 # RUN: . = 0x10000200; \
17 # RUN: /DISCARD/ : {*(.text*)} \
18 # RUN: .foo : {*(.foo.*)} :all \
20 # RUN: ld.lld -o %t1 --script %t.script %t
21 # RUN: llvm-readobj -l %t1 | FileCheck --check-prefix=NOPHDR %s
24 # RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS AT(0x500 + 0x500) ;} \
26 # RUN: . = 0x10000200; \
27 # RUN: .text : {*(.text*)} :all \
28 # RUN: .foo : {*(.foo.*)} :all \
29 # RUN: .data : {*(.data.*)} :all}" > %t.script
30 # RUN: ld.lld -o %t1 --script %t.script %t
31 # RUN: llvm-readobj -l %t1 | FileCheck --check-prefix=AT %s
33 # RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS ;} \
35 # RUN: . = 0x10000200; \
36 # RUN: .text : {*(.text*)} :all \
37 # RUN: .foo : {*(.foo.*)} \
38 # RUN: .data : {*(.data.*)} }" > %t.script
39 # RUN: ld.lld -o %t1 --script %t.script %t
40 # RUN: llvm-readobj -l %t1 | FileCheck --check-prefix=DEFHDR %s
42 ## Check that error is reported when trying to use phdr which is not listed
43 ## inside PHDRS {} block
44 ## TODO: If script doesn't contain PHDRS {} block then default phdr is always
45 ## created and error is not reported.
46 # RUN: echo "PHDRS { all PT_LOAD; } \
47 # RUN: SECTIONS { .baz : {*(.foo.*)} :bar }" > %t.script
48 # RUN: not ld.lld -o /dev/null --script %t.script %t 2>&1 | FileCheck --check-prefix=BADHDR %s
50 # CHECK: ProgramHeaders [
51 # CHECK-NEXT: ProgramHeader {
52 # CHECK-NEXT: Type: PT_LOAD (0x1)
53 # CHECK-NEXT: Offset: 0x0
54 # CHECK-NEXT: VirtualAddress: 0x10000000
55 # CHECK-NEXT: PhysicalAddress: 0x10000000
56 # CHECK-NEXT: FileSize: 521
57 # CHECK-NEXT: MemSize: 521
58 # CHECK-NEXT: Flags [ (0x7)
59 # CHECK-NEXT: PF_R (0x4)
60 # CHECK-NEXT: PF_W (0x2)
61 # CHECK-NEXT: PF_X (0x1)
64 # NOPHDR: ProgramHeaders [
65 # NOPHDR-NEXT: ProgramHeader {
66 # NOPHDR-NEXT: Type: PT_LOAD (0x1)
67 # NOPHDR-NEXT: Offset: 0x200
68 # NOPHDR-NEXT: VirtualAddress: 0x10000200
69 # NOPHDR-NEXT: PhysicalAddress: 0x10000200
70 # NOPHDR-NEXT: FileSize: 8
71 # NOPHDR-NEXT: MemSize: 8
72 # NOPHDR-NEXT: Flags [ (0x6)
73 # NOPHDR-NEXT: PF_R (0x4)
74 # NOPHDR-NEXT: PF_W (0x2)
76 # NOPHDR-NEXT: Alignment: 4096
80 # AT: ProgramHeaders [
81 # AT-NEXT: ProgramHeader {
82 # AT-NEXT: Type: PT_LOAD (0x1)
83 # AT-NEXT: Offset: 0x0
84 # AT-NEXT: VirtualAddress: 0x10000000
85 # AT-NEXT: PhysicalAddress: 0xA00
86 # AT-NEXT: FileSize: 521
87 # AT-NEXT: MemSize: 521
88 # AT-NEXT: Flags [ (0x7)
94 ## Check the numetic values for PHDRS.
95 # RUN: echo "PHDRS {text PT_LOAD FILEHDR PHDRS; foo 0x11223344; } \
96 # RUN: SECTIONS { . = SIZEOF_HEADERS; .foo : { *(.foo* .text*) } : text : foo}" > %t1.script
97 # RUN: ld.lld -o %t2 --script %t1.script %t
98 # RUN: llvm-readobj -l %t2 | FileCheck --check-prefix=INT-PHDRS %s
100 # INT-PHDRS: ProgramHeaders [
101 # INT-PHDRS: ProgramHeader {
102 # INT-PHDRS: Type: Unknown (0x11223344)
103 # INT-PHDRS-NEXT: Offset: 0xB0
104 # INT-PHDRS-NEXT: VirtualAddress: 0xB0
105 # INT-PHDRS-NEXT: PhysicalAddress: 0xB0
106 # INT-PHDRS-NEXT: FileSize:
107 # INT-PHDRS-NEXT: MemSize:
108 # INT-PHDRS-NEXT: Flags [
109 # INT-PHDRS-NEXT: PF_R
110 # INT-PHDRS-NEXT: PF_W
111 # INT-PHDRS-NEXT: PF_X
113 # INT-PHDRS-NEXT: Alignment:
117 # DEFHDR: ProgramHeaders [
118 # DEFHDR-NEXT: ProgramHeader {
119 # DEFHDR-NEXT: Type: PT_LOAD (0x1)
120 # DEFHDR-NEXT: Offset: 0x0
121 # DEFHDR-NEXT: VirtualAddress: 0x10000000
122 # DEFHDR-NEXT: PhysicalAddress: 0x10000000
123 # DEFHDR-NEXT: FileSize: 521
124 # DEFHDR-NEXT: MemSize: 521
125 # DEFHDR-NEXT: Flags [ (0x7)
126 # DEFHDR-NEXT: PF_R (0x4)
127 # DEFHDR-NEXT: PF_W (0x2)
128 # DEFHDR-NEXT: PF_X (0x1)
131 # BADHDR: {{.*}}.script:1: program header 'bar' is not listed in PHDRS
133 # RUN: echo "PHDRS { text PT_LOAD FOOHDR; }" > %t1.script
134 # RUN: not ld.lld -o /dev/null --script %t1.script %t 2>&1 | FileCheck --check-prefix=FOOHDR %s
135 # FOOHDR: error: {{.*}}.script:1: unexpected header attribute: FOOHDR
137 # RUN: echo "PHDRS { text PT_FOO FOOHDR; }" > %t1.script
138 # RUN: not ld.lld -o /dev/null --script %t1.script %t 2>&1 | FileCheck --check-prefix=PTFOO %s
139 # PTFOO: invalid program header type: PT_FOO