This is an archive of the discontinued LLVM Phabricator instance.

[PDB] Don't include input files in the 'cmd' entry of S_ENVBLOCK
ClosedPublic

Authored by saudi on Nov 9 2022, 9:02 AM.

Details

Summary

The S_ENVBLOCK is used for the Linker information inside of the pdb file contains an entry "cmd" for the command line arguments.
This patch aligns this entry to what MSVC generates, stripping the input files arguments.

The issue we encountered was in the case of a large project where we link many .obj files, and trying to use the Live++ tool for edit-and-continue.
Since the linker's command line reached 100KB, it gets truncated to match the 64 KB limit of the S_ENVBLOCK of the PDB file.
Live++ uses it to detect whether the appropriate flags (like /FUNCTIONPADMIN) were used for proper hotpatching.
It may miss truncated arguments and give false warnings to the user.

In our case, with this patch, the 100KB command line (which tends to get bigger as the project evolves) gets reduced to about 12KB, and evolves much slower.

Pros:

  • align on MSVC's behavior
  • keep S_ENVBLOCK size under the 64KB limit

Cons:

  • the command line found in the pdb can't be used as-is to link the project the way it was.

Diff Detail

Event Timeline

saudi created this revision.Nov 9 2022, 9:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 9 2022, 9:02 AM
saudi requested review of this revision.Nov 9 2022, 9:02 AM
saudi updated this revision to Diff 474292.Nov 9 2022, 9:05 AM

Added release note

Herald added a project: Restricted Project. · View Herald Transcript
thakis added inline comments.Nov 9 2022, 9:44 AM
lld/COFF/PDB.cpp
1357 ↗(On Diff #474292)

What if I'm cross-linking on Linux and passing in /path/to/foo.o?

saudi added inline comments.Nov 10 2022, 8:40 AM
lld/COFF/PDB.cpp
1357 ↗(On Diff #474292)

Indeed, I can't make the assumption that any argument starting with / is an input file.
I'll investigate more to get a posix-friendly version.

saudi updated this revision to Diff 474593.Nov 10 2022, 12:44 PM

Perform the argument list filtering in the driver, to use the result of parsed arguments.
Updated pdb-linker-module.test, checking that the object file is indeed discarded.

Since the object file is provided as an absolute path, this checks that '/path/to/file.o' is not mistaken for a command line argument.

thakis accepted this revision.Nov 11 2022, 6:05 AM

Works for me, thanks!

lld/COFF/DriverUtils.cpp
859

Instead of this line, maybe config->argv.push_back(argv[0]);? Maybe a bit more direct.

This revision is now accepted and ready to land.Nov 11 2022, 6:05 AM
saudi updated this revision to Diff 474759.Nov 11 2022, 7:25 AM

Simplified init of config->argv

saudi marked an inline comment as done.Nov 11 2022, 9:02 AM
saudi added inline comments.
lld/COFF/DriverUtils.cpp
859

replacing with = {argv[0]} to keep the previous behavior concerning re-initialization of config->argv

thieta accepted this revision.Nov 11 2022, 9:54 AM

LGTM!

This revision was automatically updated to reflect the committed changes.
saudi marked an inline comment as done.