1
0
Fork 0
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:
Brian Fiete 2019-09-26 08:29:34 -07:00
parent 5b34fb1948
commit 235a3c6f62
4 changed files with 23 additions and 11 deletions

View file

@ -621,6 +621,7 @@ BfIRFunction BfCompiler::CreateLoadSharedLibraries(BfVDataModule* bfModule, Arra
SmallVector<BfIRType, 2> paramTypes; SmallVector<BfIRType, 2> paramTypes;
auto loadSharedLibrariesFuncType = bfModule->mBfIRBuilder->CreateFunctionType(voidType, paramTypes, false); auto loadSharedLibrariesFuncType = bfModule->mBfIRBuilder->CreateFunctionType(voidType, paramTypes, false);
auto loadSharedLibFunc = bfModule->mBfIRBuilder->CreateFunction(loadSharedLibrariesFuncType, BfIRLinkageType_External, "BfLoadSharedLibraries"); auto loadSharedLibFunc = bfModule->mBfIRBuilder->CreateFunction(loadSharedLibrariesFuncType, BfIRLinkageType_External, "BfLoadSharedLibraries");
bfModule->SetupIRMethod(NULL, loadSharedLibFunc, false);
bfModule->mBfIRBuilder->SetActiveFunction(loadSharedLibFunc); bfModule->mBfIRBuilder->SetActiveFunction(loadSharedLibFunc);
auto entryBlock = bfModule->mBfIRBuilder->CreateBlock("entry", true); auto entryBlock = bfModule->mBfIRBuilder->CreateBlock("entry", true);
@ -1544,6 +1545,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
SmallVector<BfIRType, 2> paramTypes; SmallVector<BfIRType, 2> paramTypes;
auto dtorFuncType = bfModule->mBfIRBuilder->CreateFunctionType(voidType, paramTypes, false); auto dtorFuncType = bfModule->mBfIRBuilder->CreateFunctionType(voidType, paramTypes, false);
dtorFunc = bfModule->mBfIRBuilder->CreateFunction(dtorFuncType, BfIRLinkageType_External, "BfCallAllStaticDtors"); dtorFunc = bfModule->mBfIRBuilder->CreateFunction(dtorFuncType, BfIRLinkageType_External, "BfCallAllStaticDtors");
bfModule->SetupIRMethod(NULL, dtorFunc, false);
bfModule->mBfIRBuilder->SetActiveFunction(dtorFunc); bfModule->mBfIRBuilder->SetActiveFunction(dtorFunc);
auto entryBlock = bfModule->mBfIRBuilder->CreateBlock("entry", true); auto entryBlock = bfModule->mBfIRBuilder->CreateBlock("entry", true);
bfModule->mBfIRBuilder->SetInsertPoint(entryBlock); bfModule->mBfIRBuilder->SetInsertPoint(entryBlock);
@ -1582,6 +1584,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
paramTypes.push_back(nullPtrType); paramTypes.push_back(nullPtrType);
mainFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false); mainFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false);
mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "main"); mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "main");
bfModule->SetupIRMethod(NULL, mainFunc, false);
} }
else if (project->mTargetType == BfTargetType_BeefDynLib) else if (project->mTargetType == BfTargetType_BeefDynLib)
{ {
@ -1593,6 +1596,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "DllMain"); mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "DllMain");
if (mSystem->mPtrSize == 4) if (mSystem->mPtrSize == 4)
bfModule->mBfIRBuilder->SetFuncCallingConv(mainFunc, BfIRCallingConv_StdCall); bfModule->mBfIRBuilder->SetFuncCallingConv(mainFunc, BfIRCallingConv_StdCall);
bfModule->SetupIRMethod(NULL, mainFunc, false);
} }
else if (project->mTargetType == BfTargetType_BeefWindowsApplication) else if (project->mTargetType == BfTargetType_BeefWindowsApplication)
{ {
@ -1605,6 +1609,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "WinMain"); mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "WinMain");
if (mSystem->mPtrSize == 4) if (mSystem->mPtrSize == 4)
bfModule->mBfIRBuilder->SetFuncCallingConv(mainFunc, BfIRCallingConv_StdCall); bfModule->mBfIRBuilder->SetFuncCallingConv(mainFunc, BfIRCallingConv_StdCall);
bfModule->SetupIRMethod(NULL, mainFunc, false);
} }
else else
{ {
@ -1613,6 +1618,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
paramTypes.push_back(nullPtrType); paramTypes.push_back(nullPtrType);
mainFuncType = bfModule->mBfIRBuilder->CreateFunctionType(voidType, paramTypes, false); mainFuncType = bfModule->mBfIRBuilder->CreateFunctionType(voidType, paramTypes, false);
mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "BeefMain"); mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "BeefMain");
bfModule->SetupIRMethod(NULL, mainFunc, false);
} }
bfModule->mBfIRBuilder->SetActiveFunction(mainFunc); bfModule->mBfIRBuilder->SetActiveFunction(mainFunc);
@ -1627,6 +1633,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
auto setCmdLineFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false); auto setCmdLineFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false);
auto setCmdLineFunc = bfModule->mBfIRBuilder->CreateFunction(setCmdLineFuncType, BfIRLinkageType_External, "BfpSystem_SetCommandLine"); auto setCmdLineFunc = bfModule->mBfIRBuilder->CreateFunction(setCmdLineFuncType, BfIRLinkageType_External, "BfpSystem_SetCommandLine");
bfModule->SetupIRMethod(NULL, setCmdLineFunc, false);
SmallVector<BfIRValue, 2> args; SmallVector<BfIRValue, 2> args;
args.push_back(bfModule->mBfIRBuilder->GetArgument(0)); args.push_back(bfModule->mBfIRBuilder->GetArgument(0));
@ -1775,6 +1782,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
BfIRFunctionType thunkFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false); BfIRFunctionType thunkFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false);
BfIRFunction thunkMainFunc = bfModule->mBfIRBuilder->CreateFunction(thunkFuncType, BfIRLinkageType_External, "BeefMain"); BfIRFunction thunkMainFunc = bfModule->mBfIRBuilder->CreateFunction(thunkFuncType, BfIRLinkageType_External, "BeefMain");
bfModule->SetupIRMethod(NULL, thunkMainFunc, false);
bfModule->mBfIRBuilder->SetActiveFunction(thunkMainFunc); bfModule->mBfIRBuilder->SetActiveFunction(thunkMainFunc);
auto thunkEntryBlock = bfModule->mBfIRBuilder->CreateBlock("entry", true); auto thunkEntryBlock = bfModule->mBfIRBuilder->CreateBlock("entry", true);

View file

@ -9717,7 +9717,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
SetAndRestoreValue<BfClosureState*> prevClosureState(mModule->mCurMethodState->mClosureState, &closureState); SetAndRestoreValue<BfClosureState*> prevClosureState(mModule->mCurMethodState->mClosureState, &closureState);
if (mModule->HasCompiledOutput()) 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 // 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 // capture by reference, so we still need to do it for resolve-only

View file

@ -8523,7 +8523,7 @@ BfIRValue BfModule::CreateFunctionFrom(BfMethodInstance* methodInstance, bool tr
auto callingConv = GetCallingConvention(methodInstance->GetOwner(), methodDef); auto callingConv = GetCallingConvention(methodInstance->GetOwner(), methodDef);
if (callingConv != BfIRCallingConv_CDecl) if (callingConv != BfIRCallingConv_CDecl)
mBfIRBuilder->SetFuncCallingConv(func, callingConv); mBfIRBuilder->SetFuncCallingConv(func, callingConv);
SetupLLVMMethod(methodInstance, func, isInlined); SetupIRMethod(methodInstance, func, isInlined);
// auto srcModule = methodInstance->GetOwner()->GetModule(); // auto srcModule = methodInstance->GetOwner()->GetModule();
// if ((srcModule != NULL) && (srcModule->mProject != mProject)) // if ((srcModule != NULL) && (srcModule->mProject != mProject))
@ -13588,24 +13588,28 @@ BfIRCallingConv BfModule::GetCallingConvention(BfMethodInstance* methodInstance)
return GetCallingConvention(methodInstance->GetOwner(), methodInstance->mMethodDef); 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) if (!func)
return; return;
if (mCompiler->mOptions.mNoFramePointerElim) if (mCompiler->mOptions.mNoFramePointerElim)
mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_NoFramePointerElim); 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); mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_NoUnwind);
if (mSystem->mPtrSize == 8) // We need unwind info for debugging if (mSystem->mPtrSize == 8) // We need unwind info for debugging
mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_UWTable); 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) if (methodDef->mNoReturn)
mBfIRBuilder->Func_AddAttribute(func, -1, BfIRAttribute_NoReturn); mBfIRBuilder->Func_AddAttribute(func, -1, BfIRAttribute_NoReturn);
auto callingConv = GetCallingConvention(methodInstance->GetOwner(), methodDef); auto callingConv = GetCallingConvention(methodInstance->GetOwner(), methodDef);
if (callingConv != BfIRCallingConv_CDecl) if (callingConv != BfIRCallingConv_CDecl)
mBfIRBuilder->SetFuncCallingConv(func, callingConv); mBfIRBuilder->SetFuncCallingConv(func, callingConv);
@ -18313,7 +18317,7 @@ void BfModule::SetupIRFunction(BfMethodInstance* methodInstance, StringImpl& man
*outIsIntrinsic = isIntrinsic; *outIsIntrinsic = isIntrinsic;
if (!isIntrinsic) if (!isIntrinsic)
SetupLLVMMethod(methodInstance, methodInstance->mIRFunction, methodInstance->mAlwaysInline); SetupIRMethod(methodInstance, methodInstance->mIRFunction, methodInstance->mAlwaysInline);
} }
void BfModule::CheckHotMethod(BfMethodInstance* methodInstance, const StringImpl& inMangledName) void BfModule::CheckHotMethod(BfMethodInstance* methodInstance, const StringImpl& inMangledName)

View file

@ -1678,7 +1678,7 @@ public:
void CreateDllImportMethod(); void CreateDllImportMethod();
BfIRCallingConv GetCallingConvention(BfTypeInstance* typeInst, BfMethodDef* methodDef); BfIRCallingConv GetCallingConvention(BfTypeInstance* typeInst, BfMethodDef* methodDef);
BfIRCallingConv GetCallingConvention(BfMethodInstance* methodInstance); 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 EmitCtorBody(bool& skipBody);
void EmitDtorBody(); void EmitDtorBody();
void EmitEnumToStringBody(); void EmitEnumToStringBody();