Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/inc/daccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -2459,4 +2459,16 @@ typedef DPTR(PTR_PCODE) PTR_PTR_PCODE;
// @dbgtodo : Separating asserts and target consistency checks is tracked by DevDiv Bugs 31674
#define TARGET_CONSISTENCY_CHECK(expr,msg) _ASSERTE_MSG(expr,msg)

// For cross compilation, controlling type layout is important
// We add a simple macro here which defines DAC_ALIGNAS to the C++11 alignas operator
// This helps force the alignment of the next member
// For most cross compilation cases the layout of types simply works
// There are a few cases (where this macro is helpful) which are not consistent accross platforms:
// - Base class whose size is padded to its align size. On Linux the gcc/clang
// layouts will reuse this padding in the derived class for the first member
// - Class with an vtable pointer and an alignment greater than the pointer size.
// The Windows compilers will align the first member to the alignment size of the
// class. Linux will align the first member to its natural alignment
#define DAC_ALIGNAS(a) alignas(a)

#endif // #ifndef __daccess_h__
2 changes: 2 additions & 0 deletions src/inc/sstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ template <COUNT_T MEMSIZE>
class InlineSString : public SString
{
private:
DAC_ALIGNAS(SString)
BYTE m_inline[SBUFFER_PADDED_SIZE(MEMSIZE)];

public:
Expand Down Expand Up @@ -990,6 +991,7 @@ template <COUNT_T MEMSIZE>
class ScratchBuffer : public SString::AbstractScratchBuffer
{
private:
DAC_ALIGNAS(::SString::AbstractScratchBuffer)
BYTE m_inline[MEMSIZE];

public:
Expand Down
2 changes: 2 additions & 0 deletions src/inc/stgpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,7 @@ class StgGuidPool : public StgPool


private:
DAC_ALIGNAS(StgPool) // Align first member to alignment of base class
CGuidPoolHash m_Hash; // Hash table for lookups.
int m_bHash; // true to keep hash table.
}; // class StgGuidPool
Expand Down Expand Up @@ -1257,6 +1258,7 @@ class StgBlobPool : public StgPool
__checkReturn
HRESULT RehashBlobs();

DAC_ALIGNAS(StgPool) // Align first member to alignment of base class
CBlobPoolHash m_Hash; // Hash table for lookups.
}; // class StgBlobPool

Expand Down
1 change: 1 addition & 0 deletions src/inc/utilcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -2648,6 +2648,7 @@ template <class MemMgr>
class CHashTableAndData : public CHashTable
{
public:
DAC_ALIGNAS(CHashTable)
ULONG m_iFree; // Index into m_pcEntries[] of next available slot
ULONG m_iEntries; // size of m_pcEntries[]

Expand Down
3 changes: 1 addition & 2 deletions src/md/compiler/regmeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -1987,8 +1987,7 @@ class RegMeta :
#endif //FEATURE_METADATA_INTERNAL_APIS

UTSemReadWrite *m_pSemReadWrite;
bool m_fOwnSem;

unsigned m_fOwnSem : 1;
unsigned m_bRemap : 1; // If true, there is a token mapper.
unsigned m_bSaveOptimized : 1; // If true, save optimization has been done.
unsigned m_hasOptimizedRefToDef : 1; // true if we have performed ref to def optimization
Expand Down
1 change: 1 addition & 0 deletions src/md/inc/liteweightstgdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class CLiteWeightStgdbRW : public CLiteWeightStgdb<CMiniMdRW>
const void **ppv, // [OUT] put pointer to MD stream here.
ULONG *pcb); // [OUT] put size of the stream here.

DAC_ALIGNAS(CLiteWeightStgdb<CMiniMdRW>) // Align the first member to the alignment of the base class
UINT32 m_cbSaveSize; // Size of the saved streams.
int m_bSaveCompressed; // If true, save as compressed stream (#-, not #~)
VOID* m_pImage; // Set in OpenForRead, NULL for anything but PE files
Expand Down
1 change: 1 addition & 0 deletions src/md/inc/metamodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -2120,6 +2120,7 @@ template <class Impl> class CMiniMdTemplate : public CMiniMdBase

FORCEINLINE void MarkUnsafeToDelete() { m_isSafeToDelete = false; }

DAC_ALIGNAS(CMiniMdBase)
bool m_isSafeToDelete; // This starts out true, but gets set to FALSE if we detect
// a MiniMd API call that might have given out an internal pointer.
#endif
Expand Down
1 change: 1 addition & 0 deletions src/md/inc/metamodelro.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class CMiniMd final: public CMiniMdTemplate<CMiniMd>
#endif //FEATURE_PREJIT

protected:
DAC_ALIGNAS(CMiniMdTemplate<CMiniMd>) // Align the first member to the alignment of the base class
// Table info.
MetaData::TableRO m_Tables[TBL_COUNT];
#ifdef FEATURE_PREJIT
Expand Down
1 change: 1 addition & 0 deletions src/md/inc/metamodelrw.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ class CMiniMdRW : public CMiniMdTemplate<CMiniMdRW>
return HashToken(tkObject);
}

DAC_ALIGNAS(CMiniMdTemplate<CMiniMdRW>) // Align the first member to the alignment of the base class
CMemberRefHash *m_pMemberRefHash;

// Hash table for Methods and Fields
Expand Down
1 change: 1 addition & 0 deletions src/md/inc/recordpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class RecordPool : public StgPool
void **pContext); // Stored context here.

private:
DAC_ALIGNAS(StgPool) // Align first member to alignment of base class
UINT32 m_cbRec; // How large is each record?

}; // class RecordPool
Expand Down
2 changes: 2 additions & 0 deletions src/vm/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -2171,6 +2171,7 @@ struct ComPlusCallInfo;
class DelegateEEClass : public EEClass
{
public:
DAC_ALIGNAS(EEClass) // Align the first member to the alignment of the base class
PTR_Stub m_pStaticCallStub;
PTR_Stub m_pInstRetBuffCallStub;
RelativePointer<PTR_MethodDesc> m_pInvokeMethod;
Expand Down Expand Up @@ -2241,6 +2242,7 @@ class ArrayClass : public EEClass

private:

DAC_ALIGNAS(EEClass) // Align the first member to the alignment of the base class
unsigned char m_rank;
CorElementType m_ElementType;// Cache of element type in m_ElementTypeHnd

Expand Down
4 changes: 4 additions & 0 deletions src/vm/loaderallocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class LoaderAllocator
// Heaps for allocating data that persists for the life of the AppDomain
// Objects that are allocated frequently should be allocated into the HighFreq heap for
// better page management

DAC_ALIGNAS(UINT64) // Align the first member to alignof(m_nLoaderAllocator). Windows does this by default, force Linux to match.
BYTE * m_InitialReservedMemForLoaderHeaps;
BYTE m_LowFreqHeapInstance[sizeof(LoaderHeap)];
BYTE m_HighFreqHeapInstance[sizeof(LoaderHeap)];
Expand Down Expand Up @@ -623,6 +625,7 @@ class GlobalLoaderAllocator : public LoaderAllocator
VPTR_VTABLE_CLASS(GlobalLoaderAllocator, LoaderAllocator)
VPTR_UNIQUE(VPTRU_LoaderAllocator+1)

DAC_ALIGNAS(LoaderAllocator) // Align the first member to the alignment of the base class
BYTE m_ExecutableHeapInstance[sizeof(LoaderHeap)];

protected:
Expand All @@ -645,6 +648,7 @@ class AssemblyLoaderAllocator : public LoaderAllocator
VPTR_UNIQUE(VPTRU_LoaderAllocator+3)

protected:
DAC_ALIGNAS(LoaderAllocator) // Align the first member to the alignment of the base class
LoaderAllocatorID m_Id;
ShuffleThunkCache* m_pShuffleThunkCache;
public:
Expand Down