This is an archive of the discontinued LLVM Phabricator instance.

[clang] Canonicalize system headers in dependency file when -canonical-prefixes
ClosedPublic

Authored by aeubanks on Apr 25 2023, 1:27 PM.

Details

Summary

Clang was writing paths to the dependency file that don't exist when using a sysroot with symlinks, causing everything to get rebuilt every time. This is reproducible on Linux by creating a symlink to '/', using that as the sysroot, and trying to build something with ninja that includes the C++ stdlib (e.g. a typical build of LLVM).

This fixes https://github.com/ninja-build/ninja/issues/1330 and somewhat matches gcc.

gcc canonicalizes system headers in dependency files under a -f[no-]canonical-system-headers, but it makes more sense to look at -canonical-prefixes.

D37954 was a previous attempt at this.

Diff Detail

Event Timeline

aeubanks created this revision.Apr 25 2023, 1:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2023, 1:27 PM
aeubanks requested review of this revision.Apr 25 2023, 1:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 25 2023, 1:27 PM
aeubanks edited the summary of this revision. (Show Details)Apr 25 2023, 1:27 PM
aeubanks added reviewers: aaron.ballman, rsmith, thakis, hans.
hans accepted this revision.Apr 26 2023, 6:18 AM

Thanks! I like it.

clang/include/clang/Frontend/Utils.h
44

nit: sort?

This revision is now accepted and ready to land.Apr 26 2023, 6:18 AM
This revision was landed with ongoing or failed builds.May 1 2023, 10:47 AM
This revision was automatically updated to reflect the committed changes.
chapuni added a subscriber: chapuni.May 1 2023, 6:31 PM

I am afraid this would be incompatible to bazel due to deep symlinks for sandbox.

I am afraid this would be incompatible to bazel due to deep symlinks for sandbox.

I assume bazel would use -no-canonical-prefixes?

shafik added a subscriber: shafik.May 2 2023, 6:29 PM

This commit came up in the following bug report: https://github.com/llvm/llvm-project/issues/62505

Please take a look.