[clang] [InstallAPI] Handle zippered frameworks (PR #88205)

Cyndy Ishida via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 10 09:09:30 PDT 2024


================
@@ -588,13 +622,58 @@ void DylibVerifier::visitSymbolInDylib(const Record &R, SymbolContext &SymCtx) {
     }
   }
 
+  const bool IsLinkerSymbol = SymbolName.starts_with("$ld$");
+
+  if (R.isVerified()) {
+    // Check for unavailable symbols.
+    // This should only occur in the zippered case where we ignored
+    // availability until all headers have been parsed.
+    auto It = DeferredZipperedSymbols.find(SymCtx.SymbolName);
+    if (It == DeferredZipperedSymbols.end()) {
+      updateState(Result::Valid);
+      return;
+    }
+
+    ZipperedDeclSources Locs;
+    for (const ZipperedDeclSource &ZSource : It->second) {
+      if (ZSource.FA->Avail.isObsoleted()) {
+        updateState(Result::Ignore);
+        return;
+      }
+      if (ZSource.T.Arch != Ctx.Target.Arch)
+        continue;
+      Locs.emplace_back(ZSource);
+    }
+    assert(Locs.size() == 2 && "Expected two decls for zippered symbol");
----------------
cyndyishida wrote:

My thinking at this point is that the only kind of error is when every version of the decl look unavailable (no decl at all/only one available decl are handled separately). Because this check is handled after all CC1 invocations have finished, any macro-guarded declarations should have been resolved and show 2. 
e.g. 
```
#if defined(TARGET_OS_OSX) && TARGET_OS_OSX
extern int unavailableSymbol API_UNAVAILABLE(macos) ;
#else
extern int unavailableSymbol API_UNAVAILABLE(macCatalyst);
#endif
```
results in 

```
warning: violations found for arm64-apple-macos13
/Users/cishida/Builds/llvm-build/tools/clang/test/InstallAPI/Output/diagnostics-zippered.test.tmp/System/Library/Frameworks/Mismatch.framework/Headers/Mismatch.h:16:5: error: declaration 'unavailableSymbol' is marked unavailable, but symbol is exported in dynamic library
   16 | int unavailableSymbol API_UNAVAILABLE(macos) ;
      |     ^
warning: violations found for arm64-apple-ios16.0-macabi 
/Users/cishida/Builds/llvm-build/tools/clang/test/InstallAPI/Output/diagnostics-zippered.test.tmp/System/Library/Frameworks/Mismatch.framework/Headers/Mismatch.h:18:5: error: declaration 'unavailableSymbol' is marked unavailable, but symbol is exported in dynamic library
   18 | int unavailableSymbol API_UNAVAILABLE(macCatalyst);
      |     ^
```

Were you thinking of a different example? 

https://github.com/llvm/llvm-project/pull/88205


More information about the cfe-commits mailing list