Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit b53a526

Browse files
authored
Backport Cross DAC runtime layout changes (#28035)
* Backport Cross DAC runtime layout changes This represents the minimum set of changes required to be able to build the Cross DAC out of band. This fixes the layout difference between the Windows compiler and the clang Linux compiler. * Fix DBI CMiniMdTemplate layout * Fix alignment in checked builds
1 parent 0ba6333 commit b53a526

File tree

12 files changed

+29
-2
lines changed

12 files changed

+29
-2
lines changed

src/inc/daccess.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,4 +2459,16 @@ typedef DPTR(PTR_PCODE) PTR_PTR_PCODE;
24592459
// @dbgtodo : Separating asserts and target consistency checks is tracked by DevDiv Bugs 31674
24602460
#define TARGET_CONSISTENCY_CHECK(expr,msg) _ASSERTE_MSG(expr,msg)
24612461

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

src/inc/sstring.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ template <COUNT_T MEMSIZE>
808808
class InlineSString : public SString
809809
{
810810
private:
811+
DAC_ALIGNAS(SString)
811812
BYTE m_inline[SBUFFER_PADDED_SIZE(MEMSIZE)];
812813

813814
public:
@@ -990,6 +991,7 @@ template <COUNT_T MEMSIZE>
990991
class ScratchBuffer : public SString::AbstractScratchBuffer
991992
{
992993
private:
994+
DAC_ALIGNAS(::SString::AbstractScratchBuffer)
993995
BYTE m_inline[MEMSIZE];
994996

995997
public:

src/inc/stgpool.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,7 @@ class StgGuidPool : public StgPool
11051105

11061106

11071107
private:
1108+
DAC_ALIGNAS(StgPool) // Align first member to alignment of base class
11081109
CGuidPoolHash m_Hash; // Hash table for lookups.
11091110
int m_bHash; // true to keep hash table.
11101111
}; // class StgGuidPool
@@ -1257,6 +1258,7 @@ class StgBlobPool : public StgPool
12571258
__checkReturn
12581259
HRESULT RehashBlobs();
12591260

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

src/inc/utilcode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2648,6 +2648,7 @@ template <class MemMgr>
26482648
class CHashTableAndData : public CHashTable
26492649
{
26502650
public:
2651+
DAC_ALIGNAS(CHashTable)
26512652
ULONG m_iFree; // Index into m_pcEntries[] of next available slot
26522653
ULONG m_iEntries; // size of m_pcEntries[]
26532654

src/md/compiler/regmeta.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,8 +1987,7 @@ class RegMeta :
19871987
#endif //FEATURE_METADATA_INTERNAL_APIS
19881988

19891989
UTSemReadWrite *m_pSemReadWrite;
1990-
bool m_fOwnSem;
1991-
1990+
unsigned m_fOwnSem : 1;
19921991
unsigned m_bRemap : 1; // If true, there is a token mapper.
19931992
unsigned m_bSaveOptimized : 1; // If true, save optimization has been done.
19941993
unsigned m_hasOptimizedRefToDef : 1; // true if we have performed ref to def optimization

src/md/inc/liteweightstgdb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ class CLiteWeightStgdbRW : public CLiteWeightStgdb<CMiniMdRW>
190190
const void **ppv, // [OUT] put pointer to MD stream here.
191191
ULONG *pcb); // [OUT] put size of the stream here.
192192

193+
DAC_ALIGNAS(CLiteWeightStgdb<CMiniMdRW>) // Align the first member to the alignment of the base class
193194
UINT32 m_cbSaveSize; // Size of the saved streams.
194195
int m_bSaveCompressed; // If true, save as compressed stream (#-, not #~)
195196
VOID* m_pImage; // Set in OpenForRead, NULL for anything but PE files

src/md/inc/metamodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,6 +2120,7 @@ template <class Impl> class CMiniMdTemplate : public CMiniMdBase
21202120

21212121
FORCEINLINE void MarkUnsafeToDelete() { m_isSafeToDelete = false; }
21222122

2123+
DAC_ALIGNAS(CMiniMdBase)
21232124
bool m_isSafeToDelete; // This starts out true, but gets set to FALSE if we detect
21242125
// a MiniMd API call that might have given out an internal pointer.
21252126
#endif

src/md/inc/metamodelro.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class CMiniMd final: public CMiniMdTemplate<CMiniMd>
7777
#endif //FEATURE_PREJIT
7878

7979
protected:
80+
DAC_ALIGNAS(CMiniMdTemplate<CMiniMd>) // Align the first member to the alignment of the base class
8081
// Table info.
8182
MetaData::TableRO m_Tables[TBL_COUNT];
8283
#ifdef FEATURE_PREJIT

src/md/inc/metamodelrw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ class CMiniMdRW : public CMiniMdTemplate<CMiniMdRW>
672672
return HashToken(tkObject);
673673
}
674674

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

677678
// Hash table for Methods and Fields

src/md/inc/recordpool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ class RecordPool : public StgPool
154154
void **pContext); // Stored context here.
155155

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

159160
}; // class RecordPool

0 commit comments

Comments
 (0)