Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / COFF / pdb-relative-source-lines.test
blob025495b251595f614c84c115d64e6680f9e792e5
1 Test the linker line tables on roughly the following example:
3 ==> foo.h <==
4 void bar(void);
5 inline void foo(void) {
6   bar();
8 ==> pdb_lines_1.c <==
9 #include "foo.h"
10 int main(void) {
11   foo();
12   return 42;
14 ==> pdb_lines_2.c <==
15 void bar(void) {
18 $ clang-cl -fdebug-compilation-dir . -no-canonical-prefixes -c -Z7 pdb_lines*.c
19 $ obj2yaml pdb_lines_1.obj > pdb_lines_1_relative.yaml
20 $ obj2yaml pdb_lines_2.obj > pdb_lines_2_relative.yaml
22 /pdbsourcepath: only sets the directory that relative paths are considered
23 relative to, so this test needs to pass relative paths to lld-link for:
24 1. The input obj files
25 2. The /pdb: switch
26 3. The lld-link invocation itself
27 To achieve this, put all inputs of the lld-link invocation (including lld-link
28 itself) in a temp directory that's cwd and then make sure to only use relative
29 arguments when calling ./lld-link below.
30 RUN: rm -rf %t
31 RUN: mkdir %t
32 RUN: cp lld-link %t/lld-link
33 RUN: cd %t
35 RUN: yaml2obj %S/Inputs/pdb_lines_1_relative.yaml -o %t/pdb_lines_1_relative.obj
36 RUN: yaml2obj %S/Inputs/pdb_lines_2_relative.yaml -o %t/pdb_lines_2_relative.obj
37 RUN: ./lld-link -debug "-pdbsourcepath:c:\src" -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb pdb_lines_1_relative.obj pdb_lines_2_relative.obj
38 RUN: llvm-pdbutil pdb2yaml -ipi-stream -modules -module-files -module-syms -subsections=lines,fc %t/out.pdb | FileCheck %s
39 RUN: ./lld-link -debug "-pdbsourcepath:/usr/src" -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb pdb_lines_1_relative.obj pdb_lines_2_relative.obj
40 RUN: llvm-pdbutil pdb2yaml -ipi-stream -modules -module-files -module-syms -subsections=lines,fc %t/out.pdb | FileCheck --check-prefix=POSIX %s
42 Also check without -pdbsourcepath
43 RUN: ./lld-link -debug -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb pdb_lines_1_relative.obj pdb_lines_2_relative.obj
44 RUN: llvm-pdbutil pdb2yaml -modules -module-files -module-syms -subsections=lines,fc %t/out.pdb | FileCheck --check-prefix=ABSOLUTE %s
46 Clean up copy of large binary copied into temp directory to avoid bloat.
47 RUN: rm -f ./lld-link || true
49 CHECK-LABEL:  - Module:          'c:\src\pdb_lines_1_relative.obj'
50 CHECK-NEXT:     ObjFile:         'c:\src\pdb_lines_1_relative.obj'
51 CHECK:          SourceFiles:
52 CHECK-NEXT:       - 'c:\src\pdb_lines_1.c'
53 CHECK-NEXT:       - 'c:\src\foo.h'
54 CHECK:          Subsections:
55 CHECK:                - FileName:        'c:\src\pdb_lines_1.c'
56 CHECK:                - FileName:        'c:\src\foo.h'
57 CHECK:            - !FileChecksums
58 CHECK:                - FileName:        'c:\src\pdb_lines_1.c'
59 CHECK:                - FileName:        'c:\src\foo.h'
61 CHECK-LABEL:  - Module:          'c:\src\pdb_lines_2_relative.obj'
62 CHECK-NEXT:     ObjFile:         'c:\src\pdb_lines_2_relative.obj'
63 CHECK:          SourceFiles:
64 CHECK-NEXT:       - 'c:\src\pdb_lines_2.c'
65 CHECK:          Subsections:
66 CHECK:                - FileName:        'c:\src\pdb_lines_2.c'
67 CHECK:            - !FileChecksums
68 CHECK:                - FileName:        'c:\src\pdb_lines_2.c'
70 CHECK-LABEL:  - Kind:            S_ENVBLOCK
71 CHECK-NEXT:     EnvBlockSym:     
72 CHECK-NEXT:       Entries:     
73 CHECK-NEXT:         - cwd
74 CHECK-NEXT:         - 'c:\src'
75 CHECK-NEXT:         - exe
76 CHECK-NEXT:         - 'c:\src\lld-link'
77 CHECK-NEXT:         - pdb 
78 CHECK-NEXT:         - 'c:\src\out.pdb'
79 CHECK-NEXT:         - cmd
80 CHECK-NEXT:         - '-debug -pdbsourcepath:c:\src -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb'
82 CHECK-LABEL: IpiStream:
84 CHECK:    - Kind:            LF_STRING_ID
85 CHECK-NEXT:      StringId:
86 CHECK-NEXT:        Id:              0
87 CHECK-NEXT:        String:          .
88 CHECK-NEXT:     - Kind:            LF_STRING_ID
89 CHECK-NEXT:       StringId:
90 CHECK-NEXT:         Id:              0
91 CHECK-NEXT:         String:          pdb_lines_1.c
92 CHECK-NEXT:     - Kind:            LF_STRING_ID
93 CHECK-NEXT:       StringId:
94 CHECK-NEXT:         Id:              0
95 CHECK-NEXT:         String:          'buildninjaRel\bin\clang-cl.exe'
97 POSIX-LABEL:  - Module:          '/usr/src/pdb_lines_1_relative.obj'
98 POSIX-NEXT:     ObjFile:         '/usr/src/pdb_lines_1_relative.obj'
99 POSIX:          SourceFiles:
100 POSIX-NEXT:       - '/usr/src/pdb_lines_1.c'
101 POSIX-NEXT:       - '/usr/src/foo.h'
102 POSIX:          Subsections:
103 POSIX:                - FileName:        '/usr/src/pdb_lines_1.c'
104 POSIX:                - FileName:        '/usr/src/foo.h'
105 POSIX:            - !FileChecksums
106 POSIX:                - FileName:        '/usr/src/pdb_lines_1.c'
107 POSIX:                - FileName:        '/usr/src/foo.h'
109 POSIX-LABEL:  - Module:          '/usr/src/pdb_lines_2_relative.obj'
110 POSIX-NEXT:     ObjFile:         '/usr/src/pdb_lines_2_relative.obj'
111 POSIX:          SourceFiles:
112 POSIX-NEXT:       - '/usr/src/pdb_lines_2.c'
113 POSIX:          Subsections:
114 POSIX:                - FileName:        '/usr/src/pdb_lines_2.c'
115 POSIX:            - !FileChecksums
116 POSIX:                - FileName:        '/usr/src/pdb_lines_2.c'
118 POSIX-LABEL:  - Kind:            S_ENVBLOCK
119 POSIX-NEXT:     EnvBlockSym:     
120 POSIX-NEXT:       Entries:     
121 POSIX-NEXT:         - cwd
122 POSIX-NEXT:         - '/usr/src'
123 POSIX-NEXT:         - exe
124 POSIX-NEXT:         - '/usr/src/lld-link'
125 POSIX-NEXT:         - pdb 
126 POSIX-NEXT:         - '/usr/src/out.pdb'
127 POSIX-NEXT:         - cmd
128 POSIX-NEXT:         - '-debug -pdbsourcepath:/usr/src -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb'
130 ABSOLUTE-LABEL: StringTable:
131 ABSOLUTE-NOT: {{/|\\}}.{{/|\\}}pdb_lines_1.c
133 POSIX-LABEL: IpiStream:
134 POSIX:    - Kind:            LF_STRING_ID
135 POSIX-NEXT:      StringId:
136 POSIX-NEXT:        Id:              0
137 POSIX-NEXT:        String:          .
138 POSIX-NEXT:     - Kind:            LF_STRING_ID
139 POSIX-NEXT:       StringId:
140 POSIX-NEXT:         Id:              0
141 POSIX-NEXT:         String:          pdb_lines_1.c
142 POSIX-NEXT:     - Kind:            LF_STRING_ID
143 POSIX-NEXT:       StringId:
144 POSIX-NEXT:         Id:              0
145 POSIX-NEXT:         String:          'buildninjaRel\bin\clang-cl.exe'