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

Need support of 64 bit arch and pointers #88

Open
hardikbhalodi opened this issue Jul 27, 2024 · 0 comments
Open

Need support of 64 bit arch and pointers #88

hardikbhalodi opened this issue Jul 27, 2024 · 0 comments

Comments

@hardikbhalodi
Copy link

hardikbhalodi commented Jul 27, 2024

Port 32-bit code to 64-bit
If your code already runs on the desktop or iOS, you shouldn't need to do any extra work for Android. If this is the first time your code has been built for a 64-bit system, the main issue you must address is that pointers no longer fit in 32-bit integer types like int.

Update code that stores pointers in types such as int, unsigned, or uint32_t. On Unix systems, long matches the pointer size, but this isn't true on Windows. Instead, use the intention-revealing types uintptr_t or intptr_t. To store the difference between two pointers, use the ptrdiff_t type.

You should always prefer the specific, fixed-width integer types defined in <stdint.h> rather than non fixed-width types such as int or long, even for non-pointers.

Use the following compiler flags to catch cases where your code is incorrectly converting between pointers and integers:
-Werror=pointer-to-int-cast
-Werror=int-to-pointer-cast
-Werror=shorten-64-to-32

Java classes with int fields that hold pointers to C/C++ objects have the same problem. Search for jint in your JNI source and ensure that you switch to long on the Java side and jlong on the C++ side.

Implicit function declarations are a lot more dangerous for 64-bit code. C/C++ assume that the return type of an implicitly declared function (that is, a function that the compiler hasn't seen a declaration for) is int. If the actual return type of your function is a pointer, this works fine on a 32-bit system where your pointer fits into an int. However, on a 64-bit system, the compiler drops the top half of your pointer. For example:

// This function returns a pointer:
// extern char* foo();

// If you don't include a header that declares it,
// when the compiler sees this:
char* result = foo();

// Instead of compiling that to:
result = foo();

// It compiles to something equivalent to:
result = foo() & 0xffffffff;

// Which will then cause a SIGSEGV if you try to dereference result

Reference
https://developer.android.com/google/play/requirements/64-bit

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

No branches or pull requests

1 participant