Skip to content

Commit df2f9e5

Browse files
committed
[PDB] Don't include input files in the 'cmd' entry of S_ENVBLOCK
MSVC records the command line arguments in S_ENVBLOCK, skipping the input file arguments. This patch adds this filtering on lld-link side. Differential Revision: https://reviews.llvm.org/D137723
1 parent 7e78685 commit df2f9e5

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

lld/COFF/DriverUtils.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,8 +855,13 @@ opt::InputArgList ArgParser::parse(ArrayRef<const char *> argv) {
855855
}
856856

857857
// Save the command line after response file expansion so we can write it to
858-
// the PDB if necessary.
859-
config->argv = {expandedArgv.begin(), expandedArgv.end()};
858+
// the PDB if necessary. Mimic MSVC, which skips input files.
859+
config->argv = {argv[0]};
860+
for (opt::Arg *arg : args) {
861+
if (arg->getOption().getKind() != opt::Option::InputClass) {
862+
config->argv.push_back(args.getArgString(arg->getIndex()));
863+
}
864+
}
860865

861866
// Handle /WX early since it converts missing argument warnings to errors.
862867
errorHandler().fatalWarnings = args.hasFlag(OPT_WX, OPT_WX_no, false);

lld/docs/ReleaseNotes.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ Breaking changes
4040
COFF Improvements
4141
-----------------
4242

43-
* ...
43+
* The linker command line entry in ``S_ENVBLOCK`` of the PDB is now stripped
44+
from input files, to align with MSVC behavior.
45+
(`D137723 <https://reviews.llvm.org/D137723>`_)
4446

4547
MinGW Improvements
4648
------------------

lld/test/COFF/pdb-linker-module.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ SYMS-NEXT: - {{.*}}lld-link
2222
SYMS-NEXT: - pdb
2323
SYMS-NEXT: - {{.*}}pdb-linker-module{{.*}}pdb
2424
SYMS-NEXT: - cmd
25-
SYMS-NEXT: - /debug /pdb:{{.*}}pdb-linker-module{{.*}}pdb /nodefaultlib "/entry:1 ""hello"" 2" "/manifestuac:level='asInvoker' uiAccess='false'" {{.*}}pdb-diff.obj
25+
SYMS-NEXT: - /debug /pdb:{{.*}}pdb-linker-module{{.*}}pdb /nodefaultlib "/entry:1 ""hello"" 2" "/manifestuac:level='asInvoker' uiAccess='false'" /force

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ CHECK-NEXT: - 'c:\src\lld-link'
7777
CHECK-NEXT: - pdb
7878
CHECK-NEXT: - 'c:\src\out.pdb'
7979
CHECK-NEXT: - cmd
80-
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'
80+
CHECK-NEXT: - '-debug -pdbsourcepath:c:\src -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb'
8181

8282
CHECK-LABEL: IpiStream:
8383

@@ -125,7 +125,7 @@ POSIX-NEXT: - '/usr/src/lld-link'
125125
POSIX-NEXT: - pdb
126126
POSIX-NEXT: - '/usr/src/out.pdb'
127127
POSIX-NEXT: - cmd
128-
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'
128+
POSIX-NEXT: - '-debug -pdbsourcepath:/usr/src -entry:main -nodefaultlib -out:out.exe -pdb:out.pdb'
129129

130130
ABSOLUTE-LABEL: StringTable:
131131
ABSOLUTE-NOT: {{/|\\}}.{{/|\\}}pdb_lines_1.c

0 commit comments

Comments
 (0)