aboutsummaryrefslogtreecommitdiff
path: root/test/elf/wrap.test
blob: 997439f8f5b4f24411be2bc400674e16a111cc1e (plain) (blame)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# This tests the functionality of using the --wrap option.
# The test case is extracted by compiling and linking the following code.
#
#cat > main.c << \!
#int main() {
#  foo();
#  return 0;
#}
#!
#
#cat > wrapfoo.c << \!
#int __wrap_foo() {
#  __real_foo();
#  return 0;
#}
#!
#
#cat > realfoo.c << \!
#int foo() {
#  return 0;
#}
#!
#
#clang main.c wrapfoo.c realfoo.c -Xlinker --wrap -Xlinker foo
#RUN: yaml2obj -format=elf -docnum 1 %s -o %t.main.o
#RUN: yaml2obj -format=elf -docnum 2 %s -o %t.wrapfoo.o
#RUN: yaml2obj -format=elf -docnum 3 %s -o %t.realfoo.o
#RUN: lld -flavor gnu -target x86_64 %t.main.o %t.wrapfoo.o %t.realfoo.o \
#RUN: --wrap foo --wrap foo --noinhibit-exec --output-filetype=yaml -o %t2.out
#RUN: lld -flavor gnu -target x86_64 %t.main.o %t.wrapfoo.o  \
#RUN: --wrap foo --wrap foo --noinhibit-exec --output-filetype=yaml -o %t2.out.undef 2>&1 |  \
#RUN: FileCheck %s -check-prefix=CHECKUNDEF
#CHECKWRAP:  - name:            main
#CHECKWRAP:    references:
#CHECKWRAP:      - kind:            R_X86_64_PC32
#CHECKWRAP:        target:          __wrap_foo
#CHECKWRAP:  - name:            __wrap_foo
#CHECKWRAP:    references:
#CHECKWRAP:      - kind:            R_X86_64_PC32
#CHECKWRAP:        target:          foo
#CHECKUNDEF: Undefined symbol: {{.*}}main.o: foo
---
FileHeader:
  Class:           ELFCLASS64
  Data:            ELFDATA2LSB
  OSABI:           ELFOSABI_GNU
  Type:            ET_REL
  Machine:         EM_X86_64
Sections:
  - Name:            .text
    Type:            SHT_PROGBITS
    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
    AddressAlign:    0x0000000000000010
    Content:         5031C0E80000000031C05AC3
  - Name:            .rela.text
    Type:            SHT_RELA
    Link:            .symtab
    AddressAlign:    0x0000000000000008
    Info:            .text
    Relocations:
      - Offset:          0x0000000000000004
        Symbol:          foo
        Type:            R_X86_64_PC32
        Addend:          -4
  - Name:            .data
    Type:            SHT_PROGBITS
    Flags:           [ SHF_WRITE, SHF_ALLOC ]
    AddressAlign:    0x0000000000000004
    Content:         ''
  - Name:            .bss
    Type:            SHT_NOBITS
    Flags:           [ SHF_WRITE, SHF_ALLOC ]
    AddressAlign:    0x0000000000000004
    Content:         ''
  - Name:            .comment
    Type:            SHT_PROGBITS
    Flags:           [ SHF_MERGE, SHF_STRINGS ]
    AddressAlign:    0x0000000000000001
    Content:         00636C616E672076657273696F6E20332E372E3020287472756E6B203232383733392920286C6C766D2F7472756E6B203232383734382900
  - Name:            .note.GNU-stack
    Type:            SHT_PROGBITS
    AddressAlign:    0x0000000000000001
    Content:         ''
  - Name:            .eh_frame
    Type:            SHT_PROGBITS
    Flags:           [ SHF_ALLOC ]
    AddressAlign:    0x0000000000000008
    Content:         1400000000000000037A5200017810011B0C070890010000140000001C000000000000000C00000000410E1000000000
  - Name:            .rela.eh_frame
    Type:            SHT_RELA
    Link:            .symtab
    AddressAlign:    0x0000000000000008
    Info:            .eh_frame
    Relocations:
      - Offset:          0x0000000000000020
        Symbol:          .text
        Type:            R_X86_64_PC32
Symbols:
  Local:
    - Name:            .text
      Type:            STT_SECTION
      Section:         .text
    - Name:            .data
      Type:            STT_SECTION
      Section:         .data
    - Name:            .bss
      Type:            STT_SECTION
      Section:         .bss
    - Name:            .comment
      Type:            STT_SECTION
      Section:         .comment
    - Name:            .note.GNU-stack
      Type:            STT_SECTION
      Section:         .note.GNU-stack
    - Name:            .eh_frame
      Type:            STT_SECTION
      Section:         .eh_frame
  Global:
    - Name:            main
      Type:            STT_FUNC
      Section:         .text
      Size:            0x000000000000000C
    - Name:            foo
...
---
FileHeader:
  Class:           ELFCLASS64
  Data:            ELFDATA2LSB
  OSABI:           ELFOSABI_GNU
  Type:            ET_REL
  Machine:         EM_X86_64
Sections:
  - Name:            .text
    Type:            SHT_PROGBITS
    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
    AddressAlign:    0x0000000000000010
    Content:         5031C0E80000000031C05AC3
  - Name:            .rela.text
    Type:            SHT_RELA
    Link:            .symtab
    AddressAlign:    0x0000000000000008
    Info:            .text
    Relocations:
      - Offset:          0x0000000000000004
        Symbol:          __real_foo
        Type:            R_X86_64_PC32
        Addend:          -4
  - Name:            .data
    Type:            SHT_PROGBITS
    Flags:           [ SHF_WRITE, SHF_ALLOC ]
    AddressAlign:    0x0000000000000004
    Content:         ''
  - Name:            .bss
    Type:            SHT_NOBITS
    Flags:           [ SHF_WRITE, SHF_ALLOC ]
    AddressAlign:    0x0000000000000004
    Content:         ''
  - Name:            .comment
    Type:            SHT_PROGBITS
    Flags:           [ SHF_MERGE, SHF_STRINGS ]
    AddressAlign:    0x0000000000000001
    Content:         00636C616E672076657273696F6E20332E372E3020287472756E6B203232383733392920286C6C766D2F7472756E6B203232383734382900
  - Name:            .note.GNU-stack
    Type:            SHT_PROGBITS
    AddressAlign:    0x0000000000000001
    Content:         ''
  - Name:            .eh_frame
    Type:            SHT_PROGBITS
    Flags:           [ SHF_ALLOC ]
    AddressAlign:    0x0000000000000008
    Content:         1400000000000000037A5200017810011B0C070890010000140000001C000000000000000C00000000410E1000000000
  - Name:            .rela.eh_frame
    Type:            SHT_RELA
    Link:            .symtab
    AddressAlign:    0x0000000000000008
    Info:            .eh_frame
    Relocations:
      - Offset:          0x0000000000000020
        Symbol:          .text
        Type:            R_X86_64_PC32
Symbols:
  Local:
    - Name:            .text
      Type:            STT_SECTION
      Section:         .text
    - Name:            .data
      Type:            STT_SECTION
      Section:         .data
    - Name:            .bss
      Type:            STT_SECTION
      Section:         .bss
    - Name:            .comment
      Type:            STT_SECTION
      Section:         .comment
    - Name:            .note.GNU-stack
      Type:            STT_SECTION
      Section:         .note.GNU-stack
    - Name:            .eh_frame
      Type:            STT_SECTION
      Section:         .eh_frame
  Global:
    - Name:            __wrap_foo
      Type:            STT_FUNC
      Section:         .text
      Size:            0x000000000000000C
    - Name:            __real_foo
...
---
FileHeader:
  Class:           ELFCLASS64
  Data:            ELFDATA2LSB
  OSABI:           ELFOSABI_GNU
  Type:            ET_REL
  Machine:         EM_X86_64
Sections:
  - Name:            .text
    Type:            SHT_PROGBITS
    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
    AddressAlign:    0x0000000000000010
    Content:         31C0C3
  - Name:            .data
    Type:            SHT_PROGBITS
    Flags:           [ SHF_WRITE, SHF_ALLOC ]
    AddressAlign:    0x0000000000000004
    Content:         ''
  - Name:            .bss
    Type:            SHT_NOBITS
    Flags:           [ SHF_WRITE, SHF_ALLOC ]
    AddressAlign:    0x0000000000000004
    Content:         ''
  - Name:            .comment
    Type:            SHT_PROGBITS
    Flags:           [ SHF_MERGE, SHF_STRINGS ]
    AddressAlign:    0x0000000000000001
    Content:         00636C616E672076657273696F6E20332E372E3020287472756E6B203232383733392920286C6C766D2F7472756E6B203232383734382900
  - Name:            .note.GNU-stack
    Type:            SHT_PROGBITS
    AddressAlign:    0x0000000000000001
    Content:         ''
  - Name:            .eh_frame
    Type:            SHT_PROGBITS
    Flags:           [ SHF_ALLOC ]
    AddressAlign:    0x0000000000000008
    Content:         1400000000000000037A5200017810011B0C070890010000140000001C00000000000000030000000000000000000000
  - Name:            .rela.eh_frame
    Type:            SHT_RELA
    Link:            .symtab
    AddressAlign:    0x0000000000000008
    Info:            .eh_frame
    Relocations:
      - Offset:          0x0000000000000020
        Symbol:          .text
        Type:            R_X86_64_PC32
Symbols:
  Local:
    - Name:            .text
      Type:            STT_SECTION
      Section:         .text
    - Name:            .data
      Type:            STT_SECTION
      Section:         .data
    - Name:            .bss
      Type:            STT_SECTION
      Section:         .bss
    - Name:            .comment
      Type:            STT_SECTION
      Section:         .comment
    - Name:            .note.GNU-stack
      Type:            STT_SECTION
      Section:         .note.GNU-stack
    - Name:            .eh_frame
      Type:            STT_SECTION
      Section:         .eh_frame
  Global:
    - Name:            foo
      Type:            STT_FUNC
      Section:         .text
      Size:            0x0000000000000003
...