llvm-project/lld/test/COFF/pdb-relative-source-lines.test

146 lines
5.9 KiB
Plaintext

Test the linker line tables on roughly the following example:
==> foo.h <==
void bar(void);
inline void foo(void) {
bar();
}
==> pdb_lines_1.c <==
#include "foo.h"
int main(void) {
foo();
return 42;
}
==> pdb_lines_2.c <==
void bar(void) {
}
$ clang-cl -fdebug-compilation-dir . -no-canonical-prefixes -c -Z7 pdb_lines*.c
$ obj2yaml pdb_lines_1.obj > pdb_lines_1_relative.yaml
$ obj2yaml pdb_lines_2.obj > pdb_lines_2_relative.yaml
/pdbsourcepath: only sets the directory that relative paths are considered
relative to, so this test needs to pass relative paths to lld-link for:
1. The input obj files
2. The /pdb: switch
3. The lld-link invocation itself
To achieve this, put all inputs of the lld-link invocation (including lld-link
itself) in a temp directory that's cwd and then make sure to only use relative
arguments when calling ./lld-link below.
RUN: rm -rf %t
RUN: mkdir %t
RUN: cp lld-link %t/lld-link
RUN: cd %t
RUN: yaml2obj %S/Inputs/pdb_lines_1_relative.yaml -o %t/pdb_lines_1_relative.obj
RUN: yaml2obj %S/Inputs/pdb_lines_2_relative.yaml -o %t/pdb_lines_2_relative.obj
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
RUN: llvm-pdbutil pdb2yaml -ipi-stream -modules -module-files -module-syms -subsections=lines,fc %t/out.pdb | FileCheck %s
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
RUN: llvm-pdbutil pdb2yaml -ipi-stream -modules -module-files -module-syms -subsections=lines,fc %t/out.pdb | FileCheck --check-prefix=POSIX %s
Also check without -pdbsourcepath
RUN: ./lld-link -debug -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb pdb_lines_1_relative.obj pdb_lines_2_relative.obj
RUN: llvm-pdbutil pdb2yaml -modules -module-files -module-syms -subsections=lines,fc %t/out.pdb | FileCheck --check-prefix=ABSOLUTE %s
Clean up copy of large binary copied into temp directory to avoid bloat.
RUN: rm -f ./lld-link || true
CHECK-LABEL: - Module: 'c:\src\pdb_lines_1_relative.obj'
CHECK-NEXT: ObjFile: 'c:\src\pdb_lines_1_relative.obj'
CHECK: SourceFiles:
CHECK-NEXT: - 'c:\src\pdb_lines_1.c'
CHECK-NEXT: - 'c:\src\foo.h'
CHECK: Subsections:
CHECK: - FileName: 'c:\src\pdb_lines_1.c'
CHECK: - FileName: 'c:\src\foo.h'
CHECK: - !FileChecksums
CHECK: - FileName: 'c:\src\pdb_lines_1.c'
CHECK: - FileName: 'c:\src\foo.h'
CHECK-LABEL: - Module: 'c:\src\pdb_lines_2_relative.obj'
CHECK-NEXT: ObjFile: 'c:\src\pdb_lines_2_relative.obj'
CHECK: SourceFiles:
CHECK-NEXT: - 'c:\src\pdb_lines_2.c'
CHECK: Subsections:
CHECK: - FileName: 'c:\src\pdb_lines_2.c'
CHECK: - !FileChecksums
CHECK: - FileName: 'c:\src\pdb_lines_2.c'
CHECK-LABEL: - Kind: S_ENVBLOCK
CHECK-NEXT: EnvBlockSym:
CHECK-NEXT: Entries:
CHECK-NEXT: - cwd
CHECK-NEXT: - 'c:\src'
CHECK-NEXT: - exe
CHECK-NEXT: - 'c:\src\lld-link'
CHECK-NEXT: - pdb
CHECK-NEXT: - 'c:\src\out.pdb'
CHECK-NEXT: - cmd
CHECK-NEXT: - '-debug -pdbsourcepath:c:\src -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb pdb_lines_1_relative.obj pdb_lines_2_relative.obj'
CHECK-LABEL: IpiStream:
CHECK: - Kind: LF_STRING_ID
CHECK-NEXT: StringId:
CHECK-NEXT: Id: 0
CHECK-NEXT: String: .
CHECK-NEXT: - Kind: LF_STRING_ID
CHECK-NEXT: StringId:
CHECK-NEXT: Id: 0
CHECK-NEXT: String: pdb_lines_1.c
CHECK-NEXT: - Kind: LF_STRING_ID
CHECK-NEXT: StringId:
CHECK-NEXT: Id: 0
CHECK-NEXT: String: 'buildninjaRel\bin\clang-cl.exe'
POSIX-LABEL: - Module: '/usr/src/pdb_lines_1_relative.obj'
POSIX-NEXT: ObjFile: '/usr/src/pdb_lines_1_relative.obj'
POSIX: SourceFiles:
POSIX-NEXT: - '/usr/src/pdb_lines_1.c'
POSIX-NEXT: - '/usr/src/foo.h'
POSIX: Subsections:
POSIX: - FileName: '/usr/src/pdb_lines_1.c'
POSIX: - FileName: '/usr/src/foo.h'
POSIX: - !FileChecksums
POSIX: - FileName: '/usr/src/pdb_lines_1.c'
POSIX: - FileName: '/usr/src/foo.h'
POSIX-LABEL: - Module: '/usr/src/pdb_lines_2_relative.obj'
POSIX-NEXT: ObjFile: '/usr/src/pdb_lines_2_relative.obj'
POSIX: SourceFiles:
POSIX-NEXT: - '/usr/src/pdb_lines_2.c'
POSIX: Subsections:
POSIX: - FileName: '/usr/src/pdb_lines_2.c'
POSIX: - !FileChecksums
POSIX: - FileName: '/usr/src/pdb_lines_2.c'
POSIX-LABEL: - Kind: S_ENVBLOCK
POSIX-NEXT: EnvBlockSym:
POSIX-NEXT: Entries:
POSIX-NEXT: - cwd
POSIX-NEXT: - '/usr/src'
POSIX-NEXT: - exe
POSIX-NEXT: - '/usr/src/lld-link'
POSIX-NEXT: - pdb
POSIX-NEXT: - '/usr/src/out.pdb'
POSIX-NEXT: - cmd
POSIX-NEXT: - '-debug -pdbsourcepath:/usr/src -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb pdb_lines_1_relative.obj pdb_lines_2_relative.obj'
ABSOLUTE-LABEL: StringTable:
ABSOLUTE-NOT: {{/|\\}}.{{/|\\}}pdb_lines_1.c
POSIX-LABEL: IpiStream:
POSIX: - Kind: LF_STRING_ID
POSIX-NEXT: StringId:
POSIX-NEXT: Id: 0
POSIX-NEXT: String: .
POSIX-NEXT: - Kind: LF_STRING_ID
POSIX-NEXT: StringId:
POSIX-NEXT: Id: 0
POSIX-NEXT: String: pdb_lines_1.c
POSIX-NEXT: - Kind: LF_STRING_ID
POSIX-NEXT: StringId:
POSIX-NEXT: Id: 0
POSIX-NEXT: String: 'buildninjaRel\bin\clang-cl.exe'