Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[arm64+AOT+LLVM] P/Invoke issues with functions with 10 or more parameters #11627

@grendello

Description

@grendello

From @mathbourgeois on November 8, 2018 3:51

When using the following C function in a p/invoke project from C#, the results after the 9th variable are garbage if you run in ARM64+AOT+LLVM mode only.

C#

        [DllImport("StaticLibrary1")]
        private static extern void functionWithParams20(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l, int m, int n, int o, int p, int q, int r, int s, int t);

...
            functionWithParams20(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19);
            functionWithParams20(19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);

C++

	void functionWithParams20(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j,
		int k, int l, int m, int n, int o, int p, int q, int r, int s, int t)
	{
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of a is %d", a);
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of b is %d", b);
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of c is %d", c);
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of d is %d", d);
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of e is %d", e);
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of f is %d", f);
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of g is %d", g);
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of h is %d", h);
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of i is %d", i);
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of j is %d", j);
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of k is %d", k);
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of l is %d", l);
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of m is %d", m);
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of n is %d", n);
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of o is %d", o);
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of p is %d", p);
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of q is %d", q);
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of r is %d", r);
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of s is %d", s);
		__android_log_print(ANDROID_LOG_ERROR, "USELESS", "The value of t is %d", t);
	}

Steps to Reproduce

You can use the following test project, containing Xamarin.Android C# app and C++ android library containing 3 functions to be p/invoke-d (only the 20-int version actually breaking)

Test.zip

  1. Build and run the application in arm64-v8a (Release|ARM64)
  2. Check resulting logs
  3. Notice the p/invoke logs contain garbage

Expected Behavior

Proper results

11-07 22:33:00.487 30493 30493 E USELESS : The value of a is 0
11-07 22:33:00.487 30493 30493 E USELESS : The value of b is 1
11-07 22:33:00.487 30493 30493 E USELESS : The value of c is 2
11-07 22:33:00.487 30493 30493 E USELESS : The value of d is 3
11-07 22:33:00.487 30493 30493 E USELESS : The value of e is 4
11-07 22:33:00.487 30493 30493 E USELESS : The value of f is 5
11-07 22:33:00.487 30493 30493 E USELESS : The value of g is 6
11-07 22:33:00.487 30493 30493 E USELESS : The value of h is 7
11-07 22:33:00.487 30493 30493 E USELESS : The value of i is 8
11-07 22:33:00.487 30493 30493 E USELESS : The value of j is 9
11-07 22:33:00.487 30493 30493 E USELESS : The value of k is 10
11-07 22:33:00.487 30493 30493 E USELESS : The value of l is 11
11-07 22:33:00.487 30493 30493 E USELESS : The value of m is 12
11-07 22:33:00.487 30493 30493 E USELESS : The value of n is 13
11-07 22:33:00.487 30493 30493 E USELESS : The value of o is 14
11-07 22:33:00.487 30493 30493 E USELESS : The value of p is 15
11-07 22:33:00.487 30493 30493 E USELESS : The value of q is 16
11-07 22:33:00.487 30493 30493 E USELESS : The value of r is 17
11-07 22:33:00.487 30493 30493 E USELESS : The value of s is 18
11-07 22:33:00.487 30493 30493 E USELESS : The value of t is 19
11-07 22:33:00.487 30493 30493 E USELESS : The value of a is 19
11-07 22:33:00.487 30493 30493 E USELESS : The value of b is 18
11-07 22:33:00.487 30493 30493 E USELESS : The value of c is 17
11-07 22:33:00.487 30493 30493 E USELESS : The value of d is 16
11-07 22:33:00.487 30493 30493 E USELESS : The value of e is 15
11-07 22:33:00.487 30493 30493 E USELESS : The value of f is 14
11-07 22:33:00.487 30493 30493 E USELESS : The value of g is 13
11-07 22:33:00.487 30493 30493 E USELESS : The value of h is 12
11-07 22:33:00.487 30493 30493 E USELESS : The value of i is 11
11-07 22:33:00.487 30493 30493 E USELESS : The value of j is 10
11-07 22:33:00.487 30493 30493 E USELESS : The value of k is 9
11-07 22:33:00.487 30493 30493 E USELESS : The value of l is 8
11-07 22:33:00.487 30493 30493 E USELESS : The value of m is 7
11-07 22:33:00.487 30493 30493 E USELESS : The value of n is 6
11-07 22:33:00.487 30493 30493 E USELESS : The value of o is 5
11-07 22:33:00.487 30493 30493 E USELESS : The value of p is 4
11-07 22:33:00.487 30493 30493 E USELESS : The value of q is 3
11-07 22:33:00.487 30493 30493 E USELESS : The value of r is 2
11-07 22:33:00.487 30493 30493 E USELESS : The value of s is 1
11-07 22:33:00.487 30493 30493 E USELESS : The value of t is 0

Actual Behavior

11-07 22:22:49.689 29199 29199 E USELESS : The value of a is 0
11-07 22:22:49.689 29199 29199 E USELESS : The value of b is 1
11-07 22:22:49.689 29199 29199 E USELESS : The value of c is 2
11-07 22:22:49.689 29199 29199 E USELESS : The value of d is 3
11-07 22:22:49.689 29199 29199 E USELESS : The value of e is 4
11-07 22:22:49.689 29199 29199 E USELESS : The value of f is 5
11-07 22:22:49.689 29199 29199 E USELESS : The value of g is 6
11-07 22:22:49.689 29199 29199 E USELESS : The value of h is 7
11-07 22:22:49.689 29199 29199 E USELESS : The value of i is 8
11-07 22:22:49.689 29199 29199 E USELESS : The value of j is 10
11-07 22:22:49.689 29199 29199 E USELESS : The value of k is 12
11-07 22:22:49.689 29199 29199 E USELESS : The value of l is 14
11-07 22:22:49.689 29199 29199 E USELESS : The value of m is 16
11-07 22:22:49.689 29199 29199 E USELESS : The value of n is 18
11-07 22:22:49.689 29199 29199 E USELESS : The value of o is 0
11-07 22:22:49.689 29199 29199 E USELESS : The value of p is 2
11-07 22:22:49.689 29199 29199 E USELESS : The value of q is -1266594656
11-07 22:22:49.689 29199 29199 E USELESS : The value of r is 976037344
11-07 22:22:49.689 29199 29199 E USELESS : The value of s is 8
11-07 22:22:49.689 29199 29199 E USELESS : The value of t is -1621012387
11-07 22:22:49.689 29199 29199 E USELESS : The value of a is 19
11-07 22:22:49.689 29199 29199 E USELESS : The value of b is 18
11-07 22:22:49.689 29199 29199 E USELESS : The value of c is 17
11-07 22:22:49.689 29199 29199 E USELESS : The value of d is 16
11-07 22:22:49.689 29199 29199 E USELESS : The value of e is 15
11-07 22:22:49.689 29199 29199 E USELESS : The value of f is 14
11-07 22:22:49.689 29199 29199 E USELESS : The value of g is 13
11-07 22:22:49.689 29199 29199 E USELESS : The value of h is 12
11-07 22:22:49.689 29199 29199 E USELESS : The value of i is 11
11-07 22:22:49.689 29199 29199 E USELESS : The value of j is 9
11-07 22:22:49.689 29199 29199 E USELESS : The value of k is 7
11-07 22:22:49.689 29199 29199 E USELESS : The value of l is 5
11-07 22:22:49.689 29199 29199 E USELESS : The value of m is 3
11-07 22:22:49.689 29199 29199 E USELESS : The value of n is 1
11-07 22:22:49.689 29199 29199 E USELESS : The value of o is 0
11-07 22:22:49.689 29199 29199 E USELESS : The value of p is 2
11-07 22:22:49.689 29199 29199 E USELESS : The value of q is -1266594656
11-07 22:22:49.689 29199 29199 E USELESS : The value of r is 976037344
11-07 22:22:49.689 29199 29199 E USELESS : The value of s is 8
11-07 22:22:49.689 29199 29199 E USELESS : The value of t is -1621012387

Version Information

Microsoft Visual Studio Community 2017
Version 15.8.9
VisualStudio.15.Release/15.8.9+28010.2050
Microsoft .NET Framework
Version 4.7.03056

Installed Version: Community

Visual C++ 2017 00369-60000-00001-AA737
Microsoft Visual C++ 2017

Application Insights Tools for Visual Studio Package 8.13.10627.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017 15.8.05085.0
ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services 15.8.31590
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2017 5.2.60618.0
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0 15.8.05023.0
Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools 15.8.05023.0
Azure Functions and Web Jobs Tools

C# Tools 2.9.0-beta8-63208-01
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter 15.8.18241.1
Provides tools for finding, instantiating and customizing templates in cookiecutter format.

Extensibility Message Bus 1.1.49 (remotes/origin/d15-8@ee674f3)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

JavaScript Language Service 2.0
JavaScript Language Service

JavaScript Project System 2.0
JavaScript Project System

Microsoft Azure Tools 2.9
Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.10730.2

Microsoft Continuous Delivery Tools for Visual Studio 0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager 1.0
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger 1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards 1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers 1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package 1.0
Microsoft Visual Studio VC Package

MLGen Package Extension 1.0
MLGen Package Visual Studio Extension Detailed Info

Mono Debugging for Visual Studio 4.11.11-pre (8fb558f)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 4.6.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Office Developer Tools for Visual Studio 2017 ENU 15.0.27907.01
Microsoft Office Developer Tools for Visual Studio 2017 ENU

ProjectServicesPackage Extension 1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

Python 15.8.18241.1
Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Python - Django support 15.8.18241.1
Provides templates and integration for the Django web framework.

Python - IronPython support 15.8.18241.1
Provides templates and integration for IronPython-based projects.

Python - Profiling support 15.8.18241.1
Profiling support for Python projects.

ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info

RustLanguageExtensionOptionsPackage Extension 1.0
RustLanguageExtensionOptionsPackage Visual Studio Extension Detailed Info

SQL Server Data Tools 15.1.61808.07020
Microsoft SQL Server Data Tools

Test Adapter for Boost.Test 1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test 1.0
Enables Visual Studio's testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory.

TypeScript Tools 15.8.20822.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 2.9.0-beta8-63208-01
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual C++ for Cross Platform Mobile Development (Android) 15.0.27924.00
Visual C++ for Cross Platform Mobile Development (Android)

Visual C++ for Linux Development 1.0.9.27924
Visual C++ for Linux Development

Visual F# Tools 10.2 for F# 4.5 15.8.0.0. Commit Hash: 55a3dc3231c95c77f81ee53f7d29152029da7408.
Microsoft Visual F# Tools 10.2 for F# 4.5

Visual Studio Code Debug Adapter Host Package 1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for CMake 1.0
Visual Studio Tools for CMake

Visual Studio Tools for Containers 1.0
Visual Studio Tools for Containers

Visual Studio Tools for Universal Windows Apps 15.0.28010.2046
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

VisualStudio.Mac 1.0
Mac Extension for Visual Studio

Workflow Manager Tools 1.0 1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin 4.11.0.779 (d15-8@ff915e800)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 4.15.12 (d7ff6f39c)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 1.1.118 (4217ee9)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 9.0.0.19 (HEAD/a8a3b0ec7)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK 12.1.0.15 (cbfb047)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Copied from original issue: dotnet/android#2406

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions