Without this, someone can write lld-link.exe /OUT:foo.exe /OUT:foo.pdb foo.obj and it will generate a PDB. But it's not a very useful PDB, because .debug$S and .debug$T information is not put into the PDB unless /DEBUG is also specified from the command line. So, if /DEBUG is not specified, don't output anything.
Details
Details
Diff Detail
Diff Detail
Event Timeline
Comment Actions
Is this behavior the same as the MSVC linker? If it doesn't make sense to pass the /pdb option without /debug, we might want to emit an error (or warning) in the driver.
Comment Actions
Yes, MSVC ignores /pdb option if you don't pass /DEBUG.
D:\src\llvmbuild\pdbtest>cl /c /Z7 hello.cpp Microsoft (R) C/C++ Optimizing Compiler Version 19.10.25019 for x86 Copyright (C) Microsoft Corporation. All rights reserved. hello.cpp C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\xlocale(314): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.10.25017\include\exception(366): warning C4577: 'noexcept' used with no exception handling mode specified; termination on exception is not guaranteed. Specify /EHsc D:\src\llvmbuild\pdbtest>link /out:hello.exe /pdb:hello.pdb hello.obj Microsoft (R) Incremental Linker Version 14.10.25019.0 Copyright (C) Microsoft Corporation. All rights reserved. D:\src\llvmbuild\pdbtest>dir hello* Volume in drive D is New Volume Volume Serial Number is 2EC5-6F01 Directory of D:\src\llvmbuild\pdbtest 05/17/2017 04:05 PM 92 hello.cpp 05/17/2017 04:06 PM 183,296 hello.exe 05/17/2017 04:05 PM 334,693 hello.obj 3 File(s) 518,081 bytes 0 Dir(s) 129,495,351,296 bytes free D:\src\llvmbuild\pdbtest>link /debug /out:hello.exe /pdb:hello.pdb hello.obj Microsoft (R) Incremental Linker Version 14.10.25019.0 Copyright (C) Microsoft Corporation. All rights reserved. D:\src\llvmbuild\pdbtest>dir hello* Volume in drive D is New Volume Volume Serial Number is 2EC5-6F01 Directory of D:\src\llvmbuild\pdbtest 05/17/2017 04:05 PM 92 hello.cpp 05/17/2017 04:06 PM 756,224 hello.exe 05/17/2017 04:06 PM 3,284,272 hello.ilk 05/17/2017 04:05 PM 334,693 hello.obj 05/17/2017 04:06 PM 8,048,640 hello.pdb 5 File(s) 12,423,921 bytes 0 Dir(s) 129,483,444,224 bytes free
Comment Actions
Removed the /DEBUGPDB option since it is unreferenced in the code. If the intent is to force writing a PDB, then all you have to do is specify /DEBUG, and you are guaranteed to get a PDB.
Also added some tests confirming the interactions between /DEBUG and /PDB.
BTW, this page indicates that it's not just an accident that MSVC linker behaves this way.
Use /PDB:filename to specify the name of the PDB file. If /DEBUG is not specified, the /PDB option is ignored.