Skip to content
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

Fix gcc armel/arm64 build #53220

Merged
merged 2 commits into from
Jun 9, 2021
Merged

Conversation

gbalykov
Copy link
Member

@gbalykov gbalykov commented May 25, 2021

Mostly signed/unsigned comparisons, etc.

cc @alpencolt

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 25, 2021
@gbalykov gbalykov force-pushed the gcc-armel-build branch 2 times, most recently from 7de81d5 to 7ab98a8 Compare May 25, 2021 11:01
@gbalykov gbalykov changed the title Fix gcc armel build Fix gcc armel/arm64 build May 25, 2021
@@ -460,7 +460,7 @@ void CodeGen::genLclHeap(GenTree* tree)
}

// regCnt will be the total number of bytes to locAlloc
genSetRegToIcon(regCnt, amount, ((int)amount == amount) ? TYP_INT : TYP_LONG);
genSetRegToIcon(regCnt, amount, ((int)amount >= 0) ? TYP_INT : TYP_LONG);
Copy link
Contributor

Choose a reason for hiding this comment

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

this does not look right, a narrowing cast is implementation-defined in C++.
also, it looks like we don't support TYP_LONG in

// TODO-CrossBitness: we wouldn't need the cast below if we had CodeGen::instGen_Set_Reg_To_Reloc_Imm.

that we are calling here, maybe use ClrSafeInt and cast to int always? cc @echesakovMSFT

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, my bad, thanks. But it seems that original code is incorrect too

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is relevant to CodeGen::instGen_Set_Reg_To_Reloc_Imm issue in cross-bitness scenarious.

The change is for localloc (i.e. .NET way of alloca).

According to ECMA-335

The localloc instruction allocates size (type native unsigned int or U4) bytes from the local
dynamic memory pool ...

I agree with Sergey that we should always use TYP_INT here.

Suggested change
genSetRegToIcon(regCnt, amount, ((int)amount >= 0) ? TYP_INT : TYP_LONG);
genSetRegToIcon(regCnt, amount, TYP_INT);

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed, thanks

@@ -526,7 +526,7 @@ tdep_trace (unw_cursor_t *cursor, void **buffer, int *size)
break;

case UNW_ARM_FRAME_SYSCALL:
printf("XXX1\n");
//printf("XXX1\n");
Copy link
Contributor

Choose a reason for hiding this comment

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

not familiar with this code, what was the problem?

Copy link
Member Author

Choose a reason for hiding this comment

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

[   71s]   In file included from /home/abuild/rpmbuild/BUILD/coreclr-6.0.0/src/coreclr/pal/src/libunwind/src/arm/Ltrace.c:4:
[   71s]   /home/abuild/rpmbuild/BUILD/coreclr-6.0.0/src/coreclr/pal/src/libunwind/src/arm/Gtrace.c: In function '_ULarm_tdep_trace':
[   71s]   /home/abuild/rpmbuild/BUILD/coreclr-6.0.0/src/coreclr/pal/src/libunwind/src/arm/Gtrace.c:529:7: error: incompatible implicit declaration of built-in function 'printf' [-Werror]
[   71s]     529 |       printf("XXX1\n");
[   71s]         |       ^~~~~~
[   71s]   /home/abuild/rpmbuild/BUILD/coreclr-6.0.0/src/coreclr/pal/src/libunwind/src/arm/Gtrace.c:31:1: note: include '<stdio.h>' or provide a declaration of 'printf'
[   71s]      30 | #include <limits.h>
[   71s]     +++ |+#include <stdio.h>
[   71s]      31 |

Copy link
Contributor

Choose a reason for hiding this comment

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

Would adding #include <stdio.h> at the beginning of the file fix the issue or it would introduce some other errors?
cc @janvorli

Copy link
Member

Choose a reason for hiding this comment

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

This should not be modified here. We use a verbatim copy of the libunwind library (https://github.com/libunwind/libunwind) and all necessary changes should be made upstream.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've removed this change from here

@sandreenko
Copy link
Contributor

cc @dotnet/jit-contrib

@@ -319,7 +319,7 @@ class LightWeightMap : public LightWeightMapBuffer

// If we have RTTI, we can make this assert report the correct type. No RTTI, though, when
// built with .NET Core, especially when built against the PAL.
AssertCodeMsg((ptr - bytes) == size, EXCEPTIONCODE_LWM, "%s - Ended with unexpected sizes %p != %x",
AssertCodeMsg((unsigned int)(ptr - bytes) == size, EXCEPTIONCODE_LWM, "%s - Ended with unexpected sizes %p != %x",
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rewrite it as follows to avoid casting

Suggested change
AssertCodeMsg((unsigned int)(ptr - bytes) == size, EXCEPTIONCODE_LWM, "%s - Ended with unexpected sizes %p != %x",
AssertCodeMsg(ptr == (bytes + size), EXCEPTIONCODE_LWM, "%s - Ended with unexpected sizes %p != %x",

@@ -658,7 +658,7 @@ class DenseLightWeightMap : public LightWeightMapBuffer
ptr += bufferLength * sizeof(unsigned char);
}

AssertCodeMsg((ptr - bytes) == size, EXCEPTIONCODE_LWM, "Ended with unexpected sizes %Ix != %x", ptr - bytes,
AssertCodeMsg((unsigned int)(ptr - bytes) == size, EXCEPTIONCODE_LWM, "Ended with unexpected sizes %Ix != %x", ptr - bytes,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Suggested change
AssertCodeMsg((unsigned int)(ptr - bytes) == size, EXCEPTIONCODE_LWM, "Ended with unexpected sizes %Ix != %x", ptr - bytes,
AssertCodeMsg(ptr == (bytes + size), EXCEPTIONCODE_LWM, "Ended with unexpected sizes %Ix != %x", ptr - bytes,

@@ -460,7 +460,7 @@ void CodeGen::genLclHeap(GenTree* tree)
}

// regCnt will be the total number of bytes to locAlloc
genSetRegToIcon(regCnt, amount, ((int)amount == amount) ? TYP_INT : TYP_LONG);
genSetRegToIcon(regCnt, amount, ((int)amount >= 0) ? TYP_INT : TYP_LONG);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is relevant to CodeGen::instGen_Set_Reg_To_Reloc_Imm issue in cross-bitness scenarious.

The change is for localloc (i.e. .NET way of alloca).

According to ECMA-335

The localloc instruction allocates size (type native unsigned int or U4) bytes from the local
dynamic memory pool ...

I agree with Sergey that we should always use TYP_INT here.

Suggested change
genSetRegToIcon(regCnt, amount, ((int)amount >= 0) ? TYP_INT : TYP_LONG);
genSetRegToIcon(regCnt, amount, TYP_INT);

@@ -112,10 +112,6 @@ if(CLR_CMAKE_HOST_ARCH_ARM)
endif()
endif(CLR_CMAKE_HOST_ARCH_ARM)

if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please give an example why the change is needed? Is it assembler related?

Copy link
Member

Choose a reason for hiding this comment

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

This should stay, but the condition should be updated so that it gets added only for Intel processors (CLR_CMAKE_HOST_ARCH_AMD64 or CLR_CMAKE_HOST_ARCH_I386).

Copy link
Member Author

Choose a reason for hiding this comment

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

arm assembler doesn't have this option, and linux x64 shows:

$ as --help|grep divide
  --divide                ignored

Why is this option needed?

Copy link
Member

Choose a reason for hiding this comment

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

This was added for SunOS support. @am11 do you remember why was it needed?

Copy link
Member

Choose a reason for hiding this comment

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

On SYS-V derivative platforms, / in assembly is treated as # rather than division. In context2.S, we are using division, so it breaks build on platforms, such as SunOS-likes and QNX.

Please note that GNU toolchain support is strictly added for community supported platforms in .NET, where LLVM toolchain is either not available or not as complete. If your platform already has good support for LLVM toolchain, it is recommended (per its official support stauts) to use that instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for explanation. I've kept the original GNU condition and added x86/x64 check.

@@ -526,7 +526,7 @@ tdep_trace (unw_cursor_t *cursor, void **buffer, int *size)
break;

case UNW_ARM_FRAME_SYSCALL:
printf("XXX1\n");
//printf("XXX1\n");
Copy link
Contributor

Choose a reason for hiding this comment

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

Would adding #include <stdio.h> at the beginning of the file fix the issue or it would introduce some other errors?
cc @janvorli

@@ -82,7 +82,7 @@ static const CpuCapability CpuCapabilities[] = {
// If the capability name is not recognized or unused at present, zero is returned.
static unsigned long LookupCpuCapabilityFlag(const char* start, size_t length)
{
for (int i = 0; i < _countof(CpuCapabilities); i++)
for (int i = 0; i < (int)_countof(CpuCapabilities); i++)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would avoid casting

Suggested change
for (int i = 0; i < (int)_countof(CpuCapabilities); i++)
for (size_t i = 0; i < _countof(CpuCapabilities); i++)

@gbalykov gbalykov force-pushed the gcc-armel-build branch 2 times, most recently from d05eb6a to 7bd8bb6 Compare May 27, 2021 07:03
Mostly signed/unsigned comparisons, etc.
Copy link
Contributor

@sandreenko sandreenko left a comment

Choose a reason for hiding this comment

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

I see that the PR was updated, LGTM, thanks for making the changes.

@BruceForstall
Copy link
Member

Test failures are #53311

@BruceForstall BruceForstall merged commit f6c52b9 into dotnet:main Jun 9, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jul 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants