Skip to content

Conversation

@qiongsiwu
Copy link

This PR explicitly sets DebugCompilationDir to the system's root directory if it is safe to ignore the current working directory.

This fixes a problem where a PCM file's embedded debug information can lead to compilation failure. The compiler may have decided it is indeed safe to ignore the current working directory. In this case, the PCM file's content is functionally correct regardless of the current working directory because no inputs use relative paths (see llvm#124786). However, a PCM may contain debug info. If debug info is requested, the compiler uses the current working directory value to set DW_AT_comp_dir. This may lead to the following situation:

  1. Two different compilations need the same PCM file.
  2. The PCM file is compiled assuming a working directory, which is embedded in the debug info, but otherwise has no effect.
  3. The second compilation assumes a different working directory, and expects an identically-sized pcm file. However, it cannot find such a PCM, because the existing PCM file has been compiled assuming a different DW_AT_comp_dir , which is embedded in the debug info.

This PR resets the DebugCompilationDir if it is functionally safe to ignore the working directory so the above situation is avoided, since all debug information will share the same working directory.

rdar://145249881
(cherry picked from commit 7f482aa)

Conflicts:
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

…re current working directory (llvm#128446)

This PR explicitly sets `DebugCompilationDir` to the system's root
directory if it is safe to ignore the current working directory.

This fixes a problem where a PCM file's embedded debug information can
lead to compilation failure. The compiler may have decided it is indeed
safe to ignore the current working directory. In this case, the PCM
file's content is functionally correct regardless of the current working
directory because no inputs use relative paths (see
llvm#124786). However, a PCM may
contain debug info. If debug info is requested, the compiler uses the
current working directory value to set `DW_AT_comp_dir`. This may lead
to the following situation:
1. Two different compilations need the same PCM file.
2. The PCM file is compiled assuming a working directory, which is
embedded in the debug info, but otherwise has no effect.
3. The second compilation assumes a different working directory, and
expects an identically-sized pcm file. However, it cannot find such a
PCM, because the existing PCM file has been compiled assuming a
different `DW_AT_comp_dir `, which is embedded in the debug info.

This PR resets the `DebugCompilationDir` if it is functionally safe to
ignore the working directory so the above situation is avoided, since
all debug information will share the same working directory.

rdar://145249881
(cherry picked from commit 7f482aa)

 Conflicts:
	clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@qiongsiwu qiongsiwu requested a review from a team as a code owner February 26, 2025 23:37
@qiongsiwu qiongsiwu requested review from Bigcheese, cyndyishida and jansvoboda11 and removed request for a team and Bigcheese February 26, 2025 23:37
@qiongsiwu
Copy link
Author

@swift-ci Please test LLVM

@qiongsiwu qiongsiwu self-assigned this Feb 26, 2025
@qiongsiwu
Copy link
Author

@swift-ci please test

@qiongsiwu
Copy link
Author

Gentle ping for review. Thank you!

@qiongsiwu qiongsiwu merged commit 01f9dd6 into swiftlang:stable/20240723 Feb 27, 2025
5 checks passed
@qiongsiwu qiongsiwu deleted the cherry_pick_fix_145249881 branch February 27, 2025 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants