blob: 025ced95b30ac43bd3e02739488a9cf0b0b2ce58 [file] [log] [blame]
Eugene Leviantbbe38602016-07-19 09:25:43 +00001# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
3# RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS ;} \
4# RUN: SECTIONS { \
5# RUN: . = 0x10000200; \
George Rimar215dd472016-08-10 14:02:35 +00006# RUN: .text : {*(.text*)} :all \
Eugene Leviantbbe38602016-07-19 09:25:43 +00007# RUN: .foo : {*(.foo.*)} :all \
8# RUN: .data : {*(.data.*)} :all}" > %t.script
Eugene Leviantbbe38602016-07-19 09:25:43 +00009# RUN: ld.lld -o %t1 --script %t.script %t
10# RUN: llvm-readobj -program-headers %t1 | FileCheck %s
Eugene Leviant56b21c82016-09-09 09:46:16 +000011
Eugene Leviantdb35fdf2016-10-20 09:39:09 +000012## Check that program headers are not written, unless we explicitly tell
13## lld to do this.
14# RUN: echo "PHDRS {all PT_LOAD;} \
15# RUN: SECTIONS { \
16# RUN: . = 0x10000200; \
17# RUN: /DISCARD/ : {*(.text*)} \
18# RUN: .foo : {*(.foo.*)} :all \
19# RUN: }" > %t.script
20# RUN: ld.lld -o %t1 --script %t.script %t
21# RUN: llvm-readobj -program-headers %t1 | FileCheck --check-prefix=NOPHDR %s
22
Eugene Leviant56b21c82016-09-09 09:46:16 +000023## Check the AT(expr)
24# RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS AT(0x500 + 0x500) ;} \
25# RUN: SECTIONS { \
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 -program-headers %t1 | FileCheck --check-prefix=AT %s
32
Eugene Leviantce30b1c2016-10-19 15:04:49 +000033# RUN: echo "PHDRS {all PT_LOAD FILEHDR PHDRS ;} \
34# RUN: SECTIONS { \
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 -program-headers %t1 | FileCheck --check-prefix=DEFHDR %s
41
Eugene Leviant2a942c42016-12-05 16:38:32 +000042## 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 %t1 --script %t.script %t 2>&1 | FileCheck --check-prefix=BADHDR %s
49
Eugene Leviantbbe38602016-07-19 09:25:43 +000050# 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
George Rimara14b13d2016-09-07 10:46:07 +000058# CHECK-NEXT: Flags [ (0x7)
Eugene Leviantbbe38602016-07-19 09:25:43 +000059# CHECK-NEXT: PF_R (0x4)
George Rimara14b13d2016-09-07 10:46:07 +000060# CHECK-NEXT: PF_W (0x2)
Eugene Leviantbbe38602016-07-19 09:25:43 +000061# CHECK-NEXT: PF_X (0x1)
62# CHECK-NEXT: ]
63
Eugene Leviantdb35fdf2016-10-20 09:39:09 +000064# 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)
75# NOPHDR-NEXT: ]
76# NOPHDR-NEXT: Alignment: 4096
77# NOPHDR-NEXT: }
78# NOPHDR-NEXT: ]
79
Eugene Leviant56b21c82016-09-09 09:46:16 +000080# 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)
89# AT-NEXT: PF_R (0x4)
90# AT-NEXT: PF_W (0x2)
91# AT-NEXT: PF_X (0x1)
92# AT-NEXT: ]
93
George Rimar95dd7182016-10-18 10:49:50 +000094## Check the numetic values for PHDRS.
95# RUN: echo "PHDRS {text PT_LOAD FILEHDR PHDRS; foo 0x11223344; } \
Rafael Espindola33713982017-01-05 14:20:35 +000096# RUN: SECTIONS { . = SIZEOF_HEADERS; .foo : { *(.foo* .text*) } : text : foo}" > %t1.script
George Rimar95dd7182016-10-18 10:49:50 +000097# RUN: ld.lld -o %t2 --script %t1.script %t
98# RUN: llvm-readobj -program-headers %t2 | FileCheck --check-prefix=INT-PHDRS %s
99
100# INT-PHDRS: ProgramHeaders [
101# INT-PHDRS: ProgramHeader {
102# INT-PHDRS: Type: (0x11223344)
103# INT-PHDRS-NEXT: Offset: 0xB0
104# INT-PHDRS-NEXT: VirtualAddress: 0xB0
105# INT-PHDRS-NEXT: PhysicalAddress: 0xB0
George Rimar3fb5a6d2016-11-29 16:05:27 +0000106# INT-PHDRS-NEXT: FileSize:
107# INT-PHDRS-NEXT: MemSize:
George Rimar95dd7182016-10-18 10:49:50 +0000108# INT-PHDRS-NEXT: Flags [
109# INT-PHDRS-NEXT: PF_R
110# INT-PHDRS-NEXT: PF_W
111# INT-PHDRS-NEXT: PF_X
112# INT-PHDRS-NEXT: ]
George Rimar11992c862016-11-25 08:05:41 +0000113# INT-PHDRS-NEXT: Alignment:
George Rimar95dd7182016-10-18 10:49:50 +0000114# INT-PHDRS-NEXT: }
115# INT-PHDRS-NEXT: ]
116
Eugene Leviantce30b1c2016-10-19 15:04:49 +0000117# 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)
129# DEFHDR-NEXT: ]
130
Eugene Leviant2a942c42016-12-05 16:38:32 +0000131# BADHDR: {{.*}}.script:1: section header 'bar' is not listed in PHDRS
132
Eugene Leviantbbe38602016-07-19 09:25:43 +0000133.global _start
134_start:
135 nop
136
137.section .foo.1,"a"
138foo1:
139 .long 0
140
141.section .foo.2,"aw"
142foo2:
143 .long 0