[PATCH] D75277: [WebAssembly] Remove restriction on main name mangling
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG47039a1a4b29: [WebAssembly] Remove restriction on main name mangling (authored by sbc100). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75277/new/ https://reviews.llvm.org/D75277 Files: clang/lib/AST/Mangle.cpp clang/lib/CodeGen/CodeGenModule.cpp Index: clang/lib/CodeGen/CodeGenModule.cpp === --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -554,10 +554,8 @@ CodeGenFunction(*this).EmitCfiCheckStub(); } emitAtAvailableLinkGuard(); - if (Context.getTargetInfo().getTriple().isWasm() && - !Context.getTargetInfo().getTriple().isOSEmscripten()) { + if (Context.getTargetInfo().getTriple().isWasm()) EmitMainVoidAlias(); - } if (getTriple().isAMDGPU()) { // Emit reference of __amdgpu_device_library_preserve_asan_functions to @@ -6352,8 +6350,10 @@ // new-style no-argument main is in used. if (llvm::Function *F = getModule().getFunction("main")) { if (!F->isDeclaration() && F->arg_size() == 0 && !F->isVarArg() && -F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) - addUsedGlobal(llvm::GlobalAlias::create("__main_void", F)); + F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) { + auto *GA = llvm::GlobalAlias::create("__main_void", F); + GA->setVisibility(llvm::GlobalValue::HiddenVisibility); +} } } Index: clang/lib/AST/Mangle.cpp === --- clang/lib/AST/Mangle.cpp +++ clang/lib/AST/Mangle.cpp @@ -70,9 +70,7 @@ // On wasm, the argc/argv form of "main" is renamed so that the startup code // can call it with the correct function signature. - // On Emscripten, users may be exporting "main" and expecting to call it - // themselves, so we can't mangle it. - if (Triple.isWasm() && !Triple.isOSEmscripten()) + if (Triple.isWasm()) if (const FunctionDecl *FD = dyn_cast(ND)) if (FD->isMain() && FD->hasPrototype() && FD->param_size() == 2) return CCM_WasmMainArgcArgv; Index: clang/lib/CodeGen/CodeGenModule.cpp === --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -554,10 +554,8 @@ CodeGenFunction(*this).EmitCfiCheckStub(); } emitAtAvailableLinkGuard(); - if (Context.getTargetInfo().getTriple().isWasm() && - !Context.getTargetInfo().getTriple().isOSEmscripten()) { + if (Context.getTargetInfo().getTriple().isWasm()) EmitMainVoidAlias(); - } if (getTriple().isAMDGPU()) { // Emit reference of __amdgpu_device_library_preserve_asan_functions to @@ -6352,8 +6350,10 @@ // new-style no-argument main is in used. if (llvm::Function *F = getModule().getFunction("main")) { if (!F->isDeclaration() && F->arg_size() == 0 && !F->isVarArg() && -F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) - addUsedGlobal(llvm::GlobalAlias::create("__main_void", F)); +F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) { + auto *GA = llvm::GlobalAlias::create("__main_void", F); + GA->setVisibility(llvm::GlobalValue::HiddenVisibility); +} } } Index: clang/lib/AST/Mangle.cpp === --- clang/lib/AST/Mangle.cpp +++ clang/lib/AST/Mangle.cpp @@ -70,9 +70,7 @@ // On wasm, the argc/argv form of "main" is renamed so that the startup code // can call it with the correct function signature. - // On Emscripten, users may be exporting "main" and expecting to call it - // themselves, so we can't mangle it. - if (Triple.isWasm() && !Triple.isOSEmscripten()) + if (Triple.isWasm()) if (const FunctionDecl *FD = dyn_cast(ND)) if (FD->isMain() && FD->hasPrototype() && FD->param_size() == 2) return CCM_WasmMainArgcArgv; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D75277: [WebAssembly] Remove restriction on main name mangling
sbc100 added inline comments. Comment at: clang/lib/CodeGen/CodeGenModule.cpp:6360 + auto *GA = llvm::GlobalAlias::create("__main_void", F); + GA->setVisibility(F->getVisibility()); +} sbc100 wrote: > sunfish wrote: > > sbc100 wrote: > > > sunfish wrote: > > > > Can this use `GA->setVisibility(GlobalValue::HiddenVisibility)`? > > > > `__main_void` is an implementation detail, so in theory users shouldn't > > > > be setting interesting visibility attributes on it. > > > The caller main / __main_void could live in different shared library the > > > main function itself. > > > > > > IIRC the caller of `main` is normally something like crt1.o and it should > > > be able to see `__main_void` if, and only if, it can see `main`. i.e. if > > > should have the same visibility as main itself, no? > > Typically crt1.o is linked into the same exe/dso as `main`, so it needs > > `main` to have external linkage, but it doesn't need `main` to have any > > particular visibility. > > > > In Emscripten, is `main` being called from a different dso, or from JS > > following visibility rules for different dsos? > No, emscirpten is not different that respect. Typically main lives in the > same DSO as crt1.o. > > But it doesn't have to, and we have a few tests that check it can be in a > separate dso. Actually I think verified that setting this to hidden works for emscripten (at least the tests pass). @sunfish.. do you know if you were relying on this symbols being marked as "used"? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75277/new/ https://reviews.llvm.org/D75277 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D75277: [WebAssembly] Remove restriction on main name mangling
sbc100 updated this revision to Diff 434605. sbc100 added a comment. - rebase Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75277/new/ https://reviews.llvm.org/D75277 Files: clang/lib/AST/Mangle.cpp clang/lib/CodeGen/CodeGenModule.cpp Index: clang/lib/CodeGen/CodeGenModule.cpp === --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -554,10 +554,8 @@ CodeGenFunction(*this).EmitCfiCheckStub(); } emitAtAvailableLinkGuard(); - if (Context.getTargetInfo().getTriple().isWasm() && - !Context.getTargetInfo().getTriple().isOSEmscripten()) { + if (Context.getTargetInfo().getTriple().isWasm()) EmitMainVoidAlias(); - } if (getTriple().isAMDGPU()) { // Emit reference of __amdgpu_device_library_preserve_asan_functions to @@ -6352,8 +6350,10 @@ // new-style no-argument main is in used. if (llvm::Function *F = getModule().getFunction("main")) { if (!F->isDeclaration() && F->arg_size() == 0 && !F->isVarArg() && -F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) - addUsedGlobal(llvm::GlobalAlias::create("__main_void", F)); + F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) { + auto *GA = llvm::GlobalAlias::create("__main_void", F); + GA->setVisibility(llvm::GlobalValue::HiddenVisibility); +} } } Index: clang/lib/AST/Mangle.cpp === --- clang/lib/AST/Mangle.cpp +++ clang/lib/AST/Mangle.cpp @@ -70,9 +70,7 @@ // On wasm, the argc/argv form of "main" is renamed so that the startup code // can call it with the correct function signature. - // On Emscripten, users may be exporting "main" and expecting to call it - // themselves, so we can't mangle it. - if (Triple.isWasm() && !Triple.isOSEmscripten()) + if (Triple.isWasm()) if (const FunctionDecl *FD = dyn_cast(ND)) if (FD->isMain() && FD->hasPrototype() && FD->param_size() == 2) return CCM_WasmMainArgcArgv; Index: clang/lib/CodeGen/CodeGenModule.cpp === --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -554,10 +554,8 @@ CodeGenFunction(*this).EmitCfiCheckStub(); } emitAtAvailableLinkGuard(); - if (Context.getTargetInfo().getTriple().isWasm() && - !Context.getTargetInfo().getTriple().isOSEmscripten()) { + if (Context.getTargetInfo().getTriple().isWasm()) EmitMainVoidAlias(); - } if (getTriple().isAMDGPU()) { // Emit reference of __amdgpu_device_library_preserve_asan_functions to @@ -6352,8 +6350,10 @@ // new-style no-argument main is in used. if (llvm::Function *F = getModule().getFunction("main")) { if (!F->isDeclaration() && F->arg_size() == 0 && !F->isVarArg() && -F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) - addUsedGlobal(llvm::GlobalAlias::create("__main_void", F)); +F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) { + auto *GA = llvm::GlobalAlias::create("__main_void", F); + GA->setVisibility(llvm::GlobalValue::HiddenVisibility); +} } } Index: clang/lib/AST/Mangle.cpp === --- clang/lib/AST/Mangle.cpp +++ clang/lib/AST/Mangle.cpp @@ -70,9 +70,7 @@ // On wasm, the argc/argv form of "main" is renamed so that the startup code // can call it with the correct function signature. - // On Emscripten, users may be exporting "main" and expecting to call it - // themselves, so we can't mangle it. - if (Triple.isWasm() && !Triple.isOSEmscripten()) + if (Triple.isWasm()) if (const FunctionDecl *FD = dyn_cast(ND)) if (FD->isMain() && FD->hasPrototype() && FD->param_size() == 2) return CCM_WasmMainArgcArgv; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D75277: [WebAssembly] Remove restriction on main name mangling
sbc100 updated this revision to Diff 433386. sbc100 added a comment. - feedback Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75277/new/ https://reviews.llvm.org/D75277 Files: clang/lib/AST/Mangle.cpp clang/lib/CodeGen/CodeGenModule.cpp Index: clang/lib/CodeGen/CodeGenModule.cpp === --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -555,10 +555,8 @@ CodeGenFunction(*this).EmitCfiCheckStub(); } emitAtAvailableLinkGuard(); - if (Context.getTargetInfo().getTriple().isWasm() && - !Context.getTargetInfo().getTriple().isOSEmscripten()) { + if (Context.getTargetInfo().getTriple().isWasm()) EmitMainVoidAlias(); - } if (getTriple().isAMDGPU()) { // Emit reference of __amdgpu_device_library_preserve_asan_functions to @@ -6357,8 +6355,10 @@ // new-style no-argument main is in used. if (llvm::Function *F = getModule().getFunction("main")) { if (!F->isDeclaration() && F->arg_size() == 0 && !F->isVarArg() && -F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) - addUsedGlobal(llvm::GlobalAlias::create("__main_void", F)); + F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) { + auto *GA = llvm::GlobalAlias::create("__main_void", F); + GA->setVisibility(llvm::GlobalValue::HiddenVisibility); +} } } Index: clang/lib/AST/Mangle.cpp === --- clang/lib/AST/Mangle.cpp +++ clang/lib/AST/Mangle.cpp @@ -70,9 +70,7 @@ // On wasm, the argc/argv form of "main" is renamed so that the startup code // can call it with the correct function signature. - // On Emscripten, users may be exporting "main" and expecting to call it - // themselves, so we can't mangle it. - if (Triple.isWasm() && !Triple.isOSEmscripten()) + if (Triple.isWasm()) if (const FunctionDecl *FD = dyn_cast(ND)) if (FD->isMain() && FD->hasPrototype() && FD->param_size() == 2) return CCM_WasmMainArgcArgv; Index: clang/lib/CodeGen/CodeGenModule.cpp === --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -555,10 +555,8 @@ CodeGenFunction(*this).EmitCfiCheckStub(); } emitAtAvailableLinkGuard(); - if (Context.getTargetInfo().getTriple().isWasm() && - !Context.getTargetInfo().getTriple().isOSEmscripten()) { + if (Context.getTargetInfo().getTriple().isWasm()) EmitMainVoidAlias(); - } if (getTriple().isAMDGPU()) { // Emit reference of __amdgpu_device_library_preserve_asan_functions to @@ -6357,8 +6355,10 @@ // new-style no-argument main is in used. if (llvm::Function *F = getModule().getFunction("main")) { if (!F->isDeclaration() && F->arg_size() == 0 && !F->isVarArg() && -F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) - addUsedGlobal(llvm::GlobalAlias::create("__main_void", F)); +F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) { + auto *GA = llvm::GlobalAlias::create("__main_void", F); + GA->setVisibility(llvm::GlobalValue::HiddenVisibility); +} } } Index: clang/lib/AST/Mangle.cpp === --- clang/lib/AST/Mangle.cpp +++ clang/lib/AST/Mangle.cpp @@ -70,9 +70,7 @@ // On wasm, the argc/argv form of "main" is renamed so that the startup code // can call it with the correct function signature. - // On Emscripten, users may be exporting "main" and expecting to call it - // themselves, so we can't mangle it. - if (Triple.isWasm() && !Triple.isOSEmscripten()) + if (Triple.isWasm()) if (const FunctionDecl *FD = dyn_cast(ND)) if (FD->isMain() && FD->hasPrototype() && FD->param_size() == 2) return CCM_WasmMainArgcArgv; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D75277: [WebAssembly] Remove restriction on main name mangling
sbc100 added inline comments. Comment at: clang/lib/CodeGen/CodeGenModule.cpp:6360 + auto *GA = llvm::GlobalAlias::create("__main_void", F); + GA->setVisibility(F->getVisibility()); +} sunfish wrote: > sbc100 wrote: > > sunfish wrote: > > > Can this use `GA->setVisibility(GlobalValue::HiddenVisibility)`? > > > `__main_void` is an implementation detail, so in theory users shouldn't > > > be setting interesting visibility attributes on it. > > The caller main / __main_void could live in different shared library the > > main function itself. > > > > IIRC the caller of `main` is normally something like crt1.o and it should > > be able to see `__main_void` if, and only if, it can see `main`. i.e. if > > should have the same visibility as main itself, no? > Typically crt1.o is linked into the same exe/dso as `main`, so it needs > `main` to have external linkage, but it doesn't need `main` to have any > particular visibility. > > In Emscripten, is `main` being called from a different dso, or from JS > following visibility rules for different dsos? No, emscirpten is not different that respect. Typically main lives in the same DSO as crt1.o. But it doesn't have to, and we have a few tests that check it can be in a separate dso. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75277/new/ https://reviews.llvm.org/D75277 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D75277: [WebAssembly] Remove restriction on main name mangling
sunfish added inline comments. Comment at: clang/lib/CodeGen/CodeGenModule.cpp:6360 + auto *GA = llvm::GlobalAlias::create("__main_void", F); + GA->setVisibility(F->getVisibility()); +} sbc100 wrote: > sunfish wrote: > > Can this use `GA->setVisibility(GlobalValue::HiddenVisibility)`? > > `__main_void` is an implementation detail, so in theory users shouldn't be > > setting interesting visibility attributes on it. > The caller main / __main_void could live in different shared library the main > function itself. > > IIRC the caller of `main` is normally something like crt1.o and it should be > able to see `__main_void` if, and only if, it can see `main`. i.e. if should > have the same visibility as main itself, no? Typically crt1.o is linked into the same exe/dso as `main`, so it needs `main` to have external linkage, but it doesn't need `main` to have any particular visibility. In Emscripten, is `main` being called from a different dso, or from JS following visibility rules for different dsos? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75277/new/ https://reviews.llvm.org/D75277 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D75277: [WebAssembly] Remove restriction on main name mangling
sbc100 added inline comments. Comment at: clang/lib/CodeGen/CodeGenModule.cpp:6360 + auto *GA = llvm::GlobalAlias::create("__main_void", F); + GA->setVisibility(F->getVisibility()); +} sunfish wrote: > Can this use `GA->setVisibility(GlobalValue::HiddenVisibility)`? > `__main_void` is an implementation detail, so in theory users shouldn't be > setting interesting visibility attributes on it. The caller main / __main_void could live in different shared library the main function itself. IIRC the caller of `main` is normally something like crt1.o and it should be able to see `__main_void` if, and only if, it can see `main`. i.e. if should have the same visibility as main itself, no? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75277/new/ https://reviews.llvm.org/D75277 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D75277: [WebAssembly] Remove restriction on main name mangling
sunfish added inline comments. Comment at: clang/lib/CodeGen/CodeGenModule.cpp:6360 + auto *GA = llvm::GlobalAlias::create("__main_void", F); + GA->setVisibility(F->getVisibility()); +} Can this use `GA->setVisibility(GlobalValue::HiddenVisibility)`? `__main_void` is an implementation detail, so in theory users shouldn't be setting interesting visibility attributes on it. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75277/new/ https://reviews.llvm.org/D75277 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D75277: [WebAssembly] Remove restriction on main name mangling
sbc100 updated this revision to Diff 433191. sbc100 added a comment. - revert parts Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75277/new/ https://reviews.llvm.org/D75277 Files: clang/lib/AST/Mangle.cpp clang/lib/CodeGen/CodeGenModule.cpp Index: clang/lib/CodeGen/CodeGenModule.cpp === --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -555,10 +555,8 @@ CodeGenFunction(*this).EmitCfiCheckStub(); } emitAtAvailableLinkGuard(); - if (Context.getTargetInfo().getTriple().isWasm() && - !Context.getTargetInfo().getTriple().isOSEmscripten()) { + if (Context.getTargetInfo().getTriple().isWasm()) EmitMainVoidAlias(); - } if (getTriple().isAMDGPU()) { // Emit reference of __amdgpu_device_library_preserve_asan_functions to @@ -6357,8 +6355,10 @@ // new-style no-argument main is in used. if (llvm::Function *F = getModule().getFunction("main")) { if (!F->isDeclaration() && F->arg_size() == 0 && !F->isVarArg() && -F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) - addUsedGlobal(llvm::GlobalAlias::create("__main_void", F)); + F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) { + auto *GA = llvm::GlobalAlias::create("__main_void", F); + GA->setVisibility(F->getVisibility()); +} } } Index: clang/lib/AST/Mangle.cpp === --- clang/lib/AST/Mangle.cpp +++ clang/lib/AST/Mangle.cpp @@ -70,9 +70,7 @@ // On wasm, the argc/argv form of "main" is renamed so that the startup code // can call it with the correct function signature. - // On Emscripten, users may be exporting "main" and expecting to call it - // themselves, so we can't mangle it. - if (Triple.isWasm() && !Triple.isOSEmscripten()) + if (Triple.isWasm()) if (const FunctionDecl *FD = dyn_cast(ND)) if (FD->isMain() && FD->hasPrototype() && FD->param_size() == 2) return CCM_WasmMainArgcArgv; Index: clang/lib/CodeGen/CodeGenModule.cpp === --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -555,10 +555,8 @@ CodeGenFunction(*this).EmitCfiCheckStub(); } emitAtAvailableLinkGuard(); - if (Context.getTargetInfo().getTriple().isWasm() && - !Context.getTargetInfo().getTriple().isOSEmscripten()) { + if (Context.getTargetInfo().getTriple().isWasm()) EmitMainVoidAlias(); - } if (getTriple().isAMDGPU()) { // Emit reference of __amdgpu_device_library_preserve_asan_functions to @@ -6357,8 +6355,10 @@ // new-style no-argument main is in used. if (llvm::Function *F = getModule().getFunction("main")) { if (!F->isDeclaration() && F->arg_size() == 0 && !F->isVarArg() && -F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) - addUsedGlobal(llvm::GlobalAlias::create("__main_void", F)); +F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) { + auto *GA = llvm::GlobalAlias::create("__main_void", F); + GA->setVisibility(F->getVisibility()); +} } } Index: clang/lib/AST/Mangle.cpp === --- clang/lib/AST/Mangle.cpp +++ clang/lib/AST/Mangle.cpp @@ -70,9 +70,7 @@ // On wasm, the argc/argv form of "main" is renamed so that the startup code // can call it with the correct function signature. - // On Emscripten, users may be exporting "main" and expecting to call it - // themselves, so we can't mangle it. - if (Triple.isWasm() && !Triple.isOSEmscripten()) + if (Triple.isWasm()) if (const FunctionDecl *FD = dyn_cast(ND)) if (FD->isMain() && FD->hasPrototype() && FD->param_size() == 2) return CCM_WasmMainArgcArgv; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D75277: [WebAssembly] Remove restriction on main name mangling
sbc100 added inline comments. Comment at: llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp:264 - } -} } sunfish wrote: > Why is this code going away? This isn't Emscripten-specific code. Ah.. I was hoping we could delete these codepaths, but maybe not.. :( Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75277/new/ https://reviews.llvm.org/D75277 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D75277: [WebAssembly] Remove restriction on main name mangling
sunfish added inline comments. Comment at: llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp:264 - } -} } Why is this code going away? This isn't Emscripten-specific code. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75277/new/ https://reviews.llvm.org/D75277 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D75277: [WebAssembly] Remove restriction on main name mangling
sbc100 updated this revision to Diff 433173. sbc100 added a comment. - update Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75277/new/ https://reviews.llvm.org/D75277 Files: clang/lib/AST/Mangle.cpp clang/lib/CodeGen/CodeGenModule.cpp llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp Index: llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp === --- llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp +++ llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp @@ -214,22 +214,9 @@ return Wrapper; } -// Test whether a main function with type FuncTy should be rewritten to have -// type MainTy. -static bool shouldFixMainFunction(FunctionType *FuncTy, FunctionType *MainTy) { - // Only fix the main function if it's the standard zero-arg form. That way, - // the standard cases will work as expected, and users will see signature - // mismatches from the linker for non-standard cases. - return FuncTy->getReturnType() == MainTy->getReturnType() && - FuncTy->getNumParams() == 0 && - !FuncTy->isVarArg(); -} - bool FixFunctionBitcasts::runOnModule(Module &M) { LLVM_DEBUG(dbgs() << "** Fix Function Bitcasts **\n"); - Function *Main = nullptr; - CallInst *CallMain = nullptr; SmallVector, 0> Uses; // Collect all the places that need wrappers. @@ -239,29 +226,6 @@ if (F.getCallingConv() == CallingConv::Swift) continue; findUses(&F, F, Uses); - -// If we have a "main" function, and its type isn't -// "int main(int argc, char *argv[])", create an artificial call with it -// bitcasted to that type so that we generate a wrapper for it, so that -// the C runtime can call it. -if (F.getName() == "main") { - Main = &F; - LLVMContext &C = M.getContext(); - Type *MainArgTys[] = {Type::getInt32Ty(C), -PointerType::get(Type::getInt8PtrTy(C), 0)}; - FunctionType *MainTy = FunctionType::get(Type::getInt32Ty(C), MainArgTys, - /*isVarArg=*/false); - if (shouldFixMainFunction(F.getFunctionType(), MainTy)) { -LLVM_DEBUG(dbgs() << "Found `main` function with incorrect type: " - << *F.getFunctionType() << "\n"); -Value *Args[] = {UndefValue::get(MainArgTys[0]), - UndefValue::get(MainArgTys[1])}; -Value *Casted = -ConstantExpr::getBitCast(Main, PointerType::get(MainTy, 0)); -CallMain = CallInst::Create(MainTy, Casted, Args, "call_main"); -Uses.push_back(std::make_pair(CallMain, &F)); - } -} } DenseMap, Function *> Wrappers; @@ -282,25 +246,5 @@ CB->setCalledOperand(Wrapper); } - // If we created a wrapper for main, rename the wrapper so that it's the - // one that gets called from startup. - if (CallMain) { -Main->setName("__original_main"); -auto *MainWrapper = -cast(CallMain->getCalledOperand()->stripPointerCasts()); -delete CallMain; -if (Main->isDeclaration()) { - // The wrapper is not needed in this case as we don't need to export - // it to anyone else. - MainWrapper->eraseFromParent(); -} else { - // Otherwise give the wrapper the same linkage as the original main - // function, so that it can be called from the same places. - MainWrapper->setName("main"); - MainWrapper->setLinkage(Main->getLinkage()); - MainWrapper->setVisibility(Main->getVisibility()); -} - } - return true; } Index: clang/lib/CodeGen/CodeGenModule.cpp === --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -555,10 +555,8 @@ CodeGenFunction(*this).EmitCfiCheckStub(); } emitAtAvailableLinkGuard(); - if (Context.getTargetInfo().getTriple().isWasm() && - !Context.getTargetInfo().getTriple().isOSEmscripten()) { + if (Context.getTargetInfo().getTriple().isWasm()) EmitMainVoidAlias(); - } if (getTriple().isAMDGPU()) { // Emit reference of __amdgpu_device_library_preserve_asan_functions to @@ -6357,8 +6355,10 @@ // new-style no-argument main is in used. if (llvm::Function *F = getModule().getFunction("main")) { if (!F->isDeclaration() && F->arg_size() == 0 && !F->isVarArg() && -F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) - addUsedGlobal(llvm::GlobalAlias::create("__main_void", F)); +F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) { + auto *GA = llvm::GlobalAlias::create("__main_void", F); + GA->setVisibility(F->getVisibility()); +} } } Index: clang/lib/AST/Mangle.cpp === --- clang/lib/AST/Mangle.cpp +++ clang/lib/AST/Mangle.cpp
[PATCH] D75277: [WebAssembly] Remove restriction on main name mangling
sbc100 added a comment. Currently waiting on https://github.com/emscripten-core/emscripten/pull/17099 to land. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75277/new/ https://reviews.llvm.org/D75277 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D75277: [WebAssembly] Remove restriction on main name mangling
sbc100 updated this revision to Diff 433138. sbc100 added a comment. Herald added subscribers: llvm-commits, asb, hiraditya. Herald added a project: LLVM. - update Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75277/new/ https://reviews.llvm.org/D75277 Files: clang/lib/AST/Mangle.cpp clang/lib/CodeGen/CodeGenModule.cpp llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp Index: llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp === --- llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp +++ llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp @@ -214,22 +214,9 @@ return Wrapper; } -// Test whether a main function with type FuncTy should be rewritten to have -// type MainTy. -static bool shouldFixMainFunction(FunctionType *FuncTy, FunctionType *MainTy) { - // Only fix the main function if it's the standard zero-arg form. That way, - // the standard cases will work as expected, and users will see signature - // mismatches from the linker for non-standard cases. - return FuncTy->getReturnType() == MainTy->getReturnType() && - FuncTy->getNumParams() == 0 && - !FuncTy->isVarArg(); -} - bool FixFunctionBitcasts::runOnModule(Module &M) { LLVM_DEBUG(dbgs() << "** Fix Function Bitcasts **\n"); - Function *Main = nullptr; - CallInst *CallMain = nullptr; SmallVector, 0> Uses; // Collect all the places that need wrappers. @@ -239,29 +226,6 @@ if (F.getCallingConv() == CallingConv::Swift) continue; findUses(&F, F, Uses); - -// If we have a "main" function, and its type isn't -// "int main(int argc, char *argv[])", create an artificial call with it -// bitcasted to that type so that we generate a wrapper for it, so that -// the C runtime can call it. -if (F.getName() == "main") { - Main = &F; - LLVMContext &C = M.getContext(); - Type *MainArgTys[] = {Type::getInt32Ty(C), -PointerType::get(Type::getInt8PtrTy(C), 0)}; - FunctionType *MainTy = FunctionType::get(Type::getInt32Ty(C), MainArgTys, - /*isVarArg=*/false); - if (shouldFixMainFunction(F.getFunctionType(), MainTy)) { -LLVM_DEBUG(dbgs() << "Found `main` function with incorrect type: " - << *F.getFunctionType() << "\n"); -Value *Args[] = {UndefValue::get(MainArgTys[0]), - UndefValue::get(MainArgTys[1])}; -Value *Casted = -ConstantExpr::getBitCast(Main, PointerType::get(MainTy, 0)); -CallMain = CallInst::Create(MainTy, Casted, Args, "call_main"); -Uses.push_back(std::make_pair(CallMain, &F)); - } -} } DenseMap, Function *> Wrappers; @@ -282,25 +246,5 @@ CB->setCalledOperand(Wrapper); } - // If we created a wrapper for main, rename the wrapper so that it's the - // one that gets called from startup. - if (CallMain) { -Main->setName("__original_main"); -auto *MainWrapper = -cast(CallMain->getCalledOperand()->stripPointerCasts()); -delete CallMain; -if (Main->isDeclaration()) { - // The wrapper is not needed in this case as we don't need to export - // it to anyone else. - MainWrapper->eraseFromParent(); -} else { - // Otherwise give the wrapper the same linkage as the original main - // function, so that it can be called from the same places. - MainWrapper->setName("main"); - MainWrapper->setLinkage(Main->getLinkage()); - MainWrapper->setVisibility(Main->getVisibility()); -} - } - return true; } Index: clang/lib/CodeGen/CodeGenModule.cpp === --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -555,10 +555,8 @@ CodeGenFunction(*this).EmitCfiCheckStub(); } emitAtAvailableLinkGuard(); - if (Context.getTargetInfo().getTriple().isWasm() && - !Context.getTargetInfo().getTriple().isOSEmscripten()) { + if (Context.getTargetInfo().getTriple().isWasm()) EmitMainVoidAlias(); - } if (getTriple().isAMDGPU()) { // Emit reference of __amdgpu_device_library_preserve_asan_functions to @@ -6357,8 +6355,10 @@ // new-style no-argument main is in used. if (llvm::Function *F = getModule().getFunction("main")) { if (!F->isDeclaration() && F->arg_size() == 0 && !F->isVarArg() && -F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) - addUsedGlobal(llvm::GlobalAlias::create("__main_void", F)); +F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth())) { + auto *GA = llvm::GlobalAlias::create("__main_void", F); + GA->setVisibility(llvm::GlobalValue::DefaultVisibility); +} } } Index: clang/lib/AST/Mangle.cpp =
[PATCH] D75277: [WebAssembly] Remove restriction on main name mangling
sbc100 created this revision. Herald added subscribers: cfe-commits, sunfish, aheejin, jgravelle-google, dschuff. Herald added a project: clang. Emscripten now handles/supports this new mode. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D75277 Files: clang/lib/AST/Mangle.cpp clang/lib/CodeGen/CodeGenModule.cpp Index: clang/lib/CodeGen/CodeGenModule.cpp === --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -448,10 +448,8 @@ CodeGenFunction(*this).EmitCfiCheckStub(); } emitAtAvailableLinkGuard(); - if (Context.getTargetInfo().getTriple().isWasm() && - !Context.getTargetInfo().getTriple().isOSEmscripten()) { + if (Context.getTargetInfo().getTriple().isWasm()) EmitMainVoidAlias(); - } emitLLVMUsed(); if (SanStats) SanStats->finish(); Index: clang/lib/AST/Mangle.cpp === --- clang/lib/AST/Mangle.cpp +++ clang/lib/AST/Mangle.cpp @@ -67,9 +67,7 @@ // On wasm, the argc/argv form of "main" is renamed so that the startup code // can call it with the correct function signature. - // On Emscripten, users may be exporting "main" and expecting to call it - // themselves, so we can't mangle it. - if (Triple.isWasm() && !Triple.isOSEmscripten()) + if (Triple.isWasm()) if (const FunctionDecl *FD = dyn_cast(ND)) if (FD->isMain() && FD->hasPrototype() && FD->param_size() == 2) return CCM_WasmMainArgcArgv; Index: clang/lib/CodeGen/CodeGenModule.cpp === --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -448,10 +448,8 @@ CodeGenFunction(*this).EmitCfiCheckStub(); } emitAtAvailableLinkGuard(); - if (Context.getTargetInfo().getTriple().isWasm() && - !Context.getTargetInfo().getTriple().isOSEmscripten()) { + if (Context.getTargetInfo().getTriple().isWasm()) EmitMainVoidAlias(); - } emitLLVMUsed(); if (SanStats) SanStats->finish(); Index: clang/lib/AST/Mangle.cpp === --- clang/lib/AST/Mangle.cpp +++ clang/lib/AST/Mangle.cpp @@ -67,9 +67,7 @@ // On wasm, the argc/argv form of "main" is renamed so that the startup code // can call it with the correct function signature. - // On Emscripten, users may be exporting "main" and expecting to call it - // themselves, so we can't mangle it. - if (Triple.isWasm() && !Triple.isOSEmscripten()) + if (Triple.isWasm()) if (const FunctionDecl *FD = dyn_cast(ND)) if (FD->isMain() && FD->hasPrototype() && FD->param_size() == 2) return CCM_WasmMainArgcArgv; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits