Search Issue Tracker

By Design

Votes

0

Found in

2017.4

2018.4

2018.4.0f1

2019.1

2019.2

2019.3

Issue ID

1165188

Regression

No

[Android] Values passed incorrectly through native delegate parameters on ARM64

Mobile

-

Repro steps:
1. Open attached project
2. Copy the libAndroidCppDelegateTest.so (armv8a version) file from folder "nativeAndroidBuild" to Plugin/Android folder
3. Set the CPU value on that plugin to ARM64 in the Inspector
4. Build 64-bit version to an android device, check the output in the log

The values are weird

5. Copy the libAndroidCppDelegateTest.so (armv7a version) file to Plugin/Android folder.
6. Set the CPU to ARMv7 in the Inspector
7. Build a 32-bit version to a device and check the output in the log

Actual: The values using 32-bit are normal while on 64-bit they aren't

Reproducible with: 2017.4.29f1, 2018.4.3f1, 2019.1.8f1, 2019.2.0b7, 2019.3.0a8

Tested and reproduced on these devices:
VLNQA00149, Samsung Galaxy S9 (SM-G960F), Android 9, CPU: Exynos 9 Series 9810, GPU: Mali-G72
VLNQA00124, Google Pixel 2 XL (Pixel 2 XL), Android 9, CPU: Snapdragon 835 MSM8998, GPU: Adreno (TM) 540
VLNQA00009, Samsung Galaxy Note8 (SM-N950F), Android 8.0.0, CPU: Exynos 9 Octa 8895, GPU: Mali-G71

  1. Resolution Note (2019.3.X):

    The problem is in users code.
    Removing explicit layout and field offsets in C# struct fixes the issue.
    The problem is with ABI:
    - on C++ side it is a struct with 3 floats, so it's passed using CPU floating point registers.
    - on C# side explicit layout turns this struct in a small arbitrary struct that is passed using general purpose registers.

    Essentially, struct on both C# and C++ sides have to match the same argument passing rules.
    Another possible way to fix the issue is to use pointer to struct in C++ and ref parameter in C#, so that struct is in memory instead of registers.

    For exact rules see ARM64 ABI:
    http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055b/IHI0055B_aapcs64.pdf

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.