phdrs.s
5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS ;} \
# RUN: SECTIONS { \
# RUN: . = 0x10000200; \
# RUN: .text : {*(.text*)} :all \
# RUN: .foo : {*(.foo.*)} :all \
# RUN: .data : {*(.data.*)} :all}" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t
# RUN: llvm-readobj -l %t1 | FileCheck %s
## Check that program headers are not written, unless we explicitly tell
## lld to do this.
# RUN: echo "PHDRS {all PT_LOAD;} \
# RUN: SECTIONS { \
# RUN: . = 0x10000200; \
# RUN: /DISCARD/ : {*(.text*)} \
# RUN: .foo : {*(.foo.*)} :all \
# RUN: }" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t
# RUN: llvm-readobj -l %t1 | FileCheck --check-prefix=NOPHDR %s
## Check the AT(expr)
# RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS AT(0x500 + 0x500) ;} \
# RUN: SECTIONS { \
# RUN: . = 0x10000200; \
# RUN: .text : {*(.text*)} :all \
# RUN: .foo : {*(.foo.*)} :all \
# RUN: .data : {*(.data.*)} :all}" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t
# RUN: llvm-readobj -l %t1 | FileCheck --check-prefix=AT %s
# RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS ;} \
# RUN: SECTIONS { \
# RUN: . = 0x10000200; \
# RUN: .text : {*(.text*)} :all \
# RUN: .foo : {*(.foo.*)} \
# RUN: .data : {*(.data.*)} }" > %t.script
# RUN: ld.lld -o %t1 --script %t.script %t
# RUN: llvm-readobj -l %t1 | FileCheck --check-prefix=DEFHDR %s
## Check that error is reported when trying to use phdr which is not listed
## inside PHDRS {} block
## TODO: If script doesn't contain PHDRS {} block then default phdr is always
## created and error is not reported.
# RUN: echo "PHDRS { all PT_LOAD; } \
# RUN: SECTIONS { .baz : {*(.foo.*)} :bar }" > %t.script
# RUN: not ld.lld -o %t1 --script %t.script %t 2>&1 | FileCheck --check-prefix=BADHDR %s
# CHECK: ProgramHeaders [
# CHECK-NEXT: ProgramHeader {
# CHECK-NEXT: Type: PT_LOAD (0x1)
# CHECK-NEXT: Offset: 0x0
# CHECK-NEXT: VirtualAddress: 0x10000000
# CHECK-NEXT: PhysicalAddress: 0x10000000
# CHECK-NEXT: FileSize: 521
# CHECK-NEXT: MemSize: 521
# CHECK-NEXT: Flags [ (0x7)
# CHECK-NEXT: PF_R (0x4)
# CHECK-NEXT: PF_W (0x2)
# CHECK-NEXT: PF_X (0x1)
# CHECK-NEXT: ]
# NOPHDR: ProgramHeaders [
# NOPHDR-NEXT: ProgramHeader {
# NOPHDR-NEXT: Type: PT_LOAD (0x1)
# NOPHDR-NEXT: Offset: 0x200
# NOPHDR-NEXT: VirtualAddress: 0x10000200
# NOPHDR-NEXT: PhysicalAddress: 0x10000200
# NOPHDR-NEXT: FileSize: 8
# NOPHDR-NEXT: MemSize: 8
# NOPHDR-NEXT: Flags [ (0x6)
# NOPHDR-NEXT: PF_R (0x4)
# NOPHDR-NEXT: PF_W (0x2)
# NOPHDR-NEXT: ]
# NOPHDR-NEXT: Alignment: 4096
# NOPHDR-NEXT: }
# NOPHDR-NEXT: ]
# AT: ProgramHeaders [
# AT-NEXT: ProgramHeader {
# AT-NEXT: Type: PT_LOAD (0x1)
# AT-NEXT: Offset: 0x0
# AT-NEXT: VirtualAddress: 0x10000000
# AT-NEXT: PhysicalAddress: 0xA00
# AT-NEXT: FileSize: 521
# AT-NEXT: MemSize: 521
# AT-NEXT: Flags [ (0x7)
# AT-NEXT: PF_R (0x4)
# AT-NEXT: PF_W (0x2)
# AT-NEXT: PF_X (0x1)
# AT-NEXT: ]
## Check the numetic values for PHDRS.
# RUN: echo "PHDRS {text PT_LOAD FILEHDR PHDRS; foo 0x11223344; } \
# RUN: SECTIONS { . = SIZEOF_HEADERS; .foo : { *(.foo* .text*) } : text : foo}" > %t1.script
# RUN: ld.lld -o %t2 --script %t1.script %t
# RUN: llvm-readobj -l %t2 | FileCheck --check-prefix=INT-PHDRS %s
# INT-PHDRS: ProgramHeaders [
# INT-PHDRS: ProgramHeader {
# INT-PHDRS: Type: (0x11223344)
# INT-PHDRS-NEXT: Offset: 0xB0
# INT-PHDRS-NEXT: VirtualAddress: 0xB0
# INT-PHDRS-NEXT: PhysicalAddress: 0xB0
# INT-PHDRS-NEXT: FileSize:
# INT-PHDRS-NEXT: MemSize:
# INT-PHDRS-NEXT: Flags [
# INT-PHDRS-NEXT: PF_R
# INT-PHDRS-NEXT: PF_W
# INT-PHDRS-NEXT: PF_X
# INT-PHDRS-NEXT: ]
# INT-PHDRS-NEXT: Alignment:
# INT-PHDRS-NEXT: }
# INT-PHDRS-NEXT: ]
# DEFHDR: ProgramHeaders [
# DEFHDR-NEXT: ProgramHeader {
# DEFHDR-NEXT: Type: PT_LOAD (0x1)
# DEFHDR-NEXT: Offset: 0x0
# DEFHDR-NEXT: VirtualAddress: 0x10000000
# DEFHDR-NEXT: PhysicalAddress: 0x10000000
# DEFHDR-NEXT: FileSize: 521
# DEFHDR-NEXT: MemSize: 521
# DEFHDR-NEXT: Flags [ (0x7)
# DEFHDR-NEXT: PF_R (0x4)
# DEFHDR-NEXT: PF_W (0x2)
# DEFHDR-NEXT: PF_X (0x1)
# DEFHDR-NEXT: ]
# BADHDR: {{.*}}.script:1: section header 'bar' is not listed in PHDRS
# RUN: echo "PHDRS { text PT_LOAD FOOHDR; }" > %t1.script
# RUN: not ld.lld -o /dev/null --script %t1.script %t 2>&1 | FileCheck --check-prefix=FOOHDR %s
# FOOHDR: error: {{.*}}.script:1: unexpected header attribute: FOOHDR
# RUN: echo "PHDRS { text PT_FOO FOOHDR; }" > %t1.script
# RUN: not ld.lld -o /dev/null --script %t1.script %t 2>&1 | FileCheck --check-prefix=PTFOO %s
# PTFOO: invalid program header type: PT_FOO
.global _start
_start:
nop
.section .foo.1,"a"
foo1:
.long 0
.section .foo.2,"aw"
foo2:
.long 0