This is an archive of the discontinued LLVM Phabricator instance.

[PDB] Add PDBSourcePath flag to support absolutize source file path
ClosedPublic

Authored by takuto.ikuta on Jul 3 2018, 7:47 AM.

Details

Summary

This patch changes relative path for source files in obj files to absolute path in PDB when linking with added flag.

I will make obj file generated by clang-cl independent from build directory for chromium build. But I don't want to confuse visual studio debugger or require additional configuration. To attain this goal, I added flag to convert relative source file path in obj to absolute path when emitting PDB.

By removing absolute path from obj files, we can share build cache between chromium developers even when they are doing debug build.
That will make build time faster.

More context:
https://bugs.chromium.org/p/chromium/issues/detail?id=712796
https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/5HXSVX-7fPc

Diff Detail

Event Timeline

takuto.ikuta created this revision.Jul 3 2018, 7:47 AM
takuto.ikuta edited the summary of this revision. (Show Details)Jul 3 2018, 7:50 AM
takuto.ikuta retitled this revision from Change relative source file path to absolute path in lld to Change relative source file path in obj files to absolute path in PDB.Jul 3 2018, 8:29 AM
takuto.ikuta edited the summary of this revision. (Show Details)
zturner added inline comments.Jul 3 2018, 5:09 PM
lld/COFF/PDB.cpp
935–944

I don't think it's correct to force Windows path style here. I think we should just use the default native style.

If you are doing a cross-compilation, then the code here will emit a path into the object file that doesn't make any sense or correspond to the actual machine that the file was generated on, which seems wrong.

This doesn't matter too much for MSVC since you will never run it on Linux anyway, but one could imagine that someday some other debugger (LLDB, GDB, etc) will be taught how to natively parse PDB files, and maybe on Linux it would be able to debug code running under WINE while the debug info and sources are on a native Linux partition. So it doesn't seem correct to lock PDBs to a Windows host at the file format level.

Use native path style

takuto.ikuta added inline comments.Jul 3 2018, 5:19 PM
lld/COFF/PDB.cpp
935–944

I see. But I just tried to follow the code in L814.

thakis added a reviewer: ruiu.Jul 6 2018, 4:45 AM
thakis added a comment.Jul 6 2018, 4:47 AM

Thanks for the patch! I wonder if this should be behind some flag (/makePDBPathsAbsolute or something) and not be done by default. If we have a flag, the flag could also optionally provide a different prefix than pwd (/makePDBPathsAbsolute:c:\src), which might be useful for cross builds. I'd like to hear ruiu's thoughts on this.

This shouldn't have a measurable impact on link time, right?

Use given path to normalize path

Thank you for taking a look.

Thanks for the patch! I wonder if this should be behind some flag (/makePDBPathsAbsolute or something) and not be done by default. If we have a flag, the flag could also optionally provide a different prefix than pwd (/makePDBPathsAbsolute:c:\src), which might be useful for cross builds. I'd like to hear ruiu's thoughts on this.

It makes sense to me. Added a flag.

This shouldn't have a measurable impact on link time, right?

I confirmed this does not show visible performance difference.

takuto.ikuta retitled this revision from Change relative source file path in obj files to absolute path in PDB to [PDB] Add makePDBPathsAbsolute flag to support absolutize source file path.Jul 11 2018, 2:48 AM
takuto.ikuta edited the summary of this revision. (Show Details)

Ping? Can I go this way?

zturner accepted this revision.Jul 11 2018, 11:39 AM
This revision is now accepted and ready to land.Jul 11 2018, 11:39 AM

If some of you have concern about this, please leave a comment.

I'll ask commit right and merge this if I could be a committer.

thakis accepted this revision.Jul 12 2018, 1:19 PM

Looks good to me, thanks!

ruiu added inline comments.Jul 12 2018, 1:42 PM
lld/COFF/Config.h
105–108

Sort.

lld/COFF/PDB.cpp
935–944

If we should use the native pathname rather than Windows one, then you probably should do either is_absolute(Filename, Sytle::windows) or is_absolute(Filename, Style::posix) but not both, since X:/foo is a relative path on Unix.

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

Don't you need only the lines that contain pathname? I'd remove all the other lines from the file, so that we don't have to update them when some unrelated change is committed.

takuto.ikuta marked an inline comment as done.

Shrink test data

takuto.ikuta marked 3 inline comments as done.Jul 12 2018, 7:36 PM
takuto.ikuta added inline comments.
lld/test/COFF/pdb-relative-source-lines.test
49

Shrinked, but let me keep hardly be changed lines as anchor.

ruiu added inline comments.Jul 13 2018, 7:18 AM
lld/COFF/Options.td
144

Help text shouldn't end with a period. Please always look around and follow the local convention. That's I think important.

Is this considered an internal option, or this is intended to be used directly by users? If it is intended to be used widely, the option name "/makepdbpathabsolute" seems a bit weird to me. There's no existing option name like that. Perhaps something like "/pdbpath:absolute" is better.

takuto.ikuta marked an inline comment as done.

pdbsourcepath

takuto.ikuta retitled this revision from [PDB] Add makePDBPathsAbsolute flag to support absolutize source file path to [PDB] Add PDBSourcePath flag to support absolutize source file path.Jul 13 2018, 9:20 AM
takuto.ikuta added inline comments.Jul 13 2018, 9:30 AM
lld/COFF/Options.td
144

Basically, I don't expect this option will be used by user widely, because this option has no meaning for obj files without clang-cl's internal -fdebug-compilation-dir option.

But path normalization feature will be useful for debuggable executable from reproducible obj files. And some other users may use this. So I changed the flag name.

ruiu added a comment.Jul 13 2018, 10:18 AM

Is Ukai-san OK with this change?

lld/COFF/Options.td
143–144

Other options seems to be sorted, so please sort alphabetically. It is nitpicky but consistency matters, so please spend a bit more time to read code around the location you are changing so that your new code doesn't look too different. I think that's important and actually saves both your and my time.

takuto.ikuta marked an inline comment as done.Jul 16 2018, 9:19 PM

Is Ukai-san OK with this change?

Yes, I got agreement on this way from him.