mirror of
https://github.com/chromium/crashpad.git
synced 2024-12-26 06:31:50 +08:00
android: NDK r16 compatibility
This updates build/gyp_crashpad_android.py to define the android_api_level GYP variable whenver unified headers are in use. Previously, it was only set when compiling with GCC and using unified headers. This pairs with https://crrev.com/c/804574 to allow proper detection of when _FILE_OFFSET_BITS=64 would be inappropriate. Since there’s no longer any possibility of using a 64-bit off_t with API < 21, this also drops the compatibility wrapper for mmap() that allowed this configuration to work. Too bad, I liked this, but it’s pointless to carry now. The development documentation is also updated to refer to NDK r16. mini_chromium is updated to 88e056258a01450b07414642fa5fb98493c1f6ce. f609089390cd fuchsia: Add ZX_LOG, et al. to mini_chromium 0a8c5de30c67 fuchsia: Fix RandBytes() ZX_CHECK message string 88e056258a01 android: Don’t use _FILE_OFFSET_BITS=64 until API 21 Change-Id: I932116e0c01bcddd5719f9091a070d504eae600f Reviewed-on: https://chromium-review.googlesource.com/804555 Commit-Queue: Mark Mentovai <mark@chromium.org> Reviewed-by: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
parent
eeb31321f7
commit
5969d6b1eb
2
DEPS
2
DEPS
@ -28,7 +28,7 @@ deps = {
|
||||
'5e2b3ddde7cda5eb6bc09a5546a76b00e49d888f',
|
||||
'crashpad/third_party/mini_chromium/mini_chromium':
|
||||
Var('chromium_git') + '/chromium/mini_chromium@' +
|
||||
'fa146c1264953b42baccfc261dc6aa59a1661d26',
|
||||
'88e056258a01450b07414642fa5fb98493c1f6ce',
|
||||
'crashpad/third_party/zlib/zlib':
|
||||
Var('chromium_git') + '/chromium/src/third_party/zlib@' +
|
||||
'13dc246a58e4b72104d35f9b1809af95221ebda7',
|
||||
|
@ -69,26 +69,32 @@ def main(args):
|
||||
os.environ['CXX_target'] = os.path.join(ndk_bin_dir,
|
||||
'%s-g++' % arch_triplet)
|
||||
|
||||
# Unlike the Clang build, when using GCC with “unified headers,”
|
||||
# __ANDROID_API__ isn’t set automatically and must be pushed in to the
|
||||
# build. Fish the correct value out of the Clang wrapper script. If unified
|
||||
# headers are not being used, the Clang wrapper won’t mention
|
||||
# __ANDROID_API__, but the standalone toolchain’s <android/api-level.h> will
|
||||
# #define it for both Clang and GCC.
|
||||
#
|
||||
# Unified headers are the way of the future, according to
|
||||
# https://android.googlesource.com/platform/ndk/+/ndk-r14/CHANGELOG.md and
|
||||
# https://android.googlesource.com/platform/ndk/+/master/docs/UnifiedHeaders.md.
|
||||
with open(clang_path, 'r') as file:
|
||||
clang_script_contents = file.read()
|
||||
matches = re.finditer(r'\s-D__ANDROID_API__=([\d]+)\s',
|
||||
clang_script_contents)
|
||||
match = next(matches, None)
|
||||
if match:
|
||||
android_api = int(match.group(1))
|
||||
extra_args.extend(['-D', 'android_api_level=%d' % android_api])
|
||||
if next(matches, None):
|
||||
raise AssertionError('__ANDROID_API__ defined too many times')
|
||||
# Unlike the Clang build, when using GCC with unified headers, __ANDROID_API__
|
||||
# isn’t set automatically and must be pushed in to the build. Fish the correct
|
||||
# value out of the Clang wrapper script. If deprecated headers are in use, the
|
||||
# Clang wrapper won’t mention __ANDROID_API__, but the standalone toolchain’s
|
||||
# <android/api-level.h> will #define it for both Clang and GCC.
|
||||
#
|
||||
# android_api_level is extracted in this manner even when compiling with Clang
|
||||
# so that it’s available for use in GYP conditions that need to test the API
|
||||
# level, but beware that it’ll only be available when unified headers are in
|
||||
# use.
|
||||
#
|
||||
# Unified headers are the way of the future, according to
|
||||
# https://android.googlesource.com/platform/ndk/+/ndk-r14/CHANGELOG.md and
|
||||
# https://android.googlesource.com/platform/ndk/+/master/docs/UnifiedHeaders.md.
|
||||
# Traditional (deprecated) headers have been removed entirely as of NDK r16.
|
||||
# https://android.googlesource.com/platform/ndk/+/ndk-release-r16/CHANGELOG.md.
|
||||
with open(clang_path, 'r') as file:
|
||||
clang_script_contents = file.read()
|
||||
matches = re.finditer(r'\s-D__ANDROID_API__=([\d]+)\s',
|
||||
clang_script_contents)
|
||||
match = next(matches, None)
|
||||
if match:
|
||||
android_api = int(match.group(1))
|
||||
extra_args.extend(['-D', 'android_api_level=%d' % android_api])
|
||||
if next(matches, None):
|
||||
raise AssertionError('__ANDROID_API__ defined too many times')
|
||||
|
||||
for tool in ('ar', 'nm', 'readelf'):
|
||||
os.environ['%s_target' % tool.upper()] = (
|
||||
|
@ -1,103 +0,0 @@
|
||||
// Copyright 2017 The Crashpad Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 21
|
||||
|
||||
// Bionic has provided a wrapper for __mmap2() since the beginning of time. See
|
||||
// bionic/libc/SYSCALLS.TXT in any Android version.
|
||||
extern "C" void* __mmap2(void* addr,
|
||||
size_t size,
|
||||
int prot,
|
||||
int flags,
|
||||
int fd,
|
||||
size_t pgoff);
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename T>
|
||||
T Align(T value, uint8_t alignment) {
|
||||
return (value + alignment - 1) & ~(alignment - 1);
|
||||
}
|
||||
|
||||
// Adapted from Android 8.0.0 bionic/libc/bionic/mmap.cpp.
|
||||
void* LocalMmap64(void* addr,
|
||||
size_t size,
|
||||
int prot,
|
||||
int flags,
|
||||
int fd,
|
||||
off64_t offset) {
|
||||
constexpr int kMmap2Shift = 12;
|
||||
|
||||
if (offset < 0 || (offset & ((1UL << kMmap2Shift) - 1)) != 0) {
|
||||
errno = EINVAL;
|
||||
return MAP_FAILED;
|
||||
}
|
||||
|
||||
const size_t rounded = Align(size, getpagesize());
|
||||
if (rounded < size || rounded > PTRDIFF_MAX) {
|
||||
errno = ENOMEM;
|
||||
return MAP_FAILED;
|
||||
}
|
||||
|
||||
const bool is_private_anonymous =
|
||||
(flags & (MAP_PRIVATE | MAP_ANONYMOUS)) == (MAP_PRIVATE | MAP_ANONYMOUS);
|
||||
const bool is_stack_or_grows_down =
|
||||
(flags & (MAP_STACK | MAP_GROWSDOWN)) != 0;
|
||||
|
||||
void* const result =
|
||||
__mmap2(addr, size, prot, flags, fd, offset >> kMmap2Shift);
|
||||
|
||||
static bool kernel_has_MADV_MERGEABLE = true;
|
||||
if (result != MAP_FAILED && kernel_has_MADV_MERGEABLE &&
|
||||
is_private_anonymous && !is_stack_or_grows_down) {
|
||||
const int saved_errno = errno;
|
||||
const int rc = madvise(result, size, MADV_MERGEABLE);
|
||||
if (rc == -1 && errno == EINVAL) {
|
||||
kernel_has_MADV_MERGEABLE = false;
|
||||
}
|
||||
errno = saved_errno;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C" {
|
||||
|
||||
void* mmap(void* addr, size_t size, int prot, int flags, int fd, off_t offset) {
|
||||
// Use the system’s mmap64() wrapper if available. It will be available on
|
||||
// Android 5.0 (“Lollipop”) and later.
|
||||
using Mmap64Type = void* (*)(void*, size_t, int, int, int, off64_t);
|
||||
static const Mmap64Type mmap64 =
|
||||
reinterpret_cast<Mmap64Type>(dlsym(RTLD_DEFAULT, "mmap64"));
|
||||
if (mmap64) {
|
||||
return mmap64(addr, size, prot, flags, fd, offset);
|
||||
}
|
||||
|
||||
// Otherwise, use the local implementation, which should amount to exactly the
|
||||
// same thing.
|
||||
return LocalMmap64(addr, size, prot, flags, fd, offset);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
#endif // defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 21
|
@ -1,43 +0,0 @@
|
||||
// Copyright 2017 The Crashpad Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef CRASHPAD_COMPAT_ANDROID_SYS_MMAN_H_
|
||||
#define CRASHPAD_COMPAT_ANDROID_SYS_MMAN_H_
|
||||
|
||||
#include_next <sys/mman.h>
|
||||
|
||||
#include <android/api-level.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
// There’s no mmap() wrapper compatible with a 64-bit off_t for 32-bit code
|
||||
// until API 21 (Android 5.0/“Lollipop”). A custom mmap() wrapper is provided
|
||||
// here. Note that this scenario is only possible with NDK unified headers.
|
||||
//
|
||||
// https://android.googlesource.com/platform/bionic/+/0bfcbaf4d069e005d6e959d97f8d11c77722b70d/docs/32-bit-abi.md#is-32_bit-1
|
||||
|
||||
#if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 21
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void* mmap(void* addr, size_t size, int prot, int flags, int fd, off_t offset);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // defined(__USE_FILE_OFFSET64) && __ANDROID_API__ < 21
|
||||
|
||||
#endif // CRASHPAD_COMPAT_ANDROID_SYS_MMAN_H_
|
@ -26,8 +26,6 @@
|
||||
'android/linux/prctl.h',
|
||||
'android/linux/ptrace.h',
|
||||
'android/sched.h',
|
||||
'android/sys/mman.cc',
|
||||
'android/sys/mman.h',
|
||||
'android/sys/syscall.h',
|
||||
'android/sys/user.h',
|
||||
'linux/signal.h',
|
||||
|
@ -119,7 +119,7 @@ Kit)](https://developer.android.com/ndk/) runs on.
|
||||
If it’s not already present on your system, [download the NDK package for your
|
||||
system](https://developer.android.com/ndk/downloads/) and expand it to a
|
||||
suitable location. These instructions assume that it’s been expanded to
|
||||
`~/android-ndk-r15b`.
|
||||
`~/android-ndk-r16`.
|
||||
|
||||
To build Crashpad, portions of the NDK must be reassembled into a [standalone
|
||||
toolchain](https://developer.android.com/ndk/guides/standalone_toolchain.html).
|
||||
@ -133,8 +133,8 @@ desired. To build a standalone toolchain targeting 64-bit ARM and API level 21
|
||||
|
||||
```
|
||||
$ cd ~
|
||||
$ python android-ndk-r15b/build/tools/make_standalone_toolchain.py \
|
||||
--arch=arm64 --api=21 --install-dir=android-ndk-r15b_arm64_api21
|
||||
$ python android-ndk-r16/build/tools/make_standalone_toolchain.py \
|
||||
--arch=arm64 --api=21 --install-dir=android-ndk-r16_arm64_api21
|
||||
```
|
||||
|
||||
Note that Chrome uses Android API level 21 for 64-bit platforms and 16 for
|
||||
@ -152,7 +152,7 @@ operation.
|
||||
```
|
||||
$ cd ~/crashpad/crashpad
|
||||
$ python build/gyp_crashpad_android.py \
|
||||
--ndk ~/android-ndk-r15b_arm64_api21 \
|
||||
--ndk ~/android-ndk-r16_arm64_api21 \
|
||||
--generator-output out/android_arm64_api21
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user