mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Fixed crash related to global var alignment
This commit is contained in:
parent
2c6a72ba68
commit
aaccaa97e2
5 changed files with 40 additions and 10 deletions
|
@ -12,7 +12,6 @@
|
||||||
|
|
||||||
USING_NS_BF;
|
USING_NS_BF;
|
||||||
|
|
||||||
#ifdef DEF_BF_ALLOCDEBUG
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -190,7 +189,7 @@ void StompInit()
|
||||||
gStompInside = false;
|
gStompInside = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void* StompAlloc(int size)
|
void* StompAlloc(int size)
|
||||||
{
|
{
|
||||||
//return malloc(size);
|
//return malloc(size);
|
||||||
|
|
||||||
|
@ -222,7 +221,7 @@ static void* StompAlloc(int size)
|
||||||
gStompInside = false;
|
gStompInside = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void StompFree(void* addr)
|
void StompFree(void* addr)
|
||||||
{
|
{
|
||||||
if (gSA_CritSect == NULL)
|
if (gSA_CritSect == NULL)
|
||||||
StompInit();
|
StompInit();
|
||||||
|
@ -328,6 +327,8 @@ void DbgHeapFree(const void* ptr, const char* fileName, int lineNum)
|
||||||
assert("Not found" == 0);
|
assert("Not found" == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEF_BF_ALLOCDEBUG
|
||||||
|
|
||||||
void DbgHeapCheck()
|
void DbgHeapCheck()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < (int) gDbgHeapRecords.size(); i++)
|
for (int i = 0; i < (int) gDbgHeapRecords.size(); i++)
|
||||||
|
@ -391,7 +392,7 @@ void* __cdecl operator new(std::size_t size)
|
||||||
#ifdef USE_STOMP
|
#ifdef USE_STOMP
|
||||||
return StompAlloc((int)size);
|
return StompAlloc((int)size);
|
||||||
#else
|
#else
|
||||||
return DbgHeapAlloc(size, fileName, lineNum);
|
return DbgHeapAlloc(size, "", 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,7 +428,7 @@ void operator delete(void* ptr)
|
||||||
#ifdef USE_STOMP
|
#ifdef USE_STOMP
|
||||||
StompFree(ptr);
|
StompFree(ptr);
|
||||||
#else
|
#else
|
||||||
DbgHeapFree(ptr, fileName, lineNum);
|
DbgHeapFree(ptr, "", 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,7 +437,7 @@ void operator delete[](void* ptr)
|
||||||
#ifdef USE_STOMP
|
#ifdef USE_STOMP
|
||||||
StompFree(ptr);
|
StompFree(ptr);
|
||||||
#else
|
#else
|
||||||
DbgHeapFree(ptr, fileName, lineNum);
|
DbgHeapFree(ptr, "", 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,3 +85,6 @@ void BpDump();
|
||||||
#define BP_ALLOC_RAW_T(T)
|
#define BP_ALLOC_RAW_T(T)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void* StompAlloc(int size);
|
||||||
|
void StompFree(void* addr);
|
|
@ -5,11 +5,17 @@
|
||||||
#include "../Common.h"
|
#include "../Common.h"
|
||||||
|
|
||||||
//#define BUMPALLOC_TRACKALLOCS
|
//#define BUMPALLOC_TRACKALLOCS
|
||||||
|
//#define BUMPALLOC_STOMPALLOC
|
||||||
|
|
||||||
#ifdef BUMPALLOC_ETW_TRACING
|
#ifdef BUMPALLOC_ETW_TRACING
|
||||||
#include "VSCustomNativeHeapEtwProvider.h"
|
#include "VSCustomNativeHeapEtwProvider.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef BUMPALLOC_STOMPALLOC
|
||||||
|
void* StompAlloc(int size);
|
||||||
|
void StompFree(void* addr);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef BUMPALLOC_TRACKALLOCS
|
#ifdef BUMPALLOC_TRACKALLOCS
|
||||||
#include "Dictionary.h"
|
#include "Dictionary.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -74,7 +80,11 @@ public:
|
||||||
mCurAlloc = NULL;
|
mCurAlloc = NULL;
|
||||||
mCurPtr = (uint8*)(intptr)ALLOC_SIZE;
|
mCurPtr = (uint8*)(intptr)ALLOC_SIZE;
|
||||||
for (auto ptr : mPools)
|
for (auto ptr : mPools)
|
||||||
|
#ifdef BUMPALLOC_STOMPALLOC
|
||||||
|
StompFree(ptr);
|
||||||
|
#else
|
||||||
free(ptr);
|
free(ptr);
|
||||||
|
#endif
|
||||||
mPools.Clear();
|
mPools.Clear();
|
||||||
mSizes.Clear();
|
mSizes.Clear();
|
||||||
mCurChunkNum = -1;
|
mCurChunkNum = -1;
|
||||||
|
@ -130,7 +140,11 @@ public:
|
||||||
int curSize = (int)(mCurPtr - mCurAlloc);
|
int curSize = (int)(mCurPtr - mCurAlloc);
|
||||||
mPrevSizes += curSize;
|
mPrevSizes += curSize;
|
||||||
mSizes.push_back(curSize);
|
mSizes.push_back(curSize);
|
||||||
|
#ifdef BUMPALLOC_STOMPALLOC
|
||||||
|
mCurAlloc = (uint8*)StompAlloc(ALLOC_SIZE);
|
||||||
|
#else
|
||||||
mCurAlloc = (uint8*)malloc(ALLOC_SIZE);
|
mCurAlloc = (uint8*)malloc(ALLOC_SIZE);
|
||||||
|
#endif
|
||||||
memset(mCurAlloc, 0, ALLOC_SIZE);
|
memset(mCurAlloc, 0, ALLOC_SIZE);
|
||||||
mPools.push_back(mCurAlloc);
|
mPools.push_back(mCurAlloc);
|
||||||
mCurPtr = mCurAlloc;
|
mCurPtr = mCurAlloc;
|
||||||
|
@ -205,7 +219,11 @@ public:
|
||||||
|
|
||||||
if (wantSize > ALLOC_SIZE / 2)
|
if (wantSize > ALLOC_SIZE / 2)
|
||||||
{
|
{
|
||||||
|
#ifdef BUMPALLOC_STOMPALLOC
|
||||||
|
uint8* bigData = (uint8*)StompAlloc((int)wantSize);
|
||||||
|
#else
|
||||||
uint8* bigData = (uint8*)malloc(wantSize);
|
uint8* bigData = (uint8*)malloc(wantSize);
|
||||||
|
#endif
|
||||||
memset(bigData, 0, wantSize);
|
memset(bigData, 0, wantSize);
|
||||||
mPools.push_back(bigData);
|
mPools.push_back(bigData);
|
||||||
return bigData;
|
return bigData;
|
||||||
|
|
|
@ -1658,6 +1658,9 @@ void BeIRCodeGen::HandleNextCmd()
|
||||||
{
|
{
|
||||||
CMD_PARAM(BeValue*, val);
|
CMD_PARAM(BeValue*, val);
|
||||||
CMD_PARAM(bool, unnamedAddr);
|
CMD_PARAM(bool, unnamedAddr);
|
||||||
|
|
||||||
|
BF_ASSERT(BeValueDynCast<BeGlobalVariable>(val) != NULL);
|
||||||
|
|
||||||
((BeGlobalVariable*)val)->mUnnamedAddr = true;
|
((BeGlobalVariable*)val)->mUnnamedAddr = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1666,6 +1669,8 @@ void BeIRCodeGen::HandleNextCmd()
|
||||||
CMD_PARAM(BeValue*, val);
|
CMD_PARAM(BeValue*, val);
|
||||||
CMD_PARAM(BeConstant*, initializer);
|
CMD_PARAM(BeConstant*, initializer);
|
||||||
|
|
||||||
|
BF_ASSERT(BeValueDynCast<BeGlobalVariable>(val) != NULL);
|
||||||
|
|
||||||
auto globalVariable = (BeGlobalVariable*)val;
|
auto globalVariable = (BeGlobalVariable*)val;
|
||||||
globalVariable->mInitializer = initializer;
|
globalVariable->mInitializer = initializer;
|
||||||
|
|
||||||
|
@ -1681,6 +1686,8 @@ void BeIRCodeGen::HandleNextCmd()
|
||||||
CMD_PARAM(BeValue*, val);
|
CMD_PARAM(BeValue*, val);
|
||||||
CMD_PARAM(int, alignment);
|
CMD_PARAM(int, alignment);
|
||||||
|
|
||||||
|
BF_ASSERT(BeValueDynCast<BeGlobalVariable>(val) != NULL);
|
||||||
|
|
||||||
auto globalVariable = (BeGlobalVariable*)val;
|
auto globalVariable = (BeGlobalVariable*)val;
|
||||||
globalVariable->mAlign = alignment;
|
globalVariable->mAlign = alignment;
|
||||||
BF_ASSERT(alignment > 0);
|
BF_ASSERT(alignment > 0);
|
||||||
|
|
|
@ -4461,7 +4461,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
|
||||||
auto pointerTypeData = mBfIRBuilder->CreateConstStruct(mBfIRBuilder->MapTypeInst(reflectPointerType, BfIRPopulateType_Full), pointerTypeDataParms);
|
auto pointerTypeData = mBfIRBuilder->CreateConstStruct(mBfIRBuilder->MapTypeInst(reflectPointerType, BfIRPopulateType_Full), pointerTypeDataParms);
|
||||||
typeDataVar = mBfIRBuilder->CreateGlobalVariable(mBfIRBuilder->MapTypeInst(reflectPointerType), true,
|
typeDataVar = mBfIRBuilder->CreateGlobalVariable(mBfIRBuilder->MapTypeInst(reflectPointerType), true,
|
||||||
BfIRLinkageType_External, pointerTypeData, typeDataName);
|
BfIRLinkageType_External, pointerTypeData, typeDataName);
|
||||||
|
mBfIRBuilder->GlobalVar_SetAlignment(typeDataVar, mSystem->mPtrSize);
|
||||||
typeDataVar = mBfIRBuilder->CreateBitCast(typeDataVar, mBfIRBuilder->MapType(mContext->mBfTypeType));
|
typeDataVar = mBfIRBuilder->CreateBitCast(typeDataVar, mBfIRBuilder->MapType(mContext->mBfTypeType));
|
||||||
}
|
}
|
||||||
else if (type->IsSizedArray())
|
else if (type->IsSizedArray())
|
||||||
|
@ -4478,18 +4478,19 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
|
||||||
auto sizedArrayTypeData = mBfIRBuilder->CreateConstStruct(mBfIRBuilder->MapTypeInst(reflectSizedArrayType, BfIRPopulateType_Full), sizedArrayTypeDataParms);
|
auto sizedArrayTypeData = mBfIRBuilder->CreateConstStruct(mBfIRBuilder->MapTypeInst(reflectSizedArrayType, BfIRPopulateType_Full), sizedArrayTypeDataParms);
|
||||||
typeDataVar = mBfIRBuilder->CreateGlobalVariable(mBfIRBuilder->MapTypeInst(reflectSizedArrayType), true,
|
typeDataVar = mBfIRBuilder->CreateGlobalVariable(mBfIRBuilder->MapTypeInst(reflectSizedArrayType), true,
|
||||||
BfIRLinkageType_External, sizedArrayTypeData, typeDataName);
|
BfIRLinkageType_External, sizedArrayTypeData, typeDataName);
|
||||||
|
mBfIRBuilder->GlobalVar_SetAlignment(typeDataVar, mSystem->mPtrSize);
|
||||||
typeDataVar = mBfIRBuilder->CreateBitCast(typeDataVar, mBfIRBuilder->MapType(mContext->mBfTypeType));
|
typeDataVar = mBfIRBuilder->CreateBitCast(typeDataVar, mBfIRBuilder->MapType(mContext->mBfTypeType));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
typeDataVar = mBfIRBuilder->CreateGlobalVariable(mBfIRBuilder->MapTypeInst(mContext->mBfTypeType), true,
|
typeDataVar = mBfIRBuilder->CreateGlobalVariable(mBfIRBuilder->MapTypeInst(mContext->mBfTypeType), true,
|
||||||
BfIRLinkageType_External, typeData, typeDataName);
|
BfIRLinkageType_External, typeData, typeDataName);
|
||||||
|
mBfIRBuilder->GlobalVar_SetAlignment(typeDataVar, mSystem->mPtrSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
typeDataVar = mBfIRBuilder->CreateConstNull(mBfIRBuilder->MapType(mContext->mBfTypeType));
|
typeDataVar = mBfIRBuilder->CreateConstNull(mBfIRBuilder->MapType(mContext->mBfTypeType));
|
||||||
|
|
||||||
mBfIRBuilder->GlobalVar_SetAlignment(typeDataVar, mSystem->mPtrSize);
|
|
||||||
mTypeDataRefs[typeInstance] = typeDataVar;
|
mTypeDataRefs[typeInstance] = typeDataVar;
|
||||||
|
|
||||||
return typeDataVar;
|
return typeDataVar;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue