This is an archive of the discontinued LLVM Phabricator instance.

[LLD][COFF] Fix /linkrepro with options that take a filename or path
ClosedPublic

Authored by aganea on Mar 18 2019, 7:10 PM.

Details

Summary

Some options like /pdb: or /out: or /implib: take a filename or path on the right side. When using partial or full paths with these options, previously this resulted in the paths not being translated relative-to-root by /linkrepro:

$ lld-link /pdb:"F:\some\path\mypdb.pdb" /out:"relative\..\..\real\output\file.exe" /implib:a.lib ... /linkrepro:.

The generated response file might have now non-existent paths on the reproducer's machine:

/pdb:"F:\some\path\mypdb.pdb"
/out:"relative\..\..\real\output\file.exe"
/out:a.lib
...

With this patch, the response is fully reproducible/usable as expected:

/pdb:mypdb.pdb
/out:file.exe
/implib:a.lib
...

Diff Detail

Repository
rLLD LLVM Linker

Event Timeline

aganea created this revision.Mar 18 2019, 7:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 18 2019, 7:10 PM
aganea added a comment.EditedMar 19 2019, 5:41 AM

Would you like to keep the filenames without a path as they are? ie. /implib:a.lib, keep a.lib in the response, instead of F/other/path/a.lib

Aren't all of /implib, /pdband /out output files? In that sense it doesn't matter where they are written in the repro case (and writing them locally instead of somewhere else with an absolute path probably is more convenient?).

The one that would matter though, which iirc isn't handled right now, is when def files are passed as input. IIRC they aren't copied into the repro bundle.

aganea added a comment.EditedMar 19 2019, 5:57 AM

Aren't all of /implib, /pdband /out output files? In that sense it doesn't matter where they are written in the repro case (and writing them locally instead of somewhere else with an absolute path probably is more convenient?).

Yes, however our build system generates cmd-lines with full or relative paths for these options, which makes the response unusable, unless you edit it (because the paths aren't there on the reproducer's machine)

Are you suggesting that we strip those options from their path, and only kept the filename? That would be a good alternative.

Aren't all of /implib, /pdband /out output files? In that sense it doesn't matter where they are written in the repro case (and writing them locally instead of somewhere else with an absolute path probably is more convenient?).

Yes, however our build system generates cmd-lines with full or relative paths for these options, which makes the response unusable, unless you edit it (because the paths aren't there on the reproducer's machine)

Are you suggesting that we strip those options from their path, and only kept the filename? That would be a good alternative.

That sounds like a good alternative to me, yes.

ruiu added a comment.Mar 19 2019, 7:33 AM

Aren't all of /implib, /pdband /out output files? In that sense it doesn't matter where they are written in the repro case (and writing them locally instead of somewhere else with an absolute path probably is more convenient?).

Yes, however our build system generates cmd-lines with full or relative paths for these options, which makes the response unusable, unless you edit it (because the paths aren't there on the reproducer's machine)

Are you suggesting that we strip those options from their path, and only kept the filename? That would be a good alternative.

That sounds like a good alternative to me, yes.

I agree, stripping directory names from a path seems a better approach. In particular, making it relative path as you proposed originally has an issue that you need to add an empty directory

F/other/path

to a generated tar file for

/out:F/other/path/file.exe

or otherwise the linker would fail when trying to create the output file. And adding an empty directory to an archive file is a little tricky -- I'm not 100% sure if all tar implementations restores an empty directory (a common idiom is to add an empty file .keep to an empty directory, so that the directory is not empty, but that's yet another hack.) All in all, keeping the only filename seems like the best option here.

aganea updated this revision to Diff 191335.Mar 19 2019, 9:57 AM
aganea edited the summary of this revision. (Show Details)

Only output filenames, as requested.

ruiu added inline comments.Mar 20 2019, 5:10 PM
COFF/Driver.cpp
557

Let's just write out what you want here, instead of adding a variable and a new helper function.

OS << Arg->getSpelling() << ":" << sys::path::filename(Arg->getValue()) << "\n";
aganea updated this revision to Diff 195204.Apr 15 2019, 9:15 AM

Simplified as requested.

aganea marked an inline comment as done.Apr 15 2019, 9:16 AM
aganea updated this revision to Diff 195205.Apr 15 2019, 9:19 AM
ruiu accepted this revision.Apr 15 2019, 5:44 PM

LGTM

This revision is now accepted and ready to land.Apr 15 2019, 5:44 PM
This revision was automatically updated to reflect the committed changes.