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

NDK 15 breaks mmap on Nexus 5 #449

Closed
greenrobot opened this issue Jul 10, 2017 · 9 comments
Closed

NDK 15 breaks mmap on Nexus 5 #449

greenrobot opened this issue Jul 10, 2017 · 9 comments
Assignees

Comments

@greenrobot
Copy link

Description

Using NDK 15.1.4119039 we are seeing a weird runtime failure in our app and tests on certain devices. We tracked it done to this source line:

r = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

On a Nexus 5 running Android 6.0.1, this will fail (MAP_FAILED returned) with errno == EINVAL. With earlier NDKs this was never a problem. Also, when running on a Nexus 5x, it is not a problem when building with NDK15.

Environment Details

  • NDK Version: 15.1.4119039
  • Build sytem: cmake
  • Host OS: Windows
  • Compiler: Clang ("-DANDROID_TOOLCHAIN=clang" passed via gradle externalNativeBuild.cmake.arguments)
  • ABI: "armeabi-v7a" (others built are "arm64-v8a" and "x86")
  • STL: "-DANDROID_STL=c++_static"
  • NDK API level: 25
  • Device API level: 23
@enh
Copy link
Contributor

enh commented Jul 10, 2017

are you building with _FILE_OFFSET_BITS=64 by any chance?

@enh enh self-assigned this Jul 10, 2017
@greenrobot
Copy link
Author

@enh Yes

@enh
Copy link
Contributor

enh commented Jul 10, 2017

yeah, that should be fixed by https://android-review.googlesource.com/429481/. in the meantime, not building with _FILE_OFFSET_BITS=64 is a workaround.

@greenrobot
Copy link
Author

Thanks. I'll just stick to NDK14b until the next NDK release.

@DanAlbert
Copy link
Member

Just don't set _FILE_OFFSET_BITS=64 for pre-L targets. The difference between r14 and r15 here is that doing that used to be a no-op. Even when we do fix this, your code still won't build if you're setting that for 32-bit code because there wasn't an mmap64 for your target API level.

@DanAlbert
Copy link
Member

Oh, actually:

NDK API level: 25
Device API level: 23

Don't do that. NDK API level is the minimum version your app supports.

That said, mmap64 was in 21 and you're targeting 25, so this shouldn't be a problem... @enh is taking a closer look.

@enh
Copy link
Contributor

enh commented Jul 10, 2017

yeah, seems like we're still missing something here. is this literally the code? offset is 0?

r = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

i don't suppose you know how to run strace to see what's really going on? if not, do you have a small reproduceable test case?

@greenrobot
Copy link
Author

Actually, my gradle setup is:

    minSdkVersion 10
    targetSdkVersion 25

and yes, that's literally the code. Haven't used strace yet.

hubot pushed a commit to aosp-mirror/platform_bionic that referenced this issue Jul 10, 2017
We had several bugs filed saying "if I set _FILE_OFFSET_BITS=64 when
targeting an API < L, various functions are missing". Instead of
saying "yes, they are", we quietly just modified the header files to
expose the non-64-bit variants. This makes no sense. We can't just say
"oh, yeah, we don't have a version of this function that agrees with
your calling code about how large off_t is, but here's a version that
doesn't: I'm sure it'll be fine".

_FILE_OFFSET_BITS=64 on Android LP32 has always been a game of chance,
but that game should be "are all the functions my code needs available
at compile time?", not "will my code actually work at run time?".

Bug: android/ndk#449
Bug: android/ndk#442
Bug: android/ndk#333
Bug: android/ndk#332
Bug: android/ndk#324
Test: builds
Change-Id: Ib095251d3e21e77ed50cc3575388107fecec4ecd
@DanAlbert
Copy link
Member

For the NDK your target API is actually your minSdkVersion (just confirmed that with one of our gradle people). With r15 if you set it something lower than we support (like 10), we'll bump you up to the minimum (14), so your actual NDK API level should be 14.

In that case, you are hitting the case of the other bug. You'll need to make sure you're not passing -D_FILE_OFFSET_BITS=64 for targets that old and then everything should work fine.

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

No branches or pull requests

3 participants