1Consider this example program with an inline function "foo": 2 3==> foo.h <== 4extern int global; 5__inline void foo() { 6 ++global; 7} 8void bar(); 9==> pdb_comdat_main.c <== 10#include "foo.h" 11int main(void) { 12 foo(); 13 bar(); 14 return 42; 15} 16==> pdb_comdat_bar.c <== 17#include "foo.h" 18void bar(void) { 19 foo(); 20} 21 22Both object files will contain debug info for foo, but only the debug info from 23pdb_comdat_main.obj should be included in the PDB. 24 25RUN: rm -rf %t && mkdir -p %t && cd %t 26RUN: yaml2obj %S/Inputs/pdb_comdat_main.yaml -o pdb_comdat_main.obj 27RUN: yaml2obj %S/Inputs/pdb_comdat_bar.yaml -o pdb_comdat_bar.obj 28RUN: lld-link pdb_comdat_main.obj pdb_comdat_bar.obj -out:%t.exe -debug -pdb:%t.pdb -nodefaultlib -entry:main 29RUN: llvm-pdbutil dump -l -symbols -globals %t.pdb | FileCheck %s 30 31CHECK: Lines 32CHECK: ============================================================ 33CHECK-LABEL: Mod 0000 | `{{.*}}pdb_comdat_main.obj`: 34CHECK: c:\src\llvm-project\build\pdb_comdat_main.c (MD5: F969E51BBE373436D81492EB61387F36) 35CHECK: c:\src\llvm-project\build\foo.h (MD5: D74D834EFAC3AE2B45E606A8320B1D5C) 36CHECK-LABEL: Mod 0001 | `{{.*}}pdb_comdat_bar.obj`: 37CHECK: c:\src\llvm-project\build\pdb_comdat_bar.c (MD5: 365279DB4FCBEDD721BBFC3B14A953C2) 38CHECK-NOT: c:\src\llvm-project\build\foo.h 39CHECK-LABEL: Mod 0002 | `* Linker *`: 40 41CHECK-LABEL: Global Symbols 42CHECK-NEXT: ============================================================ 43CHECK-NEXT: Records 44CHECK-NEXT: 84 | S_PROCREF [size = 20] `main` 45CHECK-NEXT: module = 1, sum name = 0, offset = 120 46CHECK-NEXT: 148 | S_PROCREF [size = 20] `bar` 47CHECK-NEXT: module = 2, sum name = 0, offset = 120 48CHECK-NEXT: 128 | S_PROCREF [size = 20] `foo` 49CHECK-NEXT: module = 1, sum name = 0, offset = 208 50CHECK-NEXT: 104 | S_GDATA32 [size = 24] `global` 51CHECK-NEXT: type = 0x0074 (int), addr = 0003:0000 52CHECK-NEXT: 168 | S_GDATA32 [size = 24] `global` 53CHECK-NEXT: type = 0x0074 (int), addr = 0003:0000 54 55CHECK: Symbols 56CHECK: ============================================================ 57CHECK-LABEL: Mod 0000 | `{{.*}}pdb_comdat_main.obj`: 58CHECK: 4 | S_OBJNAME [size = 56] sig=0, `C:\src\llvm-project\build\pdb_comdat_main.obj` 59CHECK: 60 | S_COMPILE3 [size = 60] 60CHECK: machine = intel x86-x64, Ver = Microsoft (R) Optimizing Compiler, language = c 61CHECK: frontend = 19.0.24215.1, backend = 19.0.24215.1 62CHECK: flags = security checks | hot patchable 63CHECK: 120 | S_GPROC32 [size = 44] `main` 64CHECK: parent = 0, end = 196, addr = 0001:0000, code size = 24 65CHECK: debug start = 4, debug end = 19, flags = none 66CHECK: 164 | S_FRAMEPROC [size = 32] 67CHECK: size = 40, padding size = 0, offset to padding = 0 68CHECK: bytes of callee saved registers = 0, exception handler addr = 0000:0000 69CHECK: flags = has async eh | opt speed 70CHECK: 196 | S_END [size = 4] 71CHECK: 200 | S_BUILDINFO [size = 8] BuildId = `0x100A` 72CHECK: 208 | S_GPROC32 [size = 44] `foo` 73CHECK: parent = 0, end = 284, addr = 0001:0032, code size = 15 74CHECK: debug start = 0, debug end = 14, flags = none 75CHECK: 252 | S_FRAMEPROC [size = 32] 76CHECK: size = 0, padding size = 0, offset to padding = 0 77CHECK: bytes of callee saved registers = 0, exception handler addr = 0000:0000 78CHECK: flags = marked inline | has async eh | opt speed 79CHECK: 284 | S_END [size = 4] 80CHECK-LABEL: Mod 0001 | `{{.*}}pdb_comdat_bar.obj`: 81CHECK: 4 | S_OBJNAME [size = 56] sig=0, `C:\src\llvm-project\build\pdb_comdat_bar.obj` 82CHECK: 60 | S_COMPILE3 [size = 60] 83CHECK: machine = intel x86-x64, Ver = Microsoft (R) Optimizing Compiler, language = c 84CHECK: frontend = 19.0.24215.1, backend = 19.0.24215.1 85CHECK: flags = security checks | hot patchable 86CHECK: 120 | S_GPROC32 [size = 44] `bar` 87CHECK: parent = 0, end = 196, addr = 0001:0048, code size = 14 88CHECK: debug start = 4, debug end = 9, flags = none 89CHECK: 164 | S_FRAMEPROC [size = 32] 90CHECK: size = 40, padding size = 0, offset to padding = 0 91CHECK: bytes of callee saved registers = 0, exception handler addr = 0000:0000 92CHECK: flags = has async eh | opt speed 93CHECK: 196 | S_END [size = 4] 94CHECK: 200 | S_BUILDINFO [size = 8] BuildId = `0x100D` 95CHECK-NOT: S_GPROC32 {{.*}} `foo` 96CHECK-LABEL: Mod 0002 | `* Linker *`: 97 98Reorder the object files and verify that the other table is selected. 99 100RUN: lld-link pdb_comdat_bar.obj pdb_comdat_main.obj -out:t.exe -debug -pdb:t.pdb -nodefaultlib -entry:main 101RUN: llvm-pdbutil dump -l t.pdb | FileCheck %s --check-prefix=REORDER 102 103REORDER-LABEL: Mod 0000 | `{{.*}}pdb_comdat_bar.obj`: 104REORDER: c:\src\llvm-project\build\pdb_comdat_bar.c (MD5: 365279DB4FCBEDD721BBFC3B14A953C2) 105REORDER: c:\src\llvm-project\build\foo.h (MD5: D74D834EFAC3AE2B45E606A8320B1D5C) 106REORDER-LABEL: Mod 0001 | `{{.*}}pdb_comdat_main.obj`: 107REORDER: c:\src\llvm-project\build\pdb_comdat_main.c 108REORDER-NOT: c:\src\llvm-project\build\foo.h 109REORDER-LABEL: Mod 0002 | `* Linker *`: 110 111Make sure that we don't crash on non-prevailing debug sections if -debug is not enabled. 112RUN: lld-link pdb_comdat_main.obj pdb_comdat_bar.obj -out:%t.exe -nodefaultlib -entry:main 113