1## Show that llvm-readobj/llvm-readelf tools can dump the .dynamic section which
2## is not alone in PT_DYNAMIC segment.
3
4## In the first case .text is placed before .dynamic.
5## We check that we warn about this case.
6
7# RUN: yaml2obj --docnum=1 %s -o %t1.o
8# RUN: llvm-readobj --dynamic-table %t1.o 2>&1 \
9# RUN:   | FileCheck %s --DFILE=%t1.o --check-prefixes=WARNING,LLVM
10# RUN: llvm-readelf --dynamic-table %t1.o 2>&1 \
11# RUN:   | FileCheck %s --DFILE=%t1.o --check-prefixes=WARNING,GNU
12
13# WARNING: warning: '[[FILE]]': SHT_DYNAMIC section with index 2 is not at the start of PT_DYNAMIC segment
14# WARNING: warning: '[[FILE]]': invalid PT_DYNAMIC size (0x21){{$}}
15# WARNING: warning: '[[FILE]]': SHT_DYNAMIC section header and PT_DYNAMIC program header disagree about the location of the dynamic table
16# WARNING: warning: '[[FILE]]': PT_DYNAMIC dynamic table is invalid: SHT_DYNAMIC will be used
17
18# LLVM:      DynamicSection [ (2 entries)
19# LLVM-NEXT:   Tag                Type     Name/Value
20# LLVM-NEXT:   0x0000000000000018 BIND_NOW 0x1
21# LLVM-NEXT:   0x0000000000000000 NULL     0x0
22# LLVM-NEXT: ]
23
24# GNU:      Dynamic section at offset 0x{{.*}} contains 2 entries:
25# GNU-NEXT:   Tag                Type       Name/Value
26# GNU-NEXT:   0x0000000000000018 (BIND_NOW) 0x1
27# GNU-NEXT:   0x0000000000000000 (NULL)     0x0
28
29--- !ELF
30FileHeader:
31  Class: ELFCLASS64
32  Data:  ELFDATA2LSB
33  Type:  ET_EXEC
34Sections:
35  - Name: .text
36    Type: SHT_PROGBITS
37    Flags: [SHF_ALLOC]
38    Address: 0x1000
39    AddressAlign: 0x100
40    Content: "00"
41  - Name: .dynamic
42    Type: SHT_DYNAMIC
43    Flags: [SHF_ALLOC]
44    Address: 0x1001
45    Entries:
46      - Tag:   DT_BIND_NOW
47        Value: 0x1
48      - Tag:   DT_NULL
49        Value: 0x0
50ProgramHeaders:
51  - Type:     PT_LOAD
52    VAddr:    0x1000
53    FirstSec: .text
54    LastSec:  .dynamic
55  - Type:     PT_DYNAMIC
56    VAddr:    0x1000
57    FirstSec: .text
58    LastSec:  .dynamic
59
60## In this case .text goes after .dynamic and we don't display any warnings,
61## though the content of the .text is used for dumping the dynamic table.
62
63# RUN: yaml2obj --docnum=2 %s -o %t2.o
64# RUN: llvm-readobj --dynamic-table %t2.o 2>&1 | FileCheck %s --check-prefix=LLVM2
65# RUN: llvm-readelf --dynamic-table %t2.o 2>&1 | FileCheck %s --check-prefix=GNU2
66
67# LLVM2:      DynamicSection [ (3 entries)
68# LLVM2-NEXT:   Tag                Type     Name/Value
69# LLVM2-NEXT:   0x0000000000000018 BIND_NOW 0x1
70# LLVM2-NEXT:   0x0000000000000018 BIND_NOW 0x2
71# LLVM2-NEXT:   0x0000000000000000 NULL     0x0
72# LLVM2-NEXT: ]
73
74# GNU2:      Dynamic section at offset 0x{{.*}} contains 3 entries:
75# GNU2-NEXT:   Tag                Type       Name/Value
76# GNU2-NEXT:   0x0000000000000018 (BIND_NOW) 0x1
77# GNU2-NEXT:   0x0000000000000018 (BIND_NOW) 0x2
78# GNU2-NEXT:   0x0000000000000000 (NULL)     0x0
79
80--- !ELF
81FileHeader:
82  Class: ELFCLASS64
83  Data:  ELFDATA2LSB
84  Type:  ET_EXEC
85Sections:
86  - Name: .dynamic
87    Type: SHT_DYNAMIC
88    Flags: [SHF_ALLOC]
89    Address: 0x1000
90    AddressAlign: 0x1000
91    Entries:
92      - Tag:   DT_BIND_NOW
93        Value: 0x1
94      - Tag:   DT_BIND_NOW
95        Value: 0x2
96  - Name: .text
97    Type: SHT_PROGBITS
98    Flags: [SHF_ALLOC]
99    Address: 0x1100
100    AddressAlign: 0x100
101    Content: "00000000000000000000000000000000"
102ProgramHeaders:
103  - Type:     PT_LOAD
104    VAddr:    0x1000
105    FirstSec: .dynamic
106    LastSec:  .text
107  - Type:     PT_DYNAMIC
108    VAddr:    0x1000
109    FirstSec: .dynamic
110    LastSec:  .text
111
112## In this case .text goes after .dynamic, but (PT_DYNAMIC segment size % dynamic entry size != 0)
113## and we have to use the information from the section header instead.
114
115# RUN: yaml2obj --docnum=3 %s -o %t3.o
116# RUN: llvm-readobj --dynamic-table %t3.o 2>&1 | FileCheck %s --DFILE=%t3.o --check-prefixes=WARNING2,LLVM3
117# RUN: llvm-readelf --dynamic-table %t3.o 2>&1 | FileCheck %s --DFILE=%t3.o --check-prefixes=WARNING2,GNU3
118
119# WARNING2: warning: '[[FILE]]': invalid PT_DYNAMIC size (0x101){{$}}
120# WARNING2: warning: '[[FILE]]': PT_DYNAMIC dynamic table is invalid: SHT_DYNAMIC will be used
121
122# LLVM3:      DynamicSection [ (2 entries)
123# LLVM3-NEXT:   Tag                Type     Name/Value
124# LLVM3-NEXT:   0x0000000000000018 BIND_NOW 0x1
125# LLVM3-NEXT:   0x0000000000000000 NULL     0x0
126# LLVM3-NEXT: ]
127
128# GNU3:      Dynamic section at offset 0x{{.*}} contains 2 entries:
129# GNU3-NEXT:   Tag                Type       Name/Value
130# GNU3-NEXT:   0x0000000000000018 (BIND_NOW) 0x1
131# GNU3-NEXT:   0x0000000000000000 (NULL)     0x0
132
133--- !ELF
134FileHeader:
135  Class: ELFCLASS64
136  Data:  ELFDATA2LSB
137  Type:  ET_EXEC
138Sections:
139  - Name: .dynamic
140    Type: SHT_DYNAMIC
141    Flags: [SHF_ALLOC]
142    Address: 0x1000
143    AddressAlign: 0x1000
144    Entries:
145      - Tag:   DT_BIND_NOW
146        Value: 0x1
147      - Tag:   DT_NULL
148        Value: 0x0
149  - Name: .text
150    Type: SHT_PROGBITS
151    Flags: [SHF_ALLOC]
152    Address: 0x1100
153    AddressAlign: 0x100
154    Content: "00"
155ProgramHeaders:
156  - Type:     PT_LOAD
157    VAddr:    0x1000
158    FirstSec: .dynamic
159    LastSec:  .text
160  - Type:     PT_DYNAMIC
161    VAddr:    0x1000
162    FirstSec: .dynamic
163    LastSec:  .text
164