android: Don’t compete with NDK API >= 21 over NDK structures

Chrome uses API 16 for 32-bit builds and API 21 for 64-bit builds. The
NDK’s <link.h> provides r_debug and link_map structure definitions only
at API 21 and above. Breakpad used a custom <link.h> to define these
structures only during 64-bit builds, which worked for Chrome’s
purposes. However, other consumers may wish to build Breakpad at
arbitrary API levels without regard to bitness. This alters Breakpad’s
custom <link.h> to correctly check the NDK API level rather than target
CPU bitness.

Likewise for <sys/user.h> on 32-bit x86, which provided a typedef for
user_fpxregs_struct to user_fxsr_struct. API 21 and above, as well as
the unified headers at any API level, always name the structure
user_fpxregs_struct.

Definitions for 64-bit ARM’s user_regs_struct and user_fpsimd_struct
have been removed from Breakpad’s copy of <sys/user.h>. The header
claims that these fallback definitions are only necessary with NDK r10,
which should no longer be in use even by Chromium, which now uses NDK
r12b. This removes the Chromium-specific ANDROID_NDK_MAJOR_VERSION macro
from use entirely.

Fixes https://stackoverflow.com/questions/44141159/ and b/65630828.

Bug: google-breakpad:733
Change-Id: I5841906297cd15b15ce48b73fd8332fd40afc9a0
Reviewed-on: https://chromium-review.googlesource.com/665740
Reviewed-by: Primiano Tucci <primiano@chromium.org>
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
Mark Mentovai 2017-09-16 00:35:46 -04:00
parent dea867e76f
commit afa9c52715
2 changed files with 26 additions and 40 deletions

View File

@ -34,10 +34,16 @@
Provide custom version here. */ Provide custom version here. */
#include_next <link.h> #include_next <link.h>
// TODO(rmcilroy): Remove this file once the ndk is updated for other #include <android/api-level.h>
// architectures - crbug.com/358831
#if !defined(__aarch64__) && !defined(__x86_64__) && \ // TODO(rmcilroy): Remove this file once the NDK API level is updated to at
!(defined(__mips__) && _MIPS_SIM == _ABI64) // least 21 for all architectures. https://crbug.com/358831
// These structures are only present in traditional headers at API level 21 and
// above. Unified headers define these structures regardless of the chosen API
// level. __ANDROID_API_N__ is a proxy for determining whether unified headers
// are in use. Its only defined by unified headers.
#if __ANDROID_API__ < 21 && !defined(__ANDROID_API_N__)
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -66,6 +72,6 @@ struct link_map {
} // extern "C" } // extern "C"
#endif // __cplusplus #endif // __cplusplus
#endif // !defined(__aarch64__) && !defined(__x86_64__) #endif // __ANDROID_API__ < 21 && !defined(__ANDROID_API_N__)
#endif /* GOOGLE_BREAKPAD_ANDROID_INCLUDE_LINK_H */ #endif /* GOOGLE_BREAKPAD_ANDROID_INCLUDE_LINK_H */

View File

@ -34,52 +34,32 @@
// glibc) and therefore avoid doing otherwise awkward #ifdefs in the code. // glibc) and therefore avoid doing otherwise awkward #ifdefs in the code.
// The following quirks are currently handled by this file: // The following quirks are currently handled by this file:
// - i386: Use the Android NDK but alias user_fxsr_struct > user_fpxregs_struct. // - i386: Use the Android NDK but alias user_fxsr_struct > user_fpxregs_struct.
// - aarch64:
// - NDK r10: Add missing user_regs_struct and user_fpsimd_struct structs.
// - NDK r11+: Add missing <stdint.h> include
// - Other platforms: Just use the Android NDK unchanged.
// TODO(primiano): remove these changes after Chromium has stably rolled to // TODO(primiano): remove these changes after Chromium has stably rolled to
// an NDK with the appropriate fixes. // an NDK with the appropriate fixes. https://crbug.com/358831
#if defined(ANDROID_NDK_MAJOR_VERSION) && ANDROID_NDK_MAJOR_VERSION > 10
#ifdef __aarch64__
#include <stdint.h>
#endif // __aarch64__
#endif // defined(ANDROID_NDK_MAJOR_VERSION) && ANDROID_NDK_MAJOR_VERSION > 10
#include_next <sys/user.h> #include_next <sys/user.h>
#ifdef __i386__ #include <android/api-level.h>
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
typedef struct user_fxsr_struct user_fpxregs_struct;
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif // __i386__
#if !defined(ANDROID_NDK_MAJOR_VERSION) || ANDROID_NDK_MAJOR_VERSION == 10
#ifdef __aarch64__
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif // __cplusplus #endif // __cplusplus
struct user_regs_struct {
__u64 regs[31]; #if defined(__i386__)
__u64 sp; #if __ANDROID_API__ < 21 && !defined(__ANDROID_API_N__)
__u64 pc;
__u64 pstate; // user_fpxregs_struct was called user_fxsr_struct in traditional headers before
}; // API level 21. Unified headers call it user_fpxregs_struct regardless of the
struct user_fpsimd_struct { // chosen API level. __ANDROID_API_N__ is a proxy for determining whether
__uint128_t vregs[32]; // unified headers are in use. Its only defined by unified headers.
__u32 fpsr; typedef struct user_fxsr_struct user_fpxregs_struct;
__u32 fpcr;
}; #endif // __ANDROID_API__ < 21 && !defined(__ANDROID_API_N__)
#endif // defined(__i386__)
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
#endif // __cplusplus #endif // __cplusplus
#endif // __aarch64__
#endif // defined(ANDROID_NDK_VERSION) && ANDROID_NDK_MAJOR_VERSION == 10
#endif // GOOGLE_BREAKPAD_COMMON_ANDROID_INCLUDE_SYS_USER_H #endif // GOOGLE_BREAKPAD_COMMON_ANDROID_INCLUDE_SYS_USER_H