Skip to content

JIT: Fix LA64 and RISCV64 build errors on Windows #100099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
5 changes: 5 additions & 0 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -3426,6 +3426,11 @@ class ICorDynamicInfo : public ICorStaticInfo
//
#define IMAGE_REL_BASED_REL_THUMB_MOV32_PCREL 0x14

#define IMAGE_REL_LOONGARCH64_JIR 0x0004
#define IMAGE_REL_LOONGARCH64_PC 0x0008

#define IMAGE_REL_RISCV64_PC 0x0003

/**********************************************************************************/
#ifdef TARGET_64BIT
#define USE_PER_FRAME_PINVOKE_INIT
Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/inc/gcinfotypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -785,8 +785,8 @@ void FASTCALL decodeCallPattern(int pattern,
#define DENORMALIZE_STACK_SLOT(x) ((x)<<3)
#define NORMALIZE_CODE_LENGTH(x) ((x)>>2) // All Instructions are 4 bytes long
#define DENORMALIZE_CODE_LENGTH(x) ((x)<<2)
#define NORMALIZE_STACK_BASE_REGISTER(x) ((x) == 22 ? 0 : 1) // Encode Frame pointer fp=$22 as zero
#define DENORMALIZE_STACK_BASE_REGISTER(x) ((x) == 0 ? 22 : 3)
#define NORMALIZE_STACK_BASE_REGISTER(x) ((x) == 22 ? 0u : 1u) // Encode Frame pointer fp=$22 as zero
#define DENORMALIZE_STACK_BASE_REGISTER(x) ((x) == 0 ? 22u : 3u)
#define NORMALIZE_SIZE_OF_STACK_AREA(x) ((x)>>3)
#define DENORMALIZE_SIZE_OF_STACK_AREA(x) ((x)<<3)
#define CODE_OFFSETS_NEED_NORMALIZATION 0
Expand Down Expand Up @@ -840,8 +840,8 @@ void FASTCALL decodeCallPattern(int pattern,
#define DENORMALIZE_STACK_SLOT(x) ((x)<<3)
#define NORMALIZE_CODE_LENGTH(x) ((x)>>2) // All Instructions are 4 bytes long
#define DENORMALIZE_CODE_LENGTH(x) ((x)<<2)
#define NORMALIZE_STACK_BASE_REGISTER(x) ((x) == 8 ? 0 : 1) // Encode Frame pointer X8 as zero, sp/x2 as 1
#define DENORMALIZE_STACK_BASE_REGISTER(x) ((x) == 0 ? 8 : 2)
#define NORMALIZE_STACK_BASE_REGISTER(x) ((x) == 8 ? 0u : 1u) // Encode Frame pointer X8 as zero, sp/x2 as 1
#define DENORMALIZE_STACK_BASE_REGISTER(x) ((x) == 0 ? 8u : 2u)
#define NORMALIZE_SIZE_OF_STACK_AREA(x) ((x)>>3)
#define DENORMALIZE_SIZE_OF_STACK_AREA(x) ((x)<<3)
#define CODE_OFFSETS_NEED_NORMALIZATION 0
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/inc/palclr.h
Original file line number Diff line number Diff line change
Expand Up @@ -610,4 +610,8 @@
#define IMAGE_FILE_MACHINE_LOONGARCH64 0x6264 // LOONGARCH64.
#endif

#ifndef IMAGE_FILE_MACHINE_RISCV64
#define IMAGE_FILE_MACHINE_RISCV64 0x5064
#endif

#endif // defined(HOST_WINDOWS)
8 changes: 3 additions & 5 deletions src/coreclr/jit/codegenloongarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2930,10 +2930,9 @@ static inline bool isImmed(GenTree* treeNode)

instruction CodeGen::genGetInsForOper(GenTree* treeNode)
{
var_types type = treeNode->TypeGet();
genTreeOps oper = treeNode->OperGet();
GenTree* op1 = treeNode->gtGetOp1();
GenTree* op2;
var_types type = treeNode->TypeGet();
genTreeOps oper = treeNode->OperGet();
GenTree* op1 = treeNode->gtGetOp1();
emitAttr attr = emitActualTypeSize(treeNode);
bool isImm = false;

Expand Down Expand Up @@ -8346,7 +8345,6 @@ void CodeGen::genFnPrologCalleeRegArgs()

if (regArgNum > 0)
{
instruction ins;
for (int i = MAX_REG_ARG - 1; i >= 0; i--)
{
if (regArg[i] > 0)
Expand Down
8 changes: 3 additions & 5 deletions src/coreclr/jit/codegenriscv64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2013,7 +2013,7 @@ void CodeGen::genLclHeap(GenTree* tree)
noway_assert(isFramePointerUsed()); // localloc requires Frame Pointer to be established since SP changes
noway_assert(genStackLevel == 0); // Can't have anything on the stack

const target_ssize_t pageSize = compiler->eeGetPageSize();
const size_t pageSize = (size_t)compiler->eeGetPageSize();

// According to RISC-V Privileged ISA page size is 4KiB
noway_assert(pageSize == 0x1000);
Expand Down Expand Up @@ -7049,8 +7049,6 @@ void CodeGen::genIntToIntCast(GenTreeCast* cast)

if ((desc.ExtendKind() != GenIntCastDesc::COPY) || (srcReg != dstReg))
{
instruction ins;

switch (desc.ExtendKind())
{
case GenIntCastDesc::ZERO_EXTEND_SMALL_INT:
Expand Down Expand Up @@ -8431,9 +8429,9 @@ void CodeGen::genFnPrologCalleeRegArgs()
int count = 0; // Number of nodes in list
bool loop = false; // List has a loop

for (unsigned cur = i; regArg[cur] != REG_NA; count++)
for (unsigned cur = (unsigned)i; regArg[cur] != REG_NA; count++)
{
if (cur == i && count > 0)
if (cur == (unsigned)i && count > 0)
{
loop = true;
break;
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/jit/emitriscv64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include "jitpch.h"
#ifdef _MSC_VER
#pragma hdrstop
#pragma warning(disable : 4244 4267)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a number of "possible loss of data" warnings related to the helpers like NBitMask that required adding a bunch of casts in many places in this file. I went with just disabling these warnings since I did not want to uglify all of that code. Perhaps there is a prettier way to fix these warnings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabling this warning is SDL violation:

add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/we4244>) # 'conversion' conversion from 'type1' to 'type2', possible loss of data

It is only ok as long as this code is not getting compiled in official builds.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dotnet/samsung Can you please provide a patch that fixes the warnings in your preferred way without resorting to disabling the warning? Thanks!

Copy link
Member

@clamp03 clamp03 Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jakobbotsch Thank you.
@Bajtazar Could you fix the warnings in emitriscv64.cpp? The most of warnings are casts related to helpers which you have refactored. I think you can fix in prettier way. :)

Copy link
Contributor

@Bajtazar Bajtazar Mar 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I prepared a patch that fixes warnings in the emitriscv64.cpp file

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Bajtazar I think the patch can be merged separately. Could you make another PR for your patch?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@Bajtazar I think the patch can be merged separately. Could you make another PR for your patch?

You can open a separate PR or I can include it in this change. Up to you.

Copy link
Contributor

@Bajtazar Bajtazar Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clamp03 @jakobbotsch I've opened a separate PR with fixes (#100270)

#endif

#if defined(TARGET_RISCV64)
Expand Down Expand Up @@ -4398,7 +4399,7 @@ void emitter::emitDispIns(
emitDispInsInstrNum(id);

const BYTE* instr = pCode + writeableOffset;
size_t instrSize;
unsigned instrSize;
for (size_t i = 0; i < sz; instr += instrSize, i += instrSize, offset += instrSize)
{
// TODO-RISCV64: support different size instructions
Expand Down
11 changes: 0 additions & 11 deletions src/coreclr/pal/inc/rt/ntimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1015,17 +1015,6 @@ typedef IMAGE_RELOCATION UNALIGNED *PIMAGE_RELOCATION;
#define IMAGE_REL_IA64_GPREL32 0x001C
#define IMAGE_REL_IA64_ADDEND 0x001F

//
// LOONGARCH64 relocation types
//
#define IMAGE_REL_LOONGARCH64_PC 0x0003
#define IMAGE_REL_LOONGARCH64_JIR 0x0004

//
// RISCV64 relocation types
//
#define IMAGE_REL_RISCV64_PC 0x0003

//
// CEF relocation types.
//
Expand Down