https://github.com/hmelder updated https://github.com/llvm/llvm-project/pull/169043
>From a07542b0e2274e36a9276ce034697ebcd0d0fee8 Mon Sep 17 00:00:00 2001 From: hmelder <[email protected]> Date: Fri, 21 Nov 2025 10:42:47 +0000 Subject: [PATCH 1/4] [clang] Whitelist wasm when targeting GNUstep 2.x --- clang/lib/Driver/ToolChains/Clang.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 30d3e5293a31b..6cbec5e17ae1a 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -8001,7 +8001,8 @@ ObjCRuntime Clang::AddObjCRuntimeArgs(const ArgList &args, if ((runtime.getKind() == ObjCRuntime::GNUstep) && (runtime.getVersion() >= VersionTuple(2, 0))) if (!getToolChain().getTriple().isOSBinFormatELF() && - !getToolChain().getTriple().isOSBinFormatCOFF()) { + !getToolChain().getTriple().isOSBinFormatCOFF() && + !getToolChain().getTriple().isOSBinFormatWasm()) { getToolChain().getDriver().Diag( diag::err_drv_gnustep_objc_runtime_incompatible_binary) << runtime.getVersion().getMajor(); >From 28a271d46318f7532e2662933de6fb0f5f694b7b Mon Sep 17 00:00:00 2001 From: hmelder <[email protected]> Date: Fri, 21 Nov 2025 10:50:35 +0000 Subject: [PATCH 2/4] [CodeGen][ObjC] Mangle public symbols for wasm Emscripten requires that exported symbols. See https://github.com/emscripten-core/emscripten/pull/23563. --- clang/lib/CodeGen/CGObjCGNU.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp index 06643d4bdc211..4f4149d1d7cd3 100644 --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -179,8 +179,15 @@ class CGObjCGNU : public CGObjCRuntime { (R.getVersion() >= VersionTuple(major, minor)); } - std::string ManglePublicSymbol(StringRef Name) { - return (StringRef(CGM.getTriple().isOSBinFormatCOFF() ? "$_" : "._") + Name).str(); + const std::string ManglePublicSymbol(StringRef Name) { + StringRef prefix = "._"; + + // Exported symbols in Emscripten must be a valid Javascript identifier. + auto triple = CGM.getTriple(); + if (triple.isOSBinFormatCOFF() || triple.isOSBinFormatWasm()) { + prefix = "$_"; + return (prefix + Name).str(); + } } std::string SymbolForProtocol(Twine Name) { >From fd226825c0c2816b693eae756970d811a7abc83e Mon Sep 17 00:00:00 2001 From: hmelder <[email protected]> Date: Fri, 21 Nov 2025 13:04:33 +0000 Subject: [PATCH 3/4] [CodeGen][ObjC] Fix class_registerAlias_np signature --- clang/lib/CodeGen/CGObjCGNU.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp index 4f4149d1d7cd3..a9f2411d86ef2 100644 --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -4113,8 +4113,7 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() { if (!ClassAliases.empty()) { llvm::Type *ArgTypes[2] = {PtrTy, PtrToInt8Ty}; llvm::FunctionType *RegisterAliasTy = - llvm::FunctionType::get(Builder.getVoidTy(), - ArgTypes, false); + llvm::FunctionType::get(BoolTy, ArgTypes, false); llvm::Function *RegisterAlias = llvm::Function::Create( RegisterAliasTy, llvm::GlobalValue::ExternalWeakLinkage, "class_registerAlias_np", >From 002c4e078cc40c19892c6f953cf5330c1e15c3cf Mon Sep 17 00:00:00 2001 From: hmelder <[email protected]> Date: Fri, 28 Nov 2025 16:28:35 +0000 Subject: [PATCH 4/4] [CodeGen][ObjC] Add WASM symbol mangling test --- .../CodeGenObjC/gnustep2-wasm32-symbols.m | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 clang/test/CodeGenObjC/gnustep2-wasm32-symbols.m diff --git a/clang/test/CodeGenObjC/gnustep2-wasm32-symbols.m b/clang/test/CodeGenObjC/gnustep2-wasm32-symbols.m new file mode 100644 index 0000000000000..7da73b8f1903e --- /dev/null +++ b/clang/test/CodeGenObjC/gnustep2-wasm32-symbols.m @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -triple wasm32-unknown-emscripten -emit-llvm -fobjc-runtime=gnustep-2.2 -o - %s | FileCheck %s + +@class NSString; + +@protocol AProtocol +- (void) meth; +@end + +@interface AClass <AProtocol> +@end + +@implementation AClass +- (void) meth {} +@end + +// Make sure that all public symbols are mangled correctly. All exported symbols +// must be valid Javascript identifiers in Emscripten. +// CHECK: $"$_OBJC_PROTOCOL_AProtocol" = comdat any +// CHECK: @"$_OBJC_METACLASS_AClass" +// CHECK: @"$_OBJC_PROTOCOL_AProtocol" +// CHECK: @"$_OBJC_CLASS_AClass" +// CHECK: @"$_OBJC_REF_CLASS_AClass" +// CHECK: @"$_OBJC_INIT_CLASS_AClass" _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
