mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 11:38:21 +02:00
Fixed missing unwind tables in main, which broke SEH catching
This commit is contained in:
parent
5b34fb1948
commit
235a3c6f62
4 changed files with 23 additions and 11 deletions
|
@ -621,6 +621,7 @@ BfIRFunction BfCompiler::CreateLoadSharedLibraries(BfVDataModule* bfModule, Arra
|
|||
SmallVector<BfIRType, 2> paramTypes;
|
||||
auto loadSharedLibrariesFuncType = bfModule->mBfIRBuilder->CreateFunctionType(voidType, paramTypes, false);
|
||||
auto loadSharedLibFunc = bfModule->mBfIRBuilder->CreateFunction(loadSharedLibrariesFuncType, BfIRLinkageType_External, "BfLoadSharedLibraries");
|
||||
bfModule->SetupIRMethod(NULL, loadSharedLibFunc, false);
|
||||
|
||||
bfModule->mBfIRBuilder->SetActiveFunction(loadSharedLibFunc);
|
||||
auto entryBlock = bfModule->mBfIRBuilder->CreateBlock("entry", true);
|
||||
|
@ -1544,6 +1545,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
|
|||
SmallVector<BfIRType, 2> paramTypes;
|
||||
auto dtorFuncType = bfModule->mBfIRBuilder->CreateFunctionType(voidType, paramTypes, false);
|
||||
dtorFunc = bfModule->mBfIRBuilder->CreateFunction(dtorFuncType, BfIRLinkageType_External, "BfCallAllStaticDtors");
|
||||
bfModule->SetupIRMethod(NULL, dtorFunc, false);
|
||||
bfModule->mBfIRBuilder->SetActiveFunction(dtorFunc);
|
||||
auto entryBlock = bfModule->mBfIRBuilder->CreateBlock("entry", true);
|
||||
bfModule->mBfIRBuilder->SetInsertPoint(entryBlock);
|
||||
|
@ -1582,6 +1584,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
|
|||
paramTypes.push_back(nullPtrType);
|
||||
mainFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false);
|
||||
mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "main");
|
||||
bfModule->SetupIRMethod(NULL, mainFunc, false);
|
||||
}
|
||||
else if (project->mTargetType == BfTargetType_BeefDynLib)
|
||||
{
|
||||
|
@ -1593,6 +1596,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
|
|||
mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "DllMain");
|
||||
if (mSystem->mPtrSize == 4)
|
||||
bfModule->mBfIRBuilder->SetFuncCallingConv(mainFunc, BfIRCallingConv_StdCall);
|
||||
bfModule->SetupIRMethod(NULL, mainFunc, false);
|
||||
}
|
||||
else if (project->mTargetType == BfTargetType_BeefWindowsApplication)
|
||||
{
|
||||
|
@ -1605,6 +1609,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
|
|||
mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "WinMain");
|
||||
if (mSystem->mPtrSize == 4)
|
||||
bfModule->mBfIRBuilder->SetFuncCallingConv(mainFunc, BfIRCallingConv_StdCall);
|
||||
bfModule->SetupIRMethod(NULL, mainFunc, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1613,6 +1618,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
|
|||
paramTypes.push_back(nullPtrType);
|
||||
mainFuncType = bfModule->mBfIRBuilder->CreateFunctionType(voidType, paramTypes, false);
|
||||
mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "BeefMain");
|
||||
bfModule->SetupIRMethod(NULL, mainFunc, false);
|
||||
}
|
||||
|
||||
bfModule->mBfIRBuilder->SetActiveFunction(mainFunc);
|
||||
|
@ -1627,6 +1633,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
|
|||
auto setCmdLineFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false);
|
||||
|
||||
auto setCmdLineFunc = bfModule->mBfIRBuilder->CreateFunction(setCmdLineFuncType, BfIRLinkageType_External, "BfpSystem_SetCommandLine");
|
||||
bfModule->SetupIRMethod(NULL, setCmdLineFunc, false);
|
||||
|
||||
SmallVector<BfIRValue, 2> args;
|
||||
args.push_back(bfModule->mBfIRBuilder->GetArgument(0));
|
||||
|
@ -1775,6 +1782,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
|
|||
BfIRFunctionType thunkFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false);
|
||||
|
||||
BfIRFunction thunkMainFunc = bfModule->mBfIRBuilder->CreateFunction(thunkFuncType, BfIRLinkageType_External, "BeefMain");
|
||||
bfModule->SetupIRMethod(NULL, thunkMainFunc, false);
|
||||
bfModule->mBfIRBuilder->SetActiveFunction(thunkMainFunc);
|
||||
|
||||
auto thunkEntryBlock = bfModule->mBfIRBuilder->CreateBlock("entry", true);
|
||||
|
|
|
@ -9717,7 +9717,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
|
|||
SetAndRestoreValue<BfClosureState*> prevClosureState(mModule->mCurMethodState->mClosureState, &closureState);
|
||||
|
||||
if (mModule->HasCompiledOutput())
|
||||
mModule->SetupLLVMMethod(methodInstance, methodInstance->mIRFunction, methodInstance->mAlwaysInline);
|
||||
mModule->SetupIRMethod(methodInstance, methodInstance->mIRFunction, methodInstance->mAlwaysInline);
|
||||
|
||||
// This keeps us from giving errors twice. ProcessMethod can give errors when we capture by value but needed to
|
||||
// capture by reference, so we still need to do it for resolve-only
|
||||
|
|
|
@ -8523,7 +8523,7 @@ BfIRValue BfModule::CreateFunctionFrom(BfMethodInstance* methodInstance, bool tr
|
|||
auto callingConv = GetCallingConvention(methodInstance->GetOwner(), methodDef);
|
||||
if (callingConv != BfIRCallingConv_CDecl)
|
||||
mBfIRBuilder->SetFuncCallingConv(func, callingConv);
|
||||
SetupLLVMMethod(methodInstance, func, isInlined);
|
||||
SetupIRMethod(methodInstance, func, isInlined);
|
||||
|
||||
// auto srcModule = methodInstance->GetOwner()->GetModule();
|
||||
// if ((srcModule != NULL) && (srcModule->mProject != mProject))
|
||||
|
@ -13588,24 +13588,28 @@ BfIRCallingConv BfModule::GetCallingConvention(BfMethodInstance* methodInstance)
|
|||
return GetCallingConvention(methodInstance->GetOwner(), methodInstance->mMethodDef);
|
||||
}
|
||||
|
||||
void BfModule::SetupLLVMMethod(BfMethodInstance* methodInstance, BfIRFunction func, bool isInlined)
|
||||
void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func, bool isInlined)
|
||||
{
|
||||
auto methodDef = methodInstance->mMethodDef;
|
||||
BfMethodDef* methodDef = NULL;
|
||||
if (methodInstance != NULL)
|
||||
methodDef = methodInstance->mMethodDef;
|
||||
|
||||
if (!func)
|
||||
return;
|
||||
|
||||
if (mCompiler->mOptions.mNoFramePointerElim)
|
||||
mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_NoFramePointerElim);
|
||||
if (methodDef->mImportKind == BfImportKind_Export)
|
||||
mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_DllExport);
|
||||
|
||||
mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_NoUnwind);
|
||||
if (mSystem->mPtrSize == 8) // We need unwind info for debugging
|
||||
mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_UWTable);
|
||||
|
||||
if (methodInstance == NULL)
|
||||
return;
|
||||
|
||||
if (methodDef->mImportKind == BfImportKind_Export)
|
||||
mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_DllExport);
|
||||
if (methodDef->mNoReturn)
|
||||
mBfIRBuilder->Func_AddAttribute(func, -1, BfIRAttribute_NoReturn);
|
||||
|
||||
auto callingConv = GetCallingConvention(methodInstance->GetOwner(), methodDef);
|
||||
if (callingConv != BfIRCallingConv_CDecl)
|
||||
mBfIRBuilder->SetFuncCallingConv(func, callingConv);
|
||||
|
@ -18313,7 +18317,7 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man
|
|||
*outIsIntrinsic = isIntrinsic;
|
||||
|
||||
if (!isIntrinsic)
|
||||
SetupLLVMMethod(methodInstance, methodInstance->mIRFunction, methodInstance->mAlwaysInline);
|
||||
SetupIRMethod(methodInstance, methodInstance->mIRFunction, methodInstance->mAlwaysInline);
|
||||
}
|
||||
|
||||
void BfModule::CheckHotMethod(BfMethodInstance* methodInstance, const StringImpl& inMangledName)
|
||||
|
|
|
@ -1678,7 +1678,7 @@ public:
|
|||
void CreateDllImportMethod();
|
||||
BfIRCallingConv GetCallingConvention(BfTypeInstance* typeInst, BfMethodDef* methodDef);
|
||||
BfIRCallingConv GetCallingConvention(BfMethodInstance* methodInstance);
|
||||
void SetupLLVMMethod(BfMethodInstance* methodInstance, BfIRFunction func, bool isInlined);
|
||||
void SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func, bool isInlined);
|
||||
void EmitCtorBody(bool& skipBody);
|
||||
void EmitDtorBody();
|
||||
void EmitEnumToStringBody();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue