@@ -440,22 +440,25 @@ static std::string getSignature(FunctionType *FTy) {
440
440
return Sig;
441
441
}
442
442
443
- static Function *getEmscriptenFunction (FunctionType *Ty, const Twine &Name,
444
- Module *M) {
445
- Function* F = Function::Create (Ty, GlobalValue::ExternalLinkage, Name, M);
443
+ static Function *getFunction (FunctionType *Ty, const Twine &Name, Module *M) {
444
+ return Function::Create (Ty, GlobalValue::ExternalLinkage, Name, M);
445
+ }
446
+
447
+ static void markAsImported (Function *F) {
446
448
// Tell the linker that this function is expected to be imported from the
447
- // 'env' module.
449
+ // 'env' module. This is necessary for functions that do not have fixed names
450
+ // (e.g. __import_xyz). These names cannot be provided by any kind of shared
451
+ // or static library as instead we mark them explictly as imported.
448
452
if (!F->hasFnAttribute (" wasm-import-module" )) {
449
- llvm::AttrBuilder B (M ->getContext ());
453
+ llvm::AttrBuilder B (F-> getParent () ->getContext ());
450
454
B.addAttribute (" wasm-import-module" , " env" );
451
455
F->addFnAttrs (B);
452
456
}
453
457
if (!F->hasFnAttribute (" wasm-import-name" )) {
454
- llvm::AttrBuilder B (M ->getContext ());
458
+ llvm::AttrBuilder B (F-> getParent () ->getContext ());
455
459
B.addAttribute (" wasm-import-name" , F->getName ());
456
460
F->addFnAttrs (B);
457
461
}
458
- return F;
459
462
}
460
463
461
464
// Returns an integer type for the target architecture's address space.
@@ -493,8 +496,9 @@ WebAssemblyLowerEmscriptenEHSjLj::getFindMatchingCatch(Module &M,
493
496
PointerType *Int8PtrTy = PointerType::getUnqual (M.getContext ());
494
497
SmallVector<Type *, 16 > Args (NumClauses, Int8PtrTy);
495
498
FunctionType *FTy = FunctionType::get (Int8PtrTy, Args, false );
496
- Function *F = getEmscriptenFunction (
499
+ Function *F = getFunction (
497
500
FTy, " __cxa_find_matching_catch_" + Twine (NumClauses + 2 ), &M);
501
+ markAsImported (F);
498
502
FindMatchingCatches[NumClauses] = F;
499
503
return F;
500
504
}
@@ -586,7 +590,8 @@ Function *WebAssemblyLowerEmscriptenEHSjLj::getInvokeWrapper(CallBase *CI) {
586
590
587
591
FunctionType *FTy = FunctionType::get (CalleeFTy->getReturnType (), ArgTys,
588
592
CalleeFTy->isVarArg ());
589
- Function *F = getEmscriptenFunction (FTy, " __invoke_" + Sig, M);
593
+ Function *F = getFunction (FTy, " __invoke_" + Sig, M);
594
+ markAsImported (F);
590
595
InvokeWrappers[Sig] = F;
591
596
return F;
592
597
}
@@ -927,11 +932,11 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runOnModule(Module &M) {
927
932
// exception handling and setjmp/longjmp handling
928
933
ThrewGV = getGlobalVariable (M, getAddrIntType (&M), TM, " __THREW__" );
929
934
ThrewValueGV = getGlobalVariable (M, IRB.getInt32Ty (), TM, " __threwValue" );
930
- GetTempRet0F = getEmscriptenFunction (
931
- FunctionType::get (IRB. getInt32Ty (), false ), " getTempRet0" , &M);
932
- SetTempRet0F = getEmscriptenFunction (
933
- FunctionType::get (IRB.getVoidTy (), IRB.getInt32Ty (), false ),
934
- " setTempRet0" , &M);
935
+ GetTempRet0F = getFunction ( FunctionType::get (IRB. getInt32Ty (), false ),
936
+ " getTempRet0" , &M);
937
+ SetTempRet0F =
938
+ getFunction ( FunctionType::get (IRB.getVoidTy (), IRB.getInt32Ty (), false ),
939
+ " setTempRet0" , &M);
935
940
GetTempRet0F->setDoesNotThrow ();
936
941
SetTempRet0F->setDoesNotThrow ();
937
942
@@ -942,13 +947,13 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runOnModule(Module &M) {
942
947
// Register __resumeException function
943
948
FunctionType *ResumeFTy =
944
949
FunctionType::get (IRB.getVoidTy (), IRB.getPtrTy (), false );
945
- ResumeF = getEmscriptenFunction (ResumeFTy, " __resumeException" , &M);
950
+ ResumeF = getFunction (ResumeFTy, " __resumeException" , &M);
946
951
ResumeF->addFnAttr (Attribute::NoReturn);
947
952
948
953
// Register llvm_eh_typeid_for function
949
954
FunctionType *EHTypeIDTy =
950
955
FunctionType::get (IRB.getInt32Ty (), IRB.getPtrTy (), false );
951
- EHTypeIDF = getEmscriptenFunction (EHTypeIDTy, " llvm_eh_typeid_for" , &M);
956
+ EHTypeIDF = getFunction (EHTypeIDTy, " llvm_eh_typeid_for" , &M);
952
957
}
953
958
954
959
// Functions that contains calls to setjmp but don't have other longjmpable
@@ -988,14 +993,14 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runOnModule(Module &M) {
988
993
// Register emscripten_longjmp function
989
994
FunctionType *FTy = FunctionType::get (
990
995
IRB.getVoidTy (), {getAddrIntType (&M), IRB.getInt32Ty ()}, false );
991
- EmLongjmpF = getEmscriptenFunction (FTy, " emscripten_longjmp" , &M);
996
+ EmLongjmpF = getFunction (FTy, " emscripten_longjmp" , &M);
992
997
EmLongjmpF->addFnAttr (Attribute::NoReturn);
993
998
} else { // EnableWasmSjLj
994
999
Type *Int8PtrTy = IRB.getPtrTy ();
995
1000
// Register __wasm_longjmp function, which calls __builtin_wasm_longjmp.
996
1001
FunctionType *FTy = FunctionType::get (
997
1002
IRB.getVoidTy (), {Int8PtrTy, IRB.getInt32Ty ()}, false );
998
- WasmLongjmpF = getEmscriptenFunction (FTy, " __wasm_longjmp" , &M);
1003
+ WasmLongjmpF = getFunction (FTy, " __wasm_longjmp" , &M);
999
1004
WasmLongjmpF->addFnAttr (Attribute::NoReturn);
1000
1005
}
1001
1006
@@ -1009,11 +1014,11 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runOnModule(Module &M) {
1009
1014
FunctionType *FTy = FunctionType::get (
1010
1015
IRB.getVoidTy (), {SetjmpFTy->getParamType (0 ), Int32Ty, Int32PtrTy},
1011
1016
false );
1012
- WasmSetjmpF = getEmscriptenFunction (FTy, " __wasm_setjmp" , &M);
1017
+ WasmSetjmpF = getFunction (FTy, " __wasm_setjmp" , &M);
1013
1018
1014
1019
// Register __wasm_setjmp_test function
1015
1020
FTy = FunctionType::get (Int32Ty, {Int32PtrTy, Int32PtrTy}, false );
1016
- WasmSetjmpTestF = getEmscriptenFunction (FTy, " __wasm_setjmp_test" , &M);
1021
+ WasmSetjmpTestF = getFunction (FTy, " __wasm_setjmp_test" , &M);
1017
1022
1018
1023
// wasm.catch() will be lowered down to wasm 'catch' instruction in
1019
1024
// instruction selection.
0 commit comments