From 33a89a6b790ccc9868d456baf2aae45f7af5b8c7 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Sat, 4 May 2024 15:12:50 +0000 Subject: [PATCH] modulewrap: Disable ObjC interop by default on non-Darwin platforms 0a5653dbaf03c21e175d317a5344e446c64a4ef0 started to call `IGM.finalize()`, which leads the Clang instance to emit ObjC metadata sections when the ObjC interop is enabled. Emitting ObjC metadata sections is not well supported on non-Darwin platforms and causes crashes for WebAssembly and COFF object formats[^1]. modulewrap tool did not configure the ObjC interop option, so it always enabled the ObjC interop. This patch aligns the default ObjC interop value with other tools by disabling it on non-Darwin platforms. [^1]: https://github.com/apple/llvm-project/blob/stable/20230725/clang/lib/CodeGen/CGObjCMac.cpp#L5068-L5074 --- lib/DriverTool/modulewrap_main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/DriverTool/modulewrap_main.cpp b/lib/DriverTool/modulewrap_main.cpp index 3bce40120d04..f918613db0ea 100644 --- a/lib/DriverTool/modulewrap_main.cpp +++ b/lib/DriverTool/modulewrap_main.cpp @@ -48,6 +48,7 @@ class ModuleWrapInvocation { llvm::Triple TargetTriple; std::vector InputFilenames; bool UseSharedResourceFolder = true; + bool EnableObjCInterop = true; public: bool hasSingleInput() const { return InputFilenames.size() == 1; } @@ -65,6 +66,7 @@ class ModuleWrapInvocation { llvm::Triple &getTargetTriple() { return TargetTriple; } bool useSharedResourceFolder() { return UseSharedResourceFolder; } + bool enableObjCInterop() { return EnableObjCInterop; } int parseArgs(llvm::ArrayRef Args, DiagnosticEngine &Diags) { using namespace options; @@ -124,6 +126,9 @@ class ModuleWrapInvocation { UseSharedResourceFolder = false; } + EnableObjCInterop = ParsedArgs.hasFlag(OPT_enable_objc_interop, + OPT_disable_objc_interop, TargetTriple.isOSDarwin()); + return 0; } }; @@ -184,6 +189,7 @@ int modulewrap_main(ArrayRef Args, const char *Argv0, symbolgraphgen::SymbolGraphOptions SymbolGraphOpts; CASOptions CASOpts; LangOpts.Target = Invocation.getTargetTriple(); + LangOpts.EnableObjCInterop = Invocation.enableObjCInterop(); ASTContext &ASTCtx = *ASTContext::get( LangOpts, TypeCheckOpts, SILOpts, SearchPathOpts, ClangImporterOpts, SymbolGraphOpts, CASOpts, SrcMgr, Instance.getDiags(),