llvm.org GIT mirror llvm / 1c404b4
llvm-lto2: Add a dump-symtab subcommand. This allows us to test the symbol table APIs for LTO input files. Differential Revision: https://reviews.llvm.org/D31920 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300086 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 3 years ago
2 changed file(s) with 100 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
0 ; RUN: llvm-as -o %t %s
1 ; RUN: llvm-lto2 dump-symtab %t | FileCheck %s
2
3 target triple = "i686-pc-windows-msvc18.0.0"
4 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
5
6 ; CHECK: source filename: src.c
7 source_filename = "src.c"
8
9 ; CHECK: linker opts (COFF only): /include:foo
10 !0 = !{i32 6, !"Linker Options", !{!{!"/include:foo"}}}
11 !llvm.module.flags = !{ !0 }
12
13 ; CHECK: H------ _g1
14 @g1 = hidden global i32 0
15
16 ; CHECK: P------ _g2
17 @g2 = protected global i32 0
18
19 ; CHECK: D------ _g3
20 @g3 = global i32 0
21
22 ; CHECK: DU----- _g4
23 @g4 = external global i32
24
25 ; CHECK: D--W--- _g5
26 @g5 = weak global i32 0
27
28 ; CHECK: D--W-O- _g6
29 @g6 = linkonce_odr unnamed_addr global i32 0
30
31 ; CHECK: D-----T _g7
32 @g7 = thread_local global i32 0
33
34 ; CHECK: D-C---- _g8
35 ; CHECK-NEXT: size 4 align 8
36 @g8 = common global i32 0, align 8
37
38 ; CHECK: D------ _g9
39 ; CHECK-NEXT: comdat g9
40 $g9 = comdat any
41 @g9 = global i32 0, comdat
42
43 ; CHECK: D--WI-- _g10
44 ; CHECK-NEXT: comdat g9
45 ; CHECK-NEXT: fallback _g9
46 @g10 = weak alias i32, i32* @g9
126126 }
127127
128128 static int usage() {
129 errs() << "Available subcommands: run\n";
129 errs() << "Available subcommands: dump-symtab run\n";
130130 return 1;
131131 }
132132
286286 return 0;
287287 }
288288
289 static int dumpSymtab(int argc, char **argv) {
290 for (StringRef F : make_range(argv + 1, argv + argc)) {
291 std::unique_ptr MB = check(MemoryBuffer::getFile(F), F);
292 std::unique_ptr Input =
293 check(InputFile::create(MB->getMemBufferRef()), F);
294
295 outs() << "source filename: " << Input->getSourceFileName() << '\n';
296 outs() << "linker opts (COFF only): " << Input->getCOFFLinkerOpts() << '\n';
297
298 std::vector ComdatTable = Input->getComdatTable();
299 for (const InputFile::Symbol &Sym : Input->symbols()) {
300 switch (Sym.getVisibility()) {
301 case GlobalValue::HiddenVisibility:
302 outs() << 'H';
303 break;
304 case GlobalValue::ProtectedVisibility:
305 outs() << 'P';
306 break;
307 case GlobalValue::DefaultVisibility:
308 outs() << 'D';
309 break;
310 }
311
312 auto PrintBool = [&](char C, bool B) { outs() << (B ? C : '-'); };
313 PrintBool('U', Sym.isUndefined());
314 PrintBool('C', Sym.isCommon());
315 PrintBool('W', Sym.isWeak());
316 PrintBool('I', Sym.isIndirect());
317 PrintBool('O', Sym.canBeOmittedFromSymbolTable());
318 PrintBool('T', Sym.isTLS());
319 outs() << ' ' << Sym.getName() << '\n';
320
321 if (Sym.isCommon())
322 outs() << " size " << Sym.getCommonSize() << " align "
323 << Sym.getCommonAlignment() << '\n';
324
325 int Comdat = Sym.getComdatIndex();
326 if (Comdat != -1)
327 outs() << " comdat " << ComdatTable[Comdat] << '\n';
328
329 if (Sym.isWeak() && Sym.isIndirect())
330 outs() << " fallback " << Sym.getCOFFWeakExternalFallback() << '\n';
331 }
332
333 outs() << '\n';
334 }
335
336 return 0;
337 }
338
289339 int main(int argc, char **argv) {
290340 InitializeAllTargets();
291341 InitializeAllTargetMCs();
301351 StringRef Subcommand = argv[1];
302352 // Ensure that argv[0] is correct after adjusting argv/argc.
303353 argv[1] = argv[0];
354 if (Subcommand == "dump-symtab")
355 return dumpSymtab(argc - 1, argv + 1);
304356 if (Subcommand == "run")
305357 return run(argc - 1, argv + 1);
306358 return usage();