[AArch64,ELF] Restrict MOVZ/MOVK to non-PIC large code model (#70178)
[llvm-project.git] / lldb / unittests / Symbol / SymtabTest.cpp
blob7b8892e5b5c0f6dfb8e3e827889c364409a79d28
1 //===-- SymbolTest.cpp ----------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
10 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
11 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
12 #include "TestingSupport/SubsystemRAII.h"
13 #include "TestingSupport/TestUtilities.h"
15 #include "lldb/Core/DataFileCache.h"
16 #include "lldb/Core/Module.h"
17 #include "lldb/Host/FileSystem.h"
18 #include "lldb/Host/HostInfo.h"
19 #include "lldb/Symbol/Symbol.h"
20 #include "lldb/Symbol/Symtab.h"
21 #include "lldb/Utility/DataEncoder.h"
22 #include "lldb/Utility/DataExtractor.h"
24 #include <memory>
26 #include "gtest/gtest.h"
28 using namespace lldb;
29 using namespace lldb_private;
30 using namespace lldb_private::plugin::dwarf;
32 class SymtabTest : public testing::Test {
33 SubsystemRAII<FileSystem, HostInfo, ObjectFileMachO, SymbolFileDWARF,
34 TypeSystemClang>
35 subsystem;
38 static void EncodeDecode(const Symtab &object, ByteOrder byte_order) {
39 const uint8_t addr_size = 8;
40 DataEncoder file(byte_order, addr_size);
42 object.Encode(file);
43 llvm::ArrayRef<uint8_t> bytes = file.GetData();
44 DataExtractor data(bytes.data(), bytes.size(), byte_order, addr_size);
45 Symtab decoded_object(object.GetObjectFile());
46 offset_t data_offset = 0;
47 bool uuid_mismatch = false;
48 decoded_object.Decode(data, &data_offset, uuid_mismatch);
49 ASSERT_EQ(object.GetNumSymbols(), decoded_object.GetNumSymbols());
50 for (size_t i = 0; i < object.GetNumSymbols(); ++i)
51 EXPECT_EQ(*object.SymbolAtIndex(i), *decoded_object.SymbolAtIndex(i));
54 static void EncodeDecode(const Symtab &object) {
55 EncodeDecode(object, eByteOrderLittle);
56 EncodeDecode(object, eByteOrderBig);
59 TEST_F(SymtabTest, EncodeDecodeSymtab) {
61 auto ExpectedFile = TestFile::fromYaml(R"(
62 --- !mach-o
63 FileHeader:
64 magic: 0xFEEDFACF
65 cputype: 0x100000C
66 cpusubtype: 0x0
67 filetype: 0x2
68 ncmds: 17
69 sizeofcmds: 792
70 flags: 0x200085
71 reserved: 0x0
72 LoadCommands:
73 - cmd: LC_SEGMENT_64
74 cmdsize: 72
75 segname: __PAGEZERO
76 vmaddr: 0
77 vmsize: 4294967296
78 fileoff: 0
79 filesize: 0
80 maxprot: 0
81 initprot: 0
82 nsects: 0
83 flags: 0
84 - cmd: LC_SEGMENT_64
85 cmdsize: 232
86 segname: __TEXT
87 vmaddr: 4294967296
88 vmsize: 16384
89 fileoff: 0
90 filesize: 16384
91 maxprot: 5
92 initprot: 5
93 nsects: 2
94 flags: 0
95 Sections:
96 - sectname: __text
97 segname: __TEXT
98 addr: 0x100003F94
99 size: 36
100 offset: 0x3F94
101 align: 2
102 reloff: 0x0
103 nreloc: 0
104 flags: 0x80000400
105 reserved1: 0x0
106 reserved2: 0x0
107 reserved3: 0x0
108 content: FF8300D1E80300AA00008052FF1F00B9E81B00B9E10B00F9E20700F9FF830091C0035FD6
109 - sectname: __unwind_info
110 segname: __TEXT
111 addr: 0x100003FB8
112 size: 72
113 offset: 0x3FB8
114 align: 2
115 reloff: 0x0
116 nreloc: 0
117 flags: 0x0
118 reserved1: 0x0
119 reserved2: 0x0
120 reserved3: 0x0
121 content: 010000001C000000000000001C000000000000001C00000002000000943F00003400000034000000B93F00000000000034000000030000000C000100100001000000000000200002
122 - cmd: LC_SEGMENT_64
123 cmdsize: 72
124 segname: __LINKEDIT
125 vmaddr: 4294983680
126 vmsize: 16384
127 fileoff: 16384
128 filesize: 674
129 maxprot: 1
130 initprot: 1
131 nsects: 0
132 flags: 0
133 - cmd: LC_DYLD_CHAINED_FIXUPS
134 cmdsize: 16
135 dataoff: 16384
136 datasize: 56
137 - cmd: LC_DYLD_EXPORTS_TRIE
138 cmdsize: 16
139 dataoff: 16440
140 datasize: 48
141 - cmd: LC_SYMTAB
142 cmdsize: 24
143 symoff: 16496
144 nsyms: 10
145 stroff: 16656
146 strsize: 128
147 - cmd: LC_DYSYMTAB
148 cmdsize: 80
149 ilocalsym: 0
150 nlocalsym: 8
151 iextdefsym: 8
152 nextdefsym: 2
153 iundefsym: 10
154 nundefsym: 0
155 tocoff: 0
156 ntoc: 0
157 modtaboff: 0
158 nmodtab: 0
159 extrefsymoff: 0
160 nextrefsyms: 0
161 indirectsymoff: 0
162 nindirectsyms: 0
163 extreloff: 0
164 nextrel: 0
165 locreloff: 0
166 nlocrel: 0
167 - cmd: LC_LOAD_DYLINKER
168 cmdsize: 32
169 name: 12
170 Content: '/usr/lib/dyld'
171 ZeroPadBytes: 7
172 - cmd: LC_UUID
173 cmdsize: 24
174 uuid: 1EECD2B8-16EA-3FEC-AB3C-F46139DBD0E2
175 - cmd: LC_BUILD_VERSION
176 cmdsize: 32
177 platform: 1
178 minos: 786432
179 sdk: 786432
180 ntools: 1
181 Tools:
182 - tool: 3
183 version: 46596096
184 - cmd: LC_SOURCE_VERSION
185 cmdsize: 16
186 version: 0
187 - cmd: LC_MAIN
188 cmdsize: 24
189 entryoff: 16276
190 stacksize: 0
191 - cmd: LC_LOAD_DYLIB
192 cmdsize: 48
193 dylib:
194 name: 24
195 timestamp: 2
196 current_version: 78643968
197 compatibility_version: 65536
198 Content: '/usr/lib/libc++.1.dylib'
199 ZeroPadBytes: 1
200 - cmd: LC_LOAD_DYLIB
201 cmdsize: 56
202 dylib:
203 name: 24
204 timestamp: 2
205 current_version: 85917696
206 compatibility_version: 65536
207 Content: '/usr/lib/libSystem.B.dylib'
208 ZeroPadBytes: 6
209 - cmd: LC_FUNCTION_STARTS
210 cmdsize: 16
211 dataoff: 16488
212 datasize: 8
213 - cmd: LC_DATA_IN_CODE
214 cmdsize: 16
215 dataoff: 16496
216 datasize: 0
217 - cmd: LC_CODE_SIGNATURE
218 cmdsize: 16
219 dataoff: 16784
220 datasize: 274
221 LinkEditData:
222 NameList:
223 - n_strx: 28
224 n_type: 0x64
225 n_sect: 0
226 n_desc: 0
227 n_value: 0
228 - n_strx: 64
229 n_type: 0x64
230 n_sect: 0
231 n_desc: 0
232 n_value: 0
233 - n_strx: 73
234 n_type: 0x66
235 n_sect: 0
236 n_desc: 1
237 n_value: 1639532873
238 - n_strx: 1
239 n_type: 0x2E
240 n_sect: 1
241 n_desc: 0
242 n_value: 4294983572
243 - n_strx: 115
244 n_type: 0x24
245 n_sect: 1
246 n_desc: 0
247 n_value: 4294983572
248 - n_strx: 1
249 n_type: 0x24
250 n_sect: 0
251 n_desc: 0
252 n_value: 36
253 - n_strx: 1
254 n_type: 0x4E
255 n_sect: 1
256 n_desc: 0
257 n_value: 36
258 - n_strx: 1
259 n_type: 0x64
260 n_sect: 1
261 n_desc: 0
262 n_value: 0
263 - n_strx: 2
264 n_type: 0xF
265 n_sect: 1
266 n_desc: 16
267 n_value: 4294967296
268 - n_strx: 22
269 n_type: 0xF
270 n_sect: 1
271 n_desc: 0
272 n_value: 4294983572
273 StringTable:
274 - ' '
275 - __mh_execute_header
276 - _main
277 - '/Users/gclayton/Documents/src/args/'
278 - main.cpp
279 - '/Users/gclayton/Documents/src/args/main.o'
280 - _main
281 - ''
282 - ''
283 - ''
284 - ''
285 - ''
286 - ''
287 - ''
289 )");
291 ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
292 auto module_sp = std::make_shared<Module>(ExpectedFile->moduleSpec());
293 ObjectFile *objfile = module_sp->GetObjectFile();
294 ASSERT_NE(objfile, nullptr);
296 // Test encoding and decoding an empty symbol table.
297 Symtab symtab(objfile);
298 symtab.PreloadSymbols();
299 EncodeDecode(symtab);
301 // Now encode and decode an actual symbol table from our yaml.
302 Symtab *module_symtab = module_sp->GetSymtab();
303 ASSERT_NE(module_symtab, nullptr);
304 module_symtab->PreloadSymbols();
305 EncodeDecode(*module_symtab);
308 TEST_F(SymtabTest, TestDecodeCStringMaps) {
309 // Symbol tables save out the symbols, but they also save out the symbol table
310 // name indexes. These name indexes are a map of sorted ConstString + T pairs
311 // and when they are decoded from a file, they are no longer sorted since
312 // ConstString objects can be sorted by "const char *" and the order in which
313 // these strings are created won't be the same in a new process. We need to
314 // ensure these name lookups happen correctly when we load the name indexes,
315 // so this test loads a symbol table from a cache file from
316 // "lldb/unittests/Symbol/Inputs/indexnames-symtab-cache" and make sure we
317 // can correctly lookup each of the names in the symbol table.
318 auto ExpectedFile = TestFile::fromYaml(R"(
319 --- !mach-o
320 FileHeader:
321 magic: 0xFEEDFACF
322 cputype: 0x100000C
323 cpusubtype: 0x0
324 filetype: 0x2
325 ncmds: 16
326 sizeofcmds: 744
327 flags: 0x200085
328 reserved: 0x0
329 LoadCommands:
330 - cmd: LC_SEGMENT_64
331 cmdsize: 72
332 segname: __PAGEZERO
333 vmaddr: 0
334 vmsize: 4294967296
335 fileoff: 0
336 filesize: 0
337 maxprot: 0
338 initprot: 0
339 nsects: 0
340 flags: 0
341 - cmd: LC_SEGMENT_64
342 cmdsize: 232
343 segname: __TEXT
344 vmaddr: 4294967296
345 vmsize: 16384
346 fileoff: 0
347 filesize: 16384
348 maxprot: 5
349 initprot: 5
350 nsects: 2
351 flags: 0
352 Sections:
353 - sectname: __text
354 segname: __TEXT
355 addr: 0x100003F64
356 size: 76
357 offset: 0x3F64
358 align: 2
359 reloff: 0x0
360 nreloc: 0
361 flags: 0x80000400
362 reserved1: 0x0
363 reserved2: 0x0
364 reserved3: 0x0
365 content: 80018052C0035FD6E0028052C0035FD640048052C0035FD6FF8300D1FD7B01A9FD43009108008052E80B00B9BFC31FB8F4FFFF97F5FFFF97F6FFFF97E00B40B9FD7B41A9FF830091C0035FD6
366 - sectname: __unwind_info
367 segname: __TEXT
368 addr: 0x100003FB0
369 size: 80
370 offset: 0x3FB0
371 align: 2
372 reloff: 0x0
373 nreloc: 0
374 flags: 0x0
375 reserved1: 0x0
376 reserved2: 0x0
377 reserved3: 0x0
378 content: 010000001C000000000000001C000000000000001C00000002000000643F00003400000034000000B13F00000000000034000000030000000C0002001400020000000001180000000000000400000002
379 - cmd: LC_SEGMENT_64
380 cmdsize: 72
381 segname: __LINKEDIT
382 vmaddr: 4294983680
383 vmsize: 16384
384 fileoff: 16384
385 filesize: 994
386 maxprot: 1
387 initprot: 1
388 nsects: 0
389 flags: 0
390 - cmd: LC_DYLD_CHAINED_FIXUPS
391 cmdsize: 16
392 dataoff: 16384
393 datasize: 56
394 - cmd: LC_DYLD_EXPORTS_TRIE
395 cmdsize: 16
396 dataoff: 16440
397 datasize: 80
398 - cmd: LC_SYMTAB
399 cmdsize: 24
400 symoff: 16528
401 nsyms: 25
402 stroff: 16928
403 strsize: 176
404 - cmd: LC_DYSYMTAB
405 cmdsize: 80
406 ilocalsym: 0
407 nlocalsym: 20
408 iextdefsym: 20
409 nextdefsym: 5
410 iundefsym: 25
411 nundefsym: 0
412 tocoff: 0
413 ntoc: 0
414 modtaboff: 0
415 nmodtab: 0
416 extrefsymoff: 0
417 nextrefsyms: 0
418 indirectsymoff: 0
419 nindirectsyms: 0
420 extreloff: 0
421 nextrel: 0
422 locreloff: 0
423 nlocrel: 0
424 - cmd: LC_LOAD_DYLINKER
425 cmdsize: 32
426 name: 12
427 Content: '/usr/lib/dyld'
428 ZeroPadBytes: 7
429 - cmd: LC_UUID
430 cmdsize: 24
431 uuid: 3E94866E-0D1A-39BD-975B-64E8F1FDBAAE
432 - cmd: LC_BUILD_VERSION
433 cmdsize: 32
434 platform: 1
435 minos: 786432
436 sdk: 787200
437 ntools: 1
438 Tools:
439 - tool: 3
440 version: 49938432
441 - cmd: LC_SOURCE_VERSION
442 cmdsize: 16
443 version: 0
444 - cmd: LC_MAIN
445 cmdsize: 24
446 entryoff: 16252
447 stacksize: 0
448 - cmd: LC_LOAD_DYLIB
449 cmdsize: 56
450 dylib:
451 name: 24
452 timestamp: 2
453 current_version: 85943299
454 compatibility_version: 65536
455 Content: '/usr/lib/libSystem.B.dylib'
456 ZeroPadBytes: 6
457 - cmd: LC_FUNCTION_STARTS
458 cmdsize: 16
459 dataoff: 16520
460 datasize: 8
461 - cmd: LC_DATA_IN_CODE
462 cmdsize: 16
463 dataoff: 16528
464 datasize: 0
465 - cmd: LC_CODE_SIGNATURE
466 cmdsize: 16
467 dataoff: 17104
468 datasize: 274
469 LinkEditData:
470 NameList:
471 - n_strx: 43
472 n_type: 0x64
473 n_sect: 0
474 n_desc: 0
475 n_value: 0
476 - n_strx: 91
477 n_type: 0x64
478 n_sect: 0
479 n_desc: 0
480 n_value: 0
481 - n_strx: 98
482 n_type: 0x66
483 n_sect: 0
484 n_desc: 1
485 n_value: 1651098491
486 - n_strx: 1
487 n_type: 0x2E
488 n_sect: 1
489 n_desc: 0
490 n_value: 4294983524
491 - n_strx: 152
492 n_type: 0x24
493 n_sect: 1
494 n_desc: 0
495 n_value: 4294983524
496 - n_strx: 1
497 n_type: 0x24
498 n_sect: 0
499 n_desc: 0
500 n_value: 8
501 - n_strx: 1
502 n_type: 0x4E
503 n_sect: 1
504 n_desc: 0
505 n_value: 8
506 - n_strx: 1
507 n_type: 0x2E
508 n_sect: 1
509 n_desc: 0
510 n_value: 4294983532
511 - n_strx: 157
512 n_type: 0x24
513 n_sect: 1
514 n_desc: 0
515 n_value: 4294983532
516 - n_strx: 1
517 n_type: 0x24
518 n_sect: 0
519 n_desc: 0
520 n_value: 8
521 - n_strx: 1
522 n_type: 0x4E
523 n_sect: 1
524 n_desc: 0
525 n_value: 8
526 - n_strx: 1
527 n_type: 0x2E
528 n_sect: 1
529 n_desc: 0
530 n_value: 4294983540
531 - n_strx: 162
532 n_type: 0x24
533 n_sect: 1
534 n_desc: 0
535 n_value: 4294983540
536 - n_strx: 1
537 n_type: 0x24
538 n_sect: 0
539 n_desc: 0
540 n_value: 8
541 - n_strx: 1
542 n_type: 0x4E
543 n_sect: 1
544 n_desc: 0
545 n_value: 8
546 - n_strx: 1
547 n_type: 0x2E
548 n_sect: 1
549 n_desc: 0
550 n_value: 4294983548
551 - n_strx: 167
552 n_type: 0x24
553 n_sect: 1
554 n_desc: 0
555 n_value: 4294983548
556 - n_strx: 1
557 n_type: 0x24
558 n_sect: 0
559 n_desc: 0
560 n_value: 52
561 - n_strx: 1
562 n_type: 0x4E
563 n_sect: 1
564 n_desc: 0
565 n_value: 52
566 - n_strx: 1
567 n_type: 0x64
568 n_sect: 1
569 n_desc: 0
570 n_value: 0
571 - n_strx: 2
572 n_type: 0xF
573 n_sect: 1
574 n_desc: 16
575 n_value: 4294967296
576 - n_strx: 22
577 n_type: 0xF
578 n_sect: 1
579 n_desc: 0
580 n_value: 4294983532
581 - n_strx: 27
582 n_type: 0xF
583 n_sect: 1
584 n_desc: 0
585 n_value: 4294983540
586 - n_strx: 32
587 n_type: 0xF
588 n_sect: 1
589 n_desc: 0
590 n_value: 4294983524
591 - n_strx: 37
592 n_type: 0xF
593 n_sect: 1
594 n_desc: 0
595 n_value: 4294983548
596 StringTable:
597 - ' '
598 - __mh_execute_header
599 - _bar
600 - _baz
601 - _foo
602 - _main
603 - '/Users/gclayton/Documents/objfiles/index-names/'
604 - main.c
605 - '/Users/gclayton/Documents/objfiles/index-names/main.o'
606 - _foo
607 - _bar
608 - _baz
609 - _main
610 - ''
611 - ''
612 - ''
613 FunctionStarts: [ 0x3F64, 0x3F6C, 0x3F74, 0x3F7C ]
615 )");
616 // This data was taken from a hex dump of the object file from the above yaml
617 // and hexdumped so we can load the cache data in this test.
618 const uint8_t symtab_cache_bytes[] = {
619 0x01, 0x10, 0x3e, 0x94, 0x86, 0x6e, 0x0d, 0x1a,
620 0x39, 0xbd, 0x97, 0x5b, 0x64, 0xe8, 0xf1, 0xfd,
621 0xba, 0xae, 0xff, 0x53, 0x54, 0x41, 0x42, 0x91,
622 0x00, 0x00, 0x00, 0x00, 0x2f, 0x55, 0x73, 0x65,
623 0x72, 0x73, 0x2f, 0x67, 0x63, 0x6c, 0x61, 0x79,
624 0x74, 0x6f, 0x6e, 0x2f, 0x44, 0x6f, 0x63, 0x75,
625 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x6f, 0x62,
626 0x6a, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x2f, 0x69,
627 0x6e, 0x64, 0x65, 0x78, 0x2d, 0x6e, 0x61, 0x6d,
628 0x65, 0x73, 0x2f, 0x6d, 0x61, 0x69, 0x6e, 0x2e,
629 0x63, 0x00, 0x2f, 0x55, 0x73, 0x65, 0x72, 0x73,
630 0x2f, 0x67, 0x63, 0x6c, 0x61, 0x79, 0x74, 0x6f,
631 0x6e, 0x2f, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65,
632 0x6e, 0x74, 0x73, 0x2f, 0x6f, 0x62, 0x6a, 0x66,
633 0x69, 0x6c, 0x65, 0x73, 0x2f, 0x69, 0x6e, 0x64,
634 0x65, 0x78, 0x2d, 0x6e, 0x61, 0x6d, 0x65, 0x73,
635 0x2f, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x6f, 0x00,
636 0x66, 0x6f, 0x6f, 0x00, 0x62, 0x61, 0x72, 0x00,
637 0x62, 0x61, 0x7a, 0x00, 0x6d, 0x61, 0x69, 0x6e,
638 0x00, 0x5f, 0x6d, 0x68, 0x5f, 0x65, 0x78, 0x65,
639 0x63, 0x75, 0x74, 0x65, 0x5f, 0x68, 0x65, 0x61,
640 0x64, 0x65, 0x72, 0x00, 0x53, 0x59, 0x4d, 0x42,
641 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
642 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x2a,
643 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
644 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
645 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
646 0x64, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
647 0x0a, 0x20, 0x01, 0x37, 0x00, 0x00, 0x00, 0x00,
648 0x7b, 0xc3, 0x69, 0x62, 0x00, 0x00, 0x00, 0x00,
649 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
650 0x01, 0x00, 0x66, 0x00, 0x04, 0x00, 0x00, 0x00,
651 0x00, 0x00, 0x02, 0x32, 0x01, 0x6d, 0x00, 0x00,
652 0x00, 0x01, 0x64, 0x3f, 0x00, 0x00, 0x01, 0x00,
653 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
654 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x08, 0x00,
655 0x00, 0x00, 0x00, 0x00, 0x02, 0x32, 0x01, 0x71,
656 0x00, 0x00, 0x00, 0x01, 0x6c, 0x3f, 0x00, 0x00,
657 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
658 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00,
659 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x32,
660 0x01, 0x75, 0x00, 0x00, 0x00, 0x01, 0x74, 0x3f,
661 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00,
662 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
663 0x0f, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
664 0x02, 0x32, 0x01, 0x79, 0x00, 0x00, 0x00, 0x01,
665 0x7c, 0x3f, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
666 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
667 0x00, 0x00, 0x0f, 0x00, 0x14, 0x00, 0x00, 0x00,
668 0x00, 0x00, 0x04, 0x12, 0x02, 0x7e, 0x00, 0x00,
669 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
670 0x00, 0x00, 0x64, 0x3f, 0x00, 0x00, 0x00, 0x00,
671 0x00, 0x00, 0x10, 0x00, 0x0f, 0x00, 0x01, 0x00,
672 0x43, 0x4d, 0x41, 0x50, 0x07, 0x00, 0x00, 0x00,
673 0x6d, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
674 0x75, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
675 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
676 0x79, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
677 0x37, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
678 0x71, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
679 0x7e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00
682 ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
683 auto module_sp = std::make_shared<Module>(ExpectedFile->moduleSpec());
684 ObjectFile *objfile = module_sp->GetObjectFile();
685 ASSERT_NE(objfile, nullptr);
687 // Test encoding and decoding an empty symbol table.
688 DataExtractor data(symtab_cache_bytes, sizeof(symtab_cache_bytes),
689 eByteOrderLittle, 8);
690 Symtab symtab(objfile);
691 offset_t data_offset = 0;
692 bool uuid_mismatch = false; // Gets set to true if signature doesn't match.
693 const bool success = symtab.Decode(data, &data_offset, uuid_mismatch);
694 ASSERT_EQ(success, true);
695 ASSERT_EQ(uuid_mismatch, false);
697 // Now make sure that name lookup works for all symbols. This indicates that
698 // the Symtab::NameToIndexMap was decoded correctly and works as expected.
699 Symbol *symbol = nullptr;
700 symbol = symtab.FindFirstSymbolWithNameAndType(ConstString("main"),
701 eSymbolTypeCode,
702 Symtab::eDebugAny,
703 Symtab::eVisibilityAny);
704 ASSERT_NE(symbol, nullptr);
705 symbol = symtab.FindFirstSymbolWithNameAndType(ConstString("foo"),
706 eSymbolTypeCode,
707 Symtab::eDebugAny,
708 Symtab::eVisibilityAny);
709 ASSERT_NE(symbol, nullptr);
710 symbol = symtab.FindFirstSymbolWithNameAndType(ConstString("bar"),
711 eSymbolTypeCode,
712 Symtab::eDebugAny,
713 Symtab::eVisibilityAny);
714 ASSERT_NE(symbol, nullptr);
715 symbol = symtab.FindFirstSymbolWithNameAndType(ConstString("baz"),
716 eSymbolTypeCode,
717 Symtab::eDebugAny,
718 Symtab::eVisibilityAny);
719 ASSERT_NE(symbol, nullptr);