@@ -1122,34 +1122,64 @@ void Compiler::eeDispLineInfos()
11221122 * (e.g., host AMD64, target ARM64), then VM will get confused anyway.
11231123 */
11241124
1125- void Compiler::eeAllocMem (AllocMemArgs* args)
1125+ void Compiler::eeAllocMem (AllocMemArgs* args, const UNATIVE_OFFSET roDataSectionAlignment )
11261126{
11271127#ifdef DEBUG
1128- const UNATIVE_OFFSET hotSizeRequest = args->hotCodeSize ;
1129- const UNATIVE_OFFSET coldSizeRequest = args->coldCodeSize ;
11301128
1131- // Fake splitting implementation: place hot/cold code in contiguous section
1132- if (JitConfig.JitFakeProcedureSplitting () && (coldSizeRequest > 0 ))
1129+ // Fake splitting implementation: place hot/cold code in contiguous section.
1130+ UNATIVE_OFFSET coldCodeOffset = 0 ;
1131+ if (JitConfig.JitFakeProcedureSplitting () && (args->coldCodeSize > 0 ))
11331132 {
1134- args->hotCodeSize = hotSizeRequest + coldSizeRequest;
1133+ coldCodeOffset = args->hotCodeSize ;
1134+ assert (coldCodeOffset > 0 );
1135+ args->hotCodeSize += args->coldCodeSize ;
11351136 args->coldCodeSize = 0 ;
11361137 }
1137- #endif
1138+
1139+ #endif // DEBUG
1140+
1141+ #if defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64)
1142+
1143+ // For arm64/LoongArch64, we want to allocate JIT data always adjacent to code similar to what native compiler does.
1144+ // This way allows us to use a single `ldr` to access such data like float constant/jmp table.
1145+ // For LoongArch64 using `pcaddi + ld` to access such data.
1146+
1147+ UNATIVE_OFFSET roDataAlignmentDelta = 0 ;
1148+ if (args->roDataSize > 0 )
1149+ {
1150+ roDataAlignmentDelta = AlignmentPad (args->hotCodeSize , roDataSectionAlignment);
1151+ }
1152+
1153+ const UNATIVE_OFFSET roDataOffset = args->hotCodeSize + roDataAlignmentDelta;
1154+ args->hotCodeSize = roDataOffset + args->roDataSize ;
1155+ args->roDataSize = 0 ;
1156+
1157+ #endif // defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64)
11381158
11391159 info.compCompHnd ->allocMem (args);
11401160
11411161#ifdef DEBUG
1142- if (JitConfig.JitFakeProcedureSplitting () && (coldSizeRequest > 0 ))
1143- {
1144- // Fix up hot/cold code pointers
1145- args->coldCodeBlock = ((BYTE*)args->hotCodeBlock ) + hotSizeRequest;
1146- args->coldCodeBlockRW = ((BYTE*)args->hotCodeBlockRW ) + hotSizeRequest;
11471162
1148- // Reset args' hot/cold code sizes in case caller reads them later
1149- args->hotCodeSize = hotSizeRequest;
1150- args->coldCodeSize = coldSizeRequest;
1163+ if (JitConfig.JitFakeProcedureSplitting () && (coldCodeOffset > 0 ))
1164+ {
1165+ // Fix up cold code pointers. Cold section is adjacent to hot section.
1166+ assert (args->coldCodeBlock == nullptr );
1167+ assert (args->coldCodeBlockRW == nullptr );
1168+ args->coldCodeBlock = ((BYTE*)args->hotCodeBlock ) + coldCodeOffset;
1169+ args->coldCodeBlockRW = ((BYTE*)args->hotCodeBlockRW ) + coldCodeOffset;
11511170 }
1152- #endif
1171+
1172+ #endif // DEBUG
1173+
1174+ #if defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64)
1175+
1176+ // Fix up data section pointers.
1177+ assert (args->roDataBlock == nullptr );
1178+ assert (args->roDataBlockRW == nullptr );
1179+ args->roDataBlock = ((BYTE*)args->hotCodeBlock ) + roDataOffset;
1180+ args->roDataBlockRW = ((BYTE*)args->hotCodeBlockRW ) + roDataOffset;
1181+
1182+ #endif // defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64)
11531183}
11541184
11551185void Compiler::eeReserveUnwindInfo (bool isFunclet, bool isColdCode, ULONG unwindSize)
0 commit comments