Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit371d227

Browse files
authored
JIT: Ensure proper alignment of async resumption data section (dotnet#121790)
We did not properly ensure the alignment of the async resumption datablob, only the overall alignment of the entire data section.Unify the code that inserts padding and use it for the async resumptiondata too.The alignment was also missing for basic block address sections, but wedid not have a problem here because we do not use absolute basic blockaddresses for 64-bit targets. Still, add the code to ensure this wouldget aligned correctly.Fixdotnet#121779
1 parent48fd2f3 commit371d227

File tree

2 files changed

+56
-47
lines changed

2 files changed

+56
-47
lines changed

‎src/coreclr/jit/emit.cpp‎

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7869,9 +7869,6 @@ UNATIVE_OFFSET emitter::emitFindOffset(const insGroup* ig, unsigned insNum) cons
78697869
//
78707870
UNATIVE_OFFSETemitter::emitDataGenBeg(unsigned size,unsigned alignment, var_types dataType)
78717871
{
7872-
unsigned secOffs;
7873-
dataSection* secDesc;
7874-
78757872
assert(emitDataSecCur ==nullptr);
78767873

78777874
// The size must not be zero and must be a multiple of MIN_DATA_ALIGN
@@ -7882,46 +7879,16 @@ UNATIVE_OFFSET emitter::emitDataGenBeg(unsigned size, unsigned alignment, var_ty
78827879
// simpler to allow it than to check and block it.
78837880
//
78847881
assert((size !=0) && ((size % dataSection::MIN_DATA_ALIGN) ==0));
7885-
assert(isPow2(alignment) && (alignment <= dataSection::MAX_DATA_ALIGN));
7886-
7887-
/* Get hold of the current offset*/
7888-
secOffs = emitConsDsc.dsdOffs;
78897882

7890-
if (((secOffs % alignment) !=0) && (alignment > dataSection::MIN_DATA_ALIGN))
7891-
{
7892-
// As per the above comment, the minimum alignment is actually (MIN_DATA_ALIGN)
7893-
// bytes so we don't need to make any adjustments if the requested
7894-
// alignment is less than MIN_DATA_ALIGN.
7895-
//
7896-
// The maximum requested alignment is tracked and the memory allocator
7897-
// will end up ensuring offset 0 is at an address matching that
7898-
// alignment. So if the requested alignment is greater than MIN_DATA_ALIGN,
7899-
// we need to pad the space out so the offset is a multiple of the requested.
7900-
//
7901-
uint8_t zeros[dataSection::MAX_DATA_ALIGN] = {};// auto initialize to all zeros
7902-
7903-
unsigned zeroSize = alignment - (secOffs % alignment);
7904-
unsigned zeroAlign = dataSection::MIN_DATA_ALIGN;
7905-
var_types zeroType = TYP_INT;
7906-
7907-
emitBlkConst(&zeros, zeroSize, zeroAlign, zeroType);
7908-
secOffs = emitConsDsc.dsdOffs;
7909-
}
7910-
7911-
assert((secOffs % alignment) ==0);
7912-
if (emitConsDsc.alignment < alignment)
7913-
{
7914-
JITDUMP("Increasing data section alignment from %u to %u for type %s\n", emitConsDsc.alignment, alignment,
7915-
varTypeName(dataType));
7916-
emitConsDsc.alignment = alignment;
7917-
}
7883+
emitEnsureDataSectionAlignment(alignment);
79187884

7885+
unsigned secOffs = emitConsDsc.dsdOffs;
79197886
/* Advance the current offset*/
79207887
emitConsDsc.dsdOffs += size;
79217888

79227889
/* Allocate a data section descriptor and add it to the list*/
79237890

7924-
secDesc = emitDataSecCur = (dataSection*)emitGetMem(roundUp(sizeof(*secDesc) + size));
7891+
dataSection*secDesc = emitDataSecCur = (dataSection*)emitGetMem(roundUp(sizeof(*secDesc) + size));
79257892

79267893
secDesc->dsSize = size;
79277894

@@ -7944,6 +7911,50 @@ UNATIVE_OFFSET emitter::emitDataGenBeg(unsigned size, unsigned alignment, var_ty
79447911
return secOffs;
79457912
}
79467913

7914+
//---------------------------------------------------------------------------
7915+
// emitEnsureDataSectionAlignment:
7916+
// Ensure that data is emitted such that the next byte would be aligned at
7917+
// the specified alignment. Also increase the overall data section alignment
7918+
// if necessary.
7919+
//
7920+
// Arguments:
7921+
// alignment - The aligment
7922+
//
7923+
voidemitter::emitEnsureDataSectionAlignment(unsigned alignment)
7924+
{
7925+
assert(isPow2(alignment) && (alignment <= dataSection::MAX_DATA_ALIGN));
7926+
7927+
if (emitConsDsc.alignment < alignment)
7928+
{
7929+
JITDUMP("Increasing overall data section alignment from %u to %u\n", emitConsDsc.alignment, alignment);
7930+
emitConsDsc.alignment = alignment;
7931+
}
7932+
7933+
unsigned secOffs = emitConsDsc.dsdOffs;
7934+
if ((secOffs % alignment) ==0)
7935+
{
7936+
return;
7937+
}
7938+
7939+
// Should always be aligned to the minimum alignment.
7940+
assert((secOffs % dataSection::MIN_DATA_ALIGN) ==0);
7941+
7942+
// The maximum requested alignment is tracked and the memory allocator
7943+
// will end up ensuring offset 0 is at an address matching that
7944+
// alignment. So if the requested alignment is greater than MIN_DATA_ALIGN,
7945+
// we need to pad the space out so the offset is a multiple of the requested.
7946+
//
7947+
uint8_t zeros[dataSection::MAX_DATA_ALIGN] = {};// auto initialize to all zeros
7948+
7949+
unsigned zeroSize = alignment - (secOffs % alignment);
7950+
unsigned zeroAlign = dataSection::MIN_DATA_ALIGN;
7951+
var_types zeroType = TYP_INT;
7952+
7953+
emitBlkConst(zeros, zeroSize, zeroAlign, zeroType);
7954+
7955+
assert((emitConsDsc.dsdOffs % alignment) ==0);
7956+
}
7957+
79477958
// Start generating a constant data section for the current function
79487959
// populated with BasicBlock references.
79497960
// You can choose the references to be either absolute pointers, or
@@ -7958,16 +7969,11 @@ UNATIVE_OFFSET emitter::emitBBTableDataGenBeg(unsigned numEntries, bool relative
79587969

79597970
assert(emitDataSecCur ==nullptr);
79607971

7961-
UNATIVE_OFFSET emittedSize;
7972+
unsigned elemSize = relativeAddr ?4 : TARGET_POINTER_SIZE;
79627973

7963-
if (relativeAddr)
7964-
{
7965-
emittedSize = numEntries *4;
7966-
}
7967-
else
7968-
{
7969-
emittedSize = numEntries * TARGET_POINTER_SIZE;
7970-
}
7974+
emitEnsureDataSectionAlignment(elemSize);
7975+
7976+
UNATIVE_OFFSET emittedSize = numEntries * elemSize;
79717977

79727978
/* Get hold of the current offset*/
79737979

@@ -8014,6 +8020,8 @@ UNATIVE_OFFSET emitter::emitBBTableDataGenBeg(unsigned numEntries, bool relative
80148020
//
80158021
voidemitter::emitAsyncResumeTable(unsigned numEntries, UNATIVE_OFFSET* dataSecOffs, emitter::dataSection** dataSec)
80168022
{
8023+
emitEnsureDataSectionAlignment(TARGET_POINTER_SIZE);
8024+
80178025
UNATIVE_OFFSET secOffs = emitConsDsc.dsdOffs;
80188026
unsigned emittedSize =sizeof(emitter::dataAsyncResumeInfo) * numEntries;
80198027
emitConsDsc.dsdOffs += emittedSize;
@@ -8037,8 +8045,7 @@ void emitter::emitAsyncResumeTable(unsigned numEntries, UNATIVE_OFFSET* dataSecO
80378045
emitConsDsc.dsdList = secDesc;
80388046
}
80398047

8040-
emitConsDsc.dsdLast = secDesc;
8041-
emitConsDsc.alignment =std::max(emitConsDsc.alignment, (UNATIVE_OFFSET)TARGET_POINTER_SIZE);
8048+
emitConsDsc.dsdLast = secDesc;
80428049

80438050
*dataSecOffs = secOffs;
80448051
*dataSec = secDesc;

‎src/coreclr/jit/emitpub.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ const char* emitOffsetToLabel(unsigned offs);
8181

8282
UNATIVE_OFFSETemitDataGenBeg(unsigned size,unsigned alignment, var_types dataType);
8383

84+
voidemitEnsureDataSectionAlignment(unsigned alignment);
85+
8486
UNATIVE_OFFSETemitBBTableDataGenBeg(unsigned numEntries,bool relativeAddr);
8587

8688
voidemitDataGenData(unsigned offs,constvoid* data, UNATIVE_OFFSET size);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp