Skip to content

Commit 7dcd8ef

Browse files
authored
[LLD] [MinGW] Respect the -S/-s options when writing PDB files (#75181)
This allows avoiding including some stray DWARF sections (e.g. from toolchain provided files), when writing a PDB file. While that probably could be considered reasonable default behaviour, PDB writing and including DWARF sections are two entirely orthogonal concepts, and GNU ld (which can generate PDB files these days) does include DWARF unless -S/-s is passed, when creating a PDB.
1 parent e36535d commit 7dcd8ef

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lld/MinGW/Driver.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
297297
StringRef v = a->getValue();
298298
if (!v.empty())
299299
add("-pdb:" + v);
300+
if (args.hasArg(OPT_strip_all)) {
301+
add("-debug:nodwarf,nosymtab");
302+
} else if (args.hasArg(OPT_strip_debug)) {
303+
add("-debug:nodwarf,symtab");
304+
}
300305
} else if (args.hasArg(OPT_strip_debug)) {
301306
add("-debug:symtab");
302307
} else if (!args.hasArg(OPT_strip_all)) {

lld/test/MinGW/driver.test

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,18 @@ STRIP-DEBUG-NOT: -debug:dwarf
138138
RUN: ld.lld -### -m i386pep foo.o -pdb out.pdb 2>&1 | FileCheck -check-prefix PDB %s
139139
RUN: ld.lld -### -m i386pep foo.o -pdb=out.pdb 2>&1 | FileCheck -check-prefix PDB %s
140140
PDB: -debug -pdb:out.pdb
141-
PDB-NOT: -debug:dwarf
141+
PDB-NOT: -debug:
142142

143143
RUN: ld.lld -### -m i386pep foo.o -pdb= 2>&1 | FileCheck -check-prefix PDB-DEFAULT %s
144144
PDB-DEFAULT: -debug
145145
PDB-DEFAULT-NOT: -pdb:{{.*}}
146+
PDB-DEFAULT-NOT: -debug:
147+
148+
RUN: ld.lld -### -m i386pep foo.o -pdb= -S 2>&1 | FileCheck -check-prefix PDB-NODWARF %s
149+
PDB-NODWARF: -debug -debug:nodwarf,symtab
150+
151+
RUN: ld.lld -### -m i386pep foo.o -pdb= -s 2>&1 | FileCheck -check-prefix PDB-NODWARF-NOSYMTAB %s
152+
PDB-NODWARF-NOSYMTAB: -debug -debug:nodwarf,nosymtab
146153

147154
RUN: ld.lld -### -m i386pep foo.o --large-address-aware 2>&1 | FileCheck -check-prefix LARGE-ADDRESS-AWARE %s
148155
LARGE-ADDRESS-AWARE: -largeaddressaware

0 commit comments

Comments
 (0)