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

Commit b7fbfd0

Browse files
author
Mike McLaughlin
authored
Fix mscordbi metadata reader alignment bug on Linux. (#19196)
Works fine on Windows minidumps, but on Linux (via OpenVirtualProcess for production breakpoints and future core dumps) the compiler's struct alignment rules are different. On Windows, classes/structs are aligned based on the largest field. On Linux, they are 4 byte aligned regardless of the field sizes. https://github.com/dotnet/coreclr/issues/17692
1 parent eafbf02 commit b7fbfd0

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/md/datasource/datatargetreader.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,13 @@ void DataTargetReader::Align(DWORD alignmentBytes)
163163

164164
void DataTargetReader::AlignBase()
165165
{
166+
#ifdef _MSC_VER
167+
// Windows MSVC compiler aligns structs based on the largest field size
166168
Align(m_currentStructureAlign);
169+
#else
170+
// clang (on all platforms) aligns structs always on 4 byte boundaries
171+
Align(4);
172+
#endif
167173
}
168174

169175
HRESULT DataTargetReader::GetRemotePointerSize(ULONG32* pPointerSize)

src/md/datasource/targettypes.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,12 @@ m_tableMax(0)
134134
HRESULT Target_MapSHash::ReadFrom(DataTargetReader & reader)
135135
{
136136
HRESULT hr = S_OK;
137+
// Only the Windows MSVC compiler does this; not clang on Linux
138+
#ifdef _MSC_VER
137139
IfFailRet(reader.Skip8()); // this byte gets used by the base class even though it has no members
138140
// I'm guessing this is so the 2nd base class (noncopyable) doesn't start at the same
139141
// location, but I can't be sure. Whatever the cause, the layout skips a byte.
142+
#endif // _MSC_VER
140143
IfFailRet(reader.ReadPointer(&m_table));
141144
IfFailRet(reader.Read32(&m_tableSize));
142145
IfFailRet(reader.Read32(&m_tableCount));

0 commit comments

Comments
 (0)