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

AMD64 Register dumper is used on ARM platforms. #3840

Closed
kirillp opened this issue Sep 27, 2021 · 16 comments
Closed

AMD64 Register dumper is used on ARM platforms. #3840

kirillp opened this issue Sep 27, 2021 · 16 comments
Assignees

Comments

@kirillp
Copy link

kirillp commented Sep 27, 2021

Currently, on Darwin systems only AMD64 register dumper is used, even on ARM (Platform.IOS_AARCH64):

@Platforms({Platform.DARWIN.class})
@AutomaticFeature
class DarwinUContextRegisterDumperFeature implements Feature {

This defect lead to weird behaviour like request for AMD64 registers in .cap files during IOS_AARCH64 build:

NativeCodeInfo:PosixDirectives:StructInfo:struct___darwin_mcontext64:StructFieldInfo:__ss___rax:PropertyInfo:size=8

All versions of GraalVM affected.

kirillp pushed a commit to Montura/graal that referenced this issue Sep 27, 2021
add DarwinArmUContextRegisterDumperFeature for Platform.IOS_AARCH64
@kirillp
Copy link
Author

kirillp commented Sep 27, 2021

suggested fix: Montura@f04db55

@teshull teshull self-assigned this Sep 28, 2021
@teshull
Copy link
Member

teshull commented Sep 28, 2021

The suggested fix doesn't really fix the issue; the methods should be populated correctly.

@kirillp
Copy link
Author

kirillp commented Sep 28, 2021

It prevents from invalid memory access. We can file a new issues to improve ARMRegisterDumper.

@kirillp
Copy link
Author

kirillp commented Sep 28, 2021

This fix works for iOS development and production.
We have very clear and readable crash reports on console.firebase.google.com for production application.
As well as clear stack-traces during product debug and testing.

I agree that ARMRegisterDumper need more work to be better, but it can be done later and it minor.

@Montura
Copy link

Montura commented Oct 4, 2021

@teshull, hi!

What about this fix Montura@d2f5b59. Is it enough?

Or I have to "fill" MContextArm64 with all the fields from _STRUCT_MCONTEXT64

https://github.com/xybp888/iOS-SDKs/blob/master/iPhoneOS11.2.sdk/usr/include/arm/_mcontext.h#L61

#define _STRUCT_MCONTEXT64	struct __darwin_mcontext64
{
	_STRUCT_ARM_EXCEPTION_STATE64	__es;
	_STRUCT_ARM_THREAD_STATE64	__ss;
	_STRUCT_ARM_NEON_STATE64	__ns;
};

https://github.com/xybp888/iOS-SDKs/blob/master/iPhoneOS11.2.sdk/usr/include/mach/arm/_structs.h#L96

#define _STRUCT_ARM_THREAD_STATE64	struct __darwin_arm_thread_state64
_STRUCT_ARM_THREAD_STATE64
{
	__uint64_t    __x[29];	/* General purpose registers x0-x28 */
	__uint64_t    __fp;		/* Frame pointer x29 */
	__uint64_t    __lr;		/* Link register x30 */
	__uint64_t    __sp;		/* Stack pointer x31 */
	__uint64_t    __pc;		/* Program counter */
	__uint32_t    __cpsr;	/* Current program status register */
	__uint32_t    __pad;    /* Same size for 32-bit or 64-bit clients */
};

Anyway I can't fill this methods properly, because I don't know in which general-purpose registers (x[29]) do you save HeapBase and Thread pointers.

class DarwinArmUContextRegisterDumper implements UContextRegisterDumper {
    @Override
    @Uninterruptible(reason = "Called from uninterruptible code", mayBeInlined = true)
    public PointerBase getHeapBase(ucontext_t uContext) {
        Signal.MContext64Arm sigcontext = uContext.uc_mcontext64_arm();
        return WordFactory.nullPointer();
    }

    @Override
    @Uninterruptible(reason = "Called from uninterruptible code", mayBeInlined = true)
    public PointerBase getThreadPointer(ucontext_t uContext) {
        Signal.MContext64Arm sigcontext = uContext.uc_mcontext64_arm();
        return WordFactory.nullPointer();
    }
}

@teshull
Copy link
Member

teshull commented Oct 4, 2021

Hi @Montura Thanks for the reference to the aarch64 structs. I started to look at this as well earlier today. I should merge a solution into master in the next week or so.

For future reference, on AArch64 the thread pointer is r28 and heap base pointer is 27. This information can be found in com.oracle.svm.core.graal.aarch64.AArch64ReservedRegisters

@teshull
Copy link
Member

teshull commented Oct 4, 2021

@Montura @kirillp Can you check if #3859 fixes your issue?

@Montura
Copy link

Montura commented Oct 4, 2021

@teshull, I'll check it tomorrow.

@kirillp
Copy link
Author

kirillp commented Oct 5, 2021

@teshull the patch looks good. Nice that you did all the remaining renames.
As I can see we are loosing one register on iOS, interesting will it affect performance much.
74b024e

@kirillp
Copy link
Author

kirillp commented Oct 6, 2021

  features->fFP = !!(cpu_has("hw.optional.floatingpoint"));
  features->fASIMD = !!(cpu_has("hw.optional.neon"));

do we need to check it ?
AFIAK all Apple ARM 64 bit processors support FP and ASIMD from the 1st version.

@teshull
Copy link
Member

teshull commented Oct 7, 2021

I like to keep this code the same as in HotSpot; it doesn't hurt to keep it in

@kirillp
Copy link
Author

kirillp commented Oct 13, 2021

can we see this in 21.3 ?

@teshull
Copy link
Member

teshull commented Oct 13, 2021

No, unfortunately it is too late for that. #3859 will be part of 22.0

@teshull teshull closed this as completed Oct 13, 2021
@kirillp
Copy link
Author

kirillp commented Oct 13, 2021

This is not good, we have to use own build again in CI. We could do my fix for 21.3 and yours for 22

@teshull
Copy link
Member

teshull commented Oct 14, 2021

The freeze for 21.3 was ~ a month ago, so it's too late to put any new things into it. If you don't want to build yourself, I imagine soon a nightly for 22.0 should be available here: https://github.com/graalvm/graalvm-ce-dev-builds/releases

@kirillp
Copy link
Author

kirillp commented Dec 28, 2021

@Montura @kirillp Can you check if #3859 fixes your issue?

@teshull
Hello, I found a new issue: #4162

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants