Xcode/Clang: Single framework produces conflicting ModuleCache entries
||Date Originated:||12-Feb-2015 11:05 PM|
Note: this bug is the culmination of my exposition on the Apple Developer Forums about the subject:
Summary: some circumstances cause clang to generate multiple ModuleCache entries for the same framework. In the worst case, two of those entries might have the same timestamp, leaving to a situation where the compiler fails with an error like:
/Volumes/Data/daniel/Sources-Modern/Diversions/Bug Reports/ClangModuleCacheBug 2/main.m:12:2: error: module 'RSFoundation' found in both '/Volumes/Data/daniel/Library/Developer/Xcode/DerivedData/ModuleCache/3DC9DUT70WHU/RSFoundation-1YTD46C9XJMOW.pcm' and '/Volumes/Data/daniel/Library/Developer/Xcode/DerivedData/ModuleCache/3DC9DUT70WHU/RSFoundation-2OA51XV5KS79U.pcm'
In the best case, I guess the ModuleCache folder is littered with older, outdated pcm files that are ignored in favor of newer pcm files for the same module. I have witnessed as many as 6 .pcm files in a given ModuleCache subfolder, all for the same RSFoundation library above.
In the course of investigating this bug I came to discover that at least one cause for the problem seems to be in interpreting library arguments to Ld differently, such that for a given .framework, a ModuleCache entry might be generated both for the hash of path [Framework]/Versions/A/Modules/Module.modulemap and for [Framework]/Modules/Module.modulemap.
The attached Xcode project demonstrates this particular case, though I'm pretty sure you could contrive the case even more simply by setting up a command-line best test case.
Steps to Reproduce:
1. Open attached ClangModuleCacheBug.zip
2. Open RSWebPublishing.xcodeproj within.
3. Build the solitary scheme "RSWebPublishing"
The framework should build without error.
The framework fails to load with error as cited above.
Take a look in the BuildSettings.xcconfig for a note about my observation that, for some reason, the bug does not occur when compiler optimizations are turned on.
Also observe that the recipe of using Xcode to contrive the problematic scenario seems to be rooted somehow in the way that I'm nesting .xcodeproj dependencies within this project. I am fairly convinced this cyclic nesting (RSCommonLib.xcodeproj depends on RSWebClientCore.xcodeproj, which depends back on RSCommonLib.xcodeproj) is not a great idea, but it does do a good job of demonstrating this bug ;)
Version 6.3 (6D520o) but also occurs on earlier 6.2 releases.
'ClangModuleCacheBug.zip' was successfully uploaded.
Reports posted here will not necessarily be seen by Apple.
All problems should be submitted at bugreport.apple.com before they are posted here.
Please only post information for Radars that you have filed yourself, and please do
not include Apple confidential information in your posts. Thank you!