diff options
39 files changed, 127 insertions, 99 deletions
diff --git a/android-changes-for-ndk-developers.md b/android-changes-for-ndk-developers.md index 069b004e7..8925926e9 100644 --- a/android-changes-for-ndk-developers.md +++ b/android-changes-for-ndk-developers.md @@ -221,3 +221,16 @@ $ readelf --program-headers -W libBadFlags.so | grep WE *Resolution*: we're aware of one middleware product that introduces these into your app. The middleware vendor is aware of the problem and has a fix available. + +## Invalid ELF header/section headers (AOSP master) + +Android loader now checks for invalid values in ELF header and section headers and fails +if they are invalid. + +*Example error* +dlopen failed: "/data/data/com.example.bad/lib.so" has unsupported e_shentsize: 0x0 (expected 0x28) + +*Resolution* +Do not use tools that produce invalid/malformed elf-files. Note that using them puts application +under high risk of being incompatible with future versions of Android. + diff --git a/libc/bionic/semaphore.cpp b/libc/bionic/semaphore.cpp index 19816470f..610a1b2bb 100644 --- a/libc/bionic/semaphore.cpp +++ b/libc/bionic/semaphore.cpp @@ -222,7 +222,7 @@ int sem_wait(sem_t* sem) { } int result = __futex_wait_ex(sem_count_ptr, shared, shared | SEMCOUNT_MINUS_ONE, false, nullptr); - if (bionic_get_application_target_sdk_version() > 23) { + if (bionic_get_application_target_sdk_version() >= __ANDROID_API_N__) { if (result ==-EINTR) { errno = EINTR; return -1; diff --git a/libc/include/android/api-level.h b/libc/include/android/api-level.h index 6dd4c18aa..c83c18d7f 100644 --- a/libc/include/android/api-level.h +++ b/libc/include/android/api-level.h @@ -43,4 +43,17 @@ #define __ANDROID_API__ __ANDROID_API_FUTURE__ #endif +#define __ANDROID_API_G__ 9 +#define __ANDROID_API_I__ 14 +#define __ANDROID_API_J__ 16 +#define __ANDROID_API_J_MR1__ 17 +#define __ANDROID_API_J_MR2__ 18 +#define __ANDROID_API_K__ 19 +#define __ANDROID_API_L__ 21 +#define __ANDROID_API_L_MR1__ 22 +#define __ANDROID_API_M__ 23 +#define __ANDROID_API_N__ 24 +#define __ANDROID_API_N_MR1__ 25 +#define __ANDROID_API_O__ 26 + #endif /* ANDROID_API_LEVEL_H */ diff --git a/libc/include/android/legacy_errno_inlines.h b/libc/include/android/legacy_errno_inlines.h index 93cba1fab..8f08074f1 100644 --- a/libc/include/android/legacy_errno_inlines.h +++ b/libc/include/android/legacy_errno_inlines.h @@ -32,7 +32,7 @@ #include <errno.h> #include <sys/cdefs.h> -#if __ANDROID_API__ < 21 +#if __ANDROID_API__ < __ANDROID_API_L__ __BEGIN_DECLS diff --git a/libc/include/android/legacy_fenv_inlines_arm.h b/libc/include/android/legacy_fenv_inlines_arm.h index a5bb26b19..58c49c2cf 100644 --- a/libc/include/android/legacy_fenv_inlines_arm.h +++ b/libc/include/android/legacy_fenv_inlines_arm.h @@ -31,7 +31,7 @@ #include <fenv.h> -#if __ANDROID_API__ < 21 && defined(__arm__) +#if __ANDROID_API__ < __ANDROID_API_L__ && defined(__arm__) __BEGIN_DECLS @@ -149,6 +149,6 @@ static __inline int fegetexcept(void) { __END_DECLS -#endif /* __ANDROID_API__ < 21 && defined(__arm__) */ +#endif /* __ANDROID_API__ < __ANDROID_API_L__ && defined(__arm__) */ #endif /* ANDROID_LEGACY_FENV_INLINES_ARM_H */ diff --git a/libc/include/android/legacy_fenv_inlines_mips.h b/libc/include/android/legacy_fenv_inlines_mips.h index ead697cc1..10b93c070 100644 --- a/libc/include/android/legacy_fenv_inlines_mips.h +++ b/libc/include/android/legacy_fenv_inlines_mips.h @@ -31,7 +31,7 @@ #include <fenv.h> -#if __ANDROID_API__ < 21 && (defined(__mips__) && !defined(__LP64__)) +#if __ANDROID_API__ < __ANDROID_API_L__ && (defined(__mips__) && !defined(__LP64__)) __BEGIN_DECLS @@ -163,6 +163,6 @@ static __inline int fegetexcept(void) { __END_DECLS -#endif /* __ANDROID_API__ < 21 && (defined(__mips__) && !defined(__LP64__)) */ +#endif /* __ANDROID_API__ < __ANDROID_API_L__ && (defined(__mips__) && !defined(__LP64__)) */ #endif /* ANDROID_LEGACY_FENV_INLINES_MIPS_H */ diff --git a/libc/include/android/legacy_signal_inlines.h b/libc/include/android/legacy_signal_inlines.h index 8ba7894fa..afdaca840 100644 --- a/libc/include/android/legacy_signal_inlines.h +++ b/libc/include/android/legacy_signal_inlines.h @@ -39,7 +39,7 @@ __BEGIN_DECLS sighandler_t bsd_signal(int signum, sighandler_t handler) __REMOVED_IN(21); -#if __ANDROID_API__ < 21 +#if __ANDROID_API__ < __ANDROID_API_L__ static __inline int sigismember(const sigset_t *set, int signum) { /* Signal numbers start at 1, but bit positions start at 0. */ @@ -98,7 +98,7 @@ static __inline sighandler_t signal(int s, sighandler_t f) { return bsd_signal(s, f); } -#endif /* __ANDROID_API__ < 21 */ +#endif /* __ANDROID_API__ < __ANDROID_API_L__ */ __END_DECLS diff --git a/libc/include/android/legacy_stdlib_inlines.h b/libc/include/android/legacy_stdlib_inlines.h index 93554e596..e211de5ae 100644 --- a/libc/include/android/legacy_stdlib_inlines.h +++ b/libc/include/android/legacy_stdlib_inlines.h @@ -32,7 +32,7 @@ #include <stdlib.h> #include <sys/cdefs.h> -#if __ANDROID_API__ < 21 +#if __ANDROID_API__ < __ANDROID_API_L__ __BEGIN_DECLS diff --git a/libc/include/android/legacy_sys_stat_inlines.h b/libc/include/android/legacy_sys_stat_inlines.h index c08edfab9..23a9f0738 100644 --- a/libc/include/android/legacy_sys_stat_inlines.h +++ b/libc/include/android/legacy_sys_stat_inlines.h @@ -32,7 +32,7 @@ #include <sys/cdefs.h> #include <sys/stat.h> -#if __ANDROID_API__ < 21 +#if __ANDROID_API__ < __ANDROID_API_L__ __BEGIN_DECLS diff --git a/libc/include/android/legacy_sys_wait_inlines.h b/libc/include/android/legacy_sys_wait_inlines.h index 63343ebaf..1124f8e29 100644 --- a/libc/include/android/legacy_sys_wait_inlines.h +++ b/libc/include/android/legacy_sys_wait_inlines.h @@ -34,7 +34,7 @@ #include <sys/wait.h> #include <unistd.h> -#if __ANDROID_API__ < 18 +#if __ANDROID_API__ < __ANDROID_API_J_MR2__ __BEGIN_DECLS @@ -44,6 +44,6 @@ static __inline pid_t wait4(pid_t pid, int* status, int options, struct rusage* __END_DECLS -#endif /* __ANDROID_API__ < 18 */ +#endif /* __ANDROID_API__ < __ANDROID_API_J_MR2__ */ #endif /* _ANDROID_LEGACY_SYS_WAIT_INLINES_H_ */ diff --git a/libc/include/android/legacy_termios_inlines.h b/libc/include/android/legacy_termios_inlines.h index 92cb22d63..4424bdb0b 100644 --- a/libc/include/android/legacy_termios_inlines.h +++ b/libc/include/android/legacy_termios_inlines.h @@ -35,7 +35,7 @@ #include <linux/termios.h> -#if __ANDROID_API__ < 21 +#if __ANDROID_API__ < __ANDROID_API_L__ __BEGIN_DECLS diff --git a/libc/include/ctype.h b/libc/include/ctype.h index f59b399b2..84dd5aa24 100644 --- a/libc/include/ctype.h +++ b/libc/include/ctype.h @@ -76,7 +76,7 @@ int isxdigit(int); int tolower(int); int toupper(int); -#if __ANDROID_API__ >= 21 +#if __ANDROID_API__ >= __ANDROID_API_L__ int isalnum_l(int, locale_t) __INTRODUCED_IN(21); int isalpha_l(int, locale_t) __INTRODUCED_IN(21); int isblank_l(int, locale_t) __INTRODUCED_IN(21); diff --git a/libc/include/fenv.h b/libc/include/fenv.h index 241e84594..a4c37e62f 100644 --- a/libc/include/fenv.h +++ b/libc/include/fenv.h @@ -36,7 +36,7 @@ __BEGIN_DECLS // fenv was always available on x86. -#if __ANDROID_API__ >= 21 || defined(__i386__) +#if __ANDROID_API__ >= __ANDROID_API_L__ || defined(__i386__) int feclearexcept(int) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_MIPS(21) __INTRODUCED_IN_X86(9); int fegetexceptflag(fexcept_t*, int) __INTRODUCED_IN_ARM(21) __INTRODUCED_IN_MIPS(21) __INTRODUCED_IN_X86(9); diff --git a/libc/include/netinet/in.h b/libc/include/netinet/in.h index 3574976b0..10fbafa99 100644 --- a/libc/include/netinet/in.h +++ b/libc/include/netinet/in.h @@ -47,13 +47,13 @@ typedef uint32_t in_addr_t; int bindresvport(int, struct sockaddr_in*); -#if __ANDROID_API__ >= 24 +#if __ANDROID_API__ >= __ANDROID_API_N__ extern const struct in6_addr in6addr_any __INTRODUCED_IN(24); extern const struct in6_addr in6addr_loopback __INTRODUCED_IN(24); #else static const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT; static const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT; -#endif /* __ANDROID_API__ >= 24 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ __END_DECLS diff --git a/libc/include/poll.h b/libc/include/poll.h index 0fa55d23e..c4e62f98d 100644 --- a/libc/include/poll.h +++ b/libc/include/poll.h @@ -53,7 +53,7 @@ __errordecl(__ppoll_too_small_error, "ppoll: pollfd array smaller than fd count" #if defined(__BIONIC_FORTIFY) -#if __ANDROID_API__ >= 23 +#if __ANDROID_API__ >= __ANDROID_API_M__ __BIONIC_FORTIFY_INLINE int poll(struct pollfd* fds, nfds_t fd_count, int timeout) { #if defined(__clang__) @@ -85,7 +85,7 @@ int ppoll(struct pollfd* fds, nfds_t fd_count, const struct timespec* timeout, c return __ppoll_real(fds, fd_count, timeout, mask); #endif } -#endif /* __ANDROID_API__ >= 23 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_M__ */ #endif diff --git a/libc/include/signal.h b/libc/include/signal.h index 17bc57d9e..7ae50de3e 100644 --- a/libc/include/signal.h +++ b/libc/include/signal.h @@ -118,7 +118,7 @@ int sigaction(int, const struct sigaction*, struct sigaction*); int siginterrupt(int, int); -#if __ANDROID_API__ >= 21 +#if __ANDROID_API__ >= __ANDROID_API_L__ sighandler_t signal(int, sighandler_t) __INTRODUCED_IN(21); int sigaddset(sigset_t*, int) __INTRODUCED_IN(21); int sigdelset(sigset_t*, int) __INTRODUCED_IN(21); diff --git a/libc/include/stdio.h b/libc/include/stdio.h index 816bd282a..9125e4c32 100644 --- a/libc/include/stdio.h +++ b/libc/include/stdio.h @@ -49,7 +49,7 @@ #include <bits/seek_constants.h> -#if __ANDROID_API__ <= 23 +#if __ANDROID_API__ < __ANDROID_API_N__ #include <bits/struct_file.h> #endif @@ -66,7 +66,7 @@ typedef off64_t fpos64_t; struct __sFILE; typedef struct __sFILE FILE; -#if __ANDROID_API__ >= 23 +#if __ANDROID_API__ >= __ANDROID_API_M__ extern FILE* stdin __INTRODUCED_IN(23); extern FILE* stdout __INTRODUCED_IN(23); extern FILE* stderr __INTRODUCED_IN(23); @@ -268,7 +268,7 @@ __errordecl(__fwrite_overflow, "fwrite called with overflowing size * count"); #if defined(__BIONIC_FORTIFY) && !defined(__BIONIC_NO_STDIO_FORTIFY) -#if __ANDROID_API__ >= 17 +#if __ANDROID_API__ >= __ANDROID_API_J_MR1__ __BIONIC_FORTIFY_INLINE __printflike(3, 0) int vsnprintf(char* dest, size_t size, const char* _Nonnull format, __va_list ap) { return __builtin___vsnprintf_chk(dest, size, 0, __bos(dest), format, ap); @@ -302,9 +302,9 @@ __printflike(2, 3) int sprintf(char* dest, const char* _Nonnull format, ...) { return __builtin___sprintf_chk(dest, 0, __bos(dest), format, __builtin_va_arg_pack()); } #endif -#endif /* __ANDROID_API__ >= 17 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */ -#if __ANDROID_API__ >= 24 +#if __ANDROID_API__ >= __ANDROID_API_N__ __BIONIC_FORTIFY_INLINE size_t fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict stream) { size_t bos = __bos0(buf); @@ -356,7 +356,7 @@ size_t fwrite(const void * __restrict buf, size_t size, size_t count, FILE * __r return __fwrite_chk(buf, size, count, stream, bos); } -#endif /* __ANDROID_API__ >= 24 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ #if !defined(__clang__) diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h index c84460bd9..d0c08e14d 100644 --- a/libc/include/stdlib.h +++ b/libc/include/stdlib.h @@ -152,7 +152,7 @@ int wctomb(char*, wchar_t) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD; size_t wcstombs(char*, const wchar_t*, size_t); -#if __ANDROID_API__ >= 21 +#if __ANDROID_API__ >= __ANDROID_API_L__ size_t __ctype_get_mb_cur_max(void) __INTRODUCED_IN(21); #define MB_CUR_MAX __ctype_get_mb_cur_max() #else @@ -184,7 +184,7 @@ char* realpath(const char* path, char* resolved) { #endif /* defined(__BIONIC_FORTIFY) */ -#if __ANDROID_API__ >= 21 +#if __ANDROID_API__ >= __ANDROID_API_L__ float strtof(const char*, char**) __INTRODUCED_IN(21); double atof(const char*) __attribute_pure__ __INTRODUCED_IN(21); int abs(int) __attribute_const__ __INTRODUCED_IN(21); diff --git a/libc/include/string.h b/libc/include/string.h index b3b3ed031..3e52f4812 100644 --- a/libc/include/string.h +++ b/libc/include/string.h @@ -114,7 +114,7 @@ char* strsignal(int); int strcoll(const char* _Nonnull, const char* _Nonnull) __attribute_pure__; size_t strxfrm(char* __restrict, const char* _Nonnull __restrict, size_t); -#if __ANDROID_API__ >= 21 +#if __ANDROID_API__ >= __ANDROID_API_L__ int strcoll_l(const char* _Nonnull, const char* _Nonnull, locale_t) __attribute_pure__ __INTRODUCED_IN(21); size_t strxfrm_l(char* __restrict, const char* _Nonnull __restrict, size_t, locale_t) __INTRODUCED_IN(21); #else @@ -152,7 +152,7 @@ size_t __strlcat_chk(char* _Nonnull __restrict, const char* _Nonnull __restrict, #if defined(__BIONIC_FORTIFY) -#if __ANDROID_API__ >= 23 +#if __ANDROID_API__ >= __ANDROID_API_M__ __BIONIC_FORTIFY_INLINE void* memchr(const void* s, int c, size_t n) { size_t bos = __bos(s); @@ -194,9 +194,9 @@ void* memrchr(const void* s, int c, size_t n) { return __memrchr_chk(s, c, n, bos); } -#endif /* __ANDROID_API__ >= 23 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_M__ */ -#if __ANDROID_API__ >= 17 +#if __ANDROID_API__ >= __ANDROID_API_J_MR1__ __BIONIC_FORTIFY_INLINE void* memcpy(void* _Nonnull __restrict dst, const void* _Nonnull __restrict src, size_t copy_amount) { return __builtin___memcpy_chk(dst, src, copy_amount, __bos0(dst)); @@ -206,23 +206,23 @@ __BIONIC_FORTIFY_INLINE void* memmove(void* _Nonnull dst, const void* _Nonnull src, size_t len) { return __builtin___memmove_chk(dst, src, len, __bos0(dst)); } -#endif /* __ANDROID_API__ >= 17 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */ -#if __ANDROID_API__ >= 21 +#if __ANDROID_API__ >= __ANDROID_API_L__ __BIONIC_FORTIFY_INLINE char* stpcpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src) { return __builtin___stpcpy_chk(dst, src, __bos(dst)); } -#endif /* __ANDROID_API__ >= 21 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_L__ */ -#if __ANDROID_API__ >= 17 +#if __ANDROID_API__ >= __ANDROID_API_J_MR1__ __BIONIC_FORTIFY_INLINE char* strcpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src) { return __builtin___strcpy_chk(dst, src, __bos(dst)); } -#endif /* __ANDROID_API__ >= 17 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */ -#if __ANDROID_API__ >= 21 +#if __ANDROID_API__ >= __ANDROID_API_L__ __BIONIC_FORTIFY_INLINE char* stpncpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src, size_t n) { size_t bos_dst = __bos(dst); @@ -264,9 +264,9 @@ char* strncpy(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src return __strncpy_chk2(dst, src, n, bos_dst, bos_src); } -#endif /* __ANDROID_API__ >= 21 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_L__ */ -#if __ANDROID_API__ >= 17 +#if __ANDROID_API__ >= __ANDROID_API_J_MR1__ __BIONIC_FORTIFY_INLINE char* strcat(char* _Nonnull __restrict dst, const char* _Nonnull __restrict src) { return __builtin___strcat_chk(dst, src, __bos(dst)); @@ -341,9 +341,9 @@ size_t strlen(const char* _Nonnull s) { return __strlen_chk(s, bos); } -#endif /* __ANDROID_API__ >= 17 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_J_MR1__ */ -#if __ANDROID_API__ >= 18 +#if __ANDROID_API__ >= __ANDROID_API_J_MR2__ __BIONIC_FORTIFY_INLINE char* strchr(const char* _Nonnull s, int c) { size_t bos = __bos(s); @@ -381,7 +381,7 @@ char* strrchr(const char* _Nonnull s, int c) { return __strrchr_chk(s, c, bos); } -#endif /* __ANDROID_API__ >= 18 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_J_MR2__ */ #endif /* defined(__BIONIC_FORTIFY) */ diff --git a/libc/include/sys/select.h b/libc/include/sys/select.h index df118e33f..40bd32e17 100644 --- a/libc/include/sys/select.h +++ b/libc/include/sys/select.h @@ -62,7 +62,7 @@ void __FD_CLR_chk(int, fd_set*, size_t) __INTRODUCED_IN(21); void __FD_SET_chk(int, fd_set*, size_t) __INTRODUCED_IN(21); int __FD_ISSET_chk(int, fd_set*, size_t) __INTRODUCED_IN(21); -#if defined(__BIONIC_FORTIFY) && __ANDROID_API__ >= 21 +#if defined(__BIONIC_FORTIFY) && __ANDROID_API__ >= __ANDROID_API_L__ #define FD_CLR(fd, set) __FD_CLR_chk(fd, set, __bos(set)) #define FD_SET(fd, set) __FD_SET_chk(fd, set, __bos(set)) #define FD_ISSET(fd, set) __FD_ISSET_chk(fd, set, __bos(set)) diff --git a/libc/include/sys/socket.h b/libc/include/sys/socket.h index 03dc849f2..8e05cf192 100644 --- a/libc/include/sys/socket.h +++ b/libc/include/sys/socket.h @@ -114,7 +114,7 @@ struct cmsghdr { ? (struct cmsghdr*) (msg)->msg_control : (struct cmsghdr*) NULL) #define CMSG_OK(mhdr, cmsg) ((cmsg)->cmsg_len >= sizeof(struct cmsghdr) && (cmsg)->cmsg_len <= (unsigned long) ((mhdr)->msg_controllen - ((char*)(cmsg) - (char*)(mhdr)->msg_control))) -#if __ANDROID_API__ >= 21 +#if __ANDROID_API__ >= __ANDROID_API_L__ struct cmsghdr* __cmsg_nxthdr(struct msghdr*, struct cmsghdr*) __INTRODUCED_IN(21); #else /* TODO(danalbert): Move this into libandroid_support. */ @@ -129,7 +129,7 @@ static inline struct cmsghdr* __cmsg_nxthdr(struct msghdr* msg, struct cmsghdr* } return ptr; } -#endif /* __ANDROID_API__ >= 21 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_L__ */ #define SCM_RIGHTS 0x01 #define SCM_CREDENTIALS 0x02 @@ -315,7 +315,7 @@ ssize_t __recvfrom_real(int, void*, size_t, int, struct sockaddr*, socklen_t*) _ #if defined(__BIONIC_FORTIFY) -#if __ANDROID_API__ >= 24 +#if __ANDROID_API__ >= __ANDROID_API_N__ __BIONIC_FORTIFY_INLINE ssize_t recvfrom(int fd, void* buf, size_t len, int flags, struct sockaddr* src_addr, socklen_t* addr_len) { size_t bos = __bos0(buf); @@ -336,7 +336,7 @@ ssize_t recvfrom(int fd, void* buf, size_t len, int flags, struct sockaddr* src_ return __recvfrom_chk(fd, buf, len, bos, flags, src_addr, addr_len); } -#endif /* __ANDROID_API__ >= 24 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ __BIONIC_FORTIFY_INLINE ssize_t recv(int socket, void* buf, size_t len, int flags) { diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h index cc9dd9196..f961cf82e 100644 --- a/libc/include/sys/stat.h +++ b/libc/include/sys/stat.h @@ -169,7 +169,7 @@ __errordecl(__umask_invalid_mode, "umask called with invalid mode"); #if defined(__BIONIC_FORTIFY) -#if __ANDROID_API__ >= 18 +#if __ANDROID_API__ >= __ANDROID_API_J_MR2__ __BIONIC_FORTIFY_INLINE mode_t umask(mode_t mode) { #if !defined(__clang__) @@ -182,11 +182,11 @@ mode_t umask(mode_t mode) { #endif return __umask_chk(mode); } -#endif /* __ANDROID_API__ >= 18 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_J_MR2__ */ #endif /* defined(__BIONIC_FORTIFY) */ -#if __ANDROID_API__ >= 21 +#if __ANDROID_API__ >= __ANDROID_API_L__ int mkfifo(const char*, mode_t) __INTRODUCED_IN(21); #else // Implemented as a static inline before 21. diff --git a/libc/include/sys/wait.h b/libc/include/sys/wait.h index f3972fca5..0247b2bce 100644 --- a/libc/include/sys/wait.h +++ b/libc/include/sys/wait.h @@ -51,7 +51,7 @@ __BEGIN_DECLS pid_t wait(int*); pid_t waitpid(pid_t, int*, int); -#if __ANDROID_API__ >= 18 +#if __ANDROID_API__ >= __ANDROID_API_J_MR2__ pid_t wait4(pid_t, int*, int, struct rusage*) __INTRODUCED_IN(18); #else // Implemented as a static inline before 18. diff --git a/libc/include/termios.h b/libc/include/termios.h index c17794cdb..49ffcd2e4 100644 --- a/libc/include/termios.h +++ b/libc/include/termios.h @@ -35,7 +35,7 @@ __BEGIN_DECLS -#if __ANDROID_API__ >= 21 +#if __ANDROID_API__ >= __ANDROID_API_L__ // Implemented as static inlines before 21. speed_t cfgetispeed(const struct termios*) __INTRODUCED_IN(21); speed_t cfgetospeed(const struct termios*) __INTRODUCED_IN(21); diff --git a/libc/include/time.h b/libc/include/time.h index 37246b473..9fde77ee8 100644 --- a/libc/include/time.h +++ b/libc/include/time.h @@ -77,7 +77,7 @@ struct tm* gmtime_r(const time_t*, struct tm*); char* strptime(const char*, const char*, struct tm*); size_t strftime(char*, size_t, const char*, const struct tm*); -#if __ANDROID_API__ >= 21 +#if __ANDROID_API__ >= __ANDROID_API_L__ size_t strftime_l(char*, size_t, const char*, const struct tm*, locale_t) __INTRODUCED_IN(21); #else // Implemented as static inline before 21. diff --git a/libc/include/unistd.h b/libc/include/unistd.h index 130ede625..1e239cd7a 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -169,7 +169,7 @@ off_t lseek(int __fd, off_t __offset, int __whence); off64_t lseek64(int __fd, off64_t __offset, int __whence); -#if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ >= 21 +#if defined(__USE_FILE_OFFSET64) && __ANDROID_API__ >= __ANDROID_API_L__ int truncate(const char* __path, off_t __length) __RENAME(truncate64) __INTRODUCED_IN(21); ssize_t pread(int __fd, void* __buf, size_t __count, off_t __offset) __RENAME(pread64) __INTRODUCED_IN(12); @@ -206,7 +206,7 @@ int ttyname_r(int __fd, char* __buf, size_t __buflen) __INTRODUCED_IN(8); int acct(const char* __filepath); -#if __ANDROID_API__ >= 21 +#if __ANDROID_API__ >= __ANDROID_API_L__ int getpagesize(void) __INTRODUCED_IN(21); #else static __inline__ int getpagesize(void) { @@ -284,7 +284,7 @@ int setdomainname(const char*, size_t) __INTRODUCED_IN_FUTURE; #if defined(__BIONIC_FORTIFY) -#if __ANDROID_API__ >= 24 +#if __ANDROID_API__ >= __ANDROID_API_N__ __BIONIC_FORTIFY_INLINE char* getcwd(char* buf, size_t size) { size_t bos = __bos(buf); @@ -315,7 +315,7 @@ char* getcwd(char* buf, size_t size) { return __getcwd_chk(buf, size, bos); } -#endif /* __ANDROID_API__ >= 24 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ #if defined(__USE_FILE_OFFSET64) #define __PREAD_PREFIX(x) __pread64_ ## x @@ -323,7 +323,7 @@ char* getcwd(char* buf, size_t size) { #define __PREAD_PREFIX(x) __pread_ ## x #endif -#if __ANDROID_API__ >= 23 +#if __ANDROID_API__ >= __ANDROID_API_M__ __BIONIC_FORTIFY_INLINE ssize_t pread(int fd, void* buf, size_t count, off_t offset) { size_t bos = __bos0(buf); @@ -373,7 +373,7 @@ ssize_t pread64(int fd, void* buf, size_t count, off64_t offset) { return __pread64_chk(fd, buf, count, offset, bos); } -#endif /* __ANDROID_API__ >= 23 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_M__ */ #if defined(__USE_FILE_OFFSET64) #define __PWRITE_PREFIX(x) __pwrite64_ ## x @@ -381,7 +381,7 @@ ssize_t pread64(int fd, void* buf, size_t count, off64_t offset) { #define __PWRITE_PREFIX(x) __pwrite_ ## x #endif -#if __ANDROID_API__ >= 24 +#if __ANDROID_API__ >= __ANDROID_API_N__ __BIONIC_FORTIFY_INLINE ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) { size_t bos = __bos0(buf); @@ -431,9 +431,9 @@ ssize_t pwrite64(int fd, const void* buf, size_t count, off64_t offset) { return __pwrite64_chk(fd, buf, count, offset, bos); } -#endif /* __ANDROID_API__ >= 24 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ -#if __ANDROID_API__ >= 21 +#if __ANDROID_API__ >= __ANDROID_API_L__ __BIONIC_FORTIFY_INLINE ssize_t read(int fd, void* buf, size_t count) { size_t bos = __bos0(buf); @@ -458,9 +458,9 @@ ssize_t read(int fd, void* buf, size_t count) { return __read_chk(fd, buf, count, bos); } -#endif /* __ANDROID_API__ >= 21 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_L__ */ -#if __ANDROID_API__ >= 24 +#if __ANDROID_API__ >= __ANDROID_API_N__ __BIONIC_FORTIFY_INLINE ssize_t write(int fd, const void* buf, size_t count) { size_t bos = __bos0(buf); @@ -487,9 +487,9 @@ ssize_t write(int fd, const void* buf, size_t count) { return __write_chk(fd, buf, count, bos); } -#endif /* __ANDROID_API__ >= 24 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ -#if __ANDROID_API__ >= 23 +#if __ANDROID_API__ >= __ANDROID_API_M__ __BIONIC_FORTIFY_INLINE ssize_t readlink(const char* path, char* buf, size_t size) { size_t bos = __bos(buf); @@ -539,7 +539,7 @@ ssize_t readlinkat(int dirfd, const char* path, char* buf, size_t size) { return __readlinkat_chk(dirfd, path, buf, size, bos); } -#endif /* __ANDROID_API__ >= 23 */ +#endif /* __ANDROID_API__ >= __ANDROID_API_M__ */ #endif /* defined(__BIONIC_FORTIFY) */ diff --git a/libc/include/wchar.h b/libc/include/wchar.h index 2ee6c6918..d3e9f5c75 100644 --- a/libc/include/wchar.h +++ b/libc/include/wchar.h @@ -132,7 +132,7 @@ wchar_t *wmemset(wchar_t *, wchar_t, size_t); int wprintf(const wchar_t *, ...); int wscanf(const wchar_t *, ...); -#if __ANDROID_API__ >= 21 +#if __ANDROID_API__ >= __ANDROID_API_L__ long long wcstoll_l(const wchar_t*, wchar_t**, int, locale_t) __INTRODUCED_IN(21); unsigned long long wcstoull_l(const wchar_t*, wchar_t**, int, locale_t) __INTRODUCED_IN(21); long double wcstold_l(const wchar_t*, wchar_t**, locale_t) __INTRODUCED_IN(21); diff --git a/libc/include/wctype.h b/libc/include/wctype.h index 0613e7ed3..a0ed09af3 100644 --- a/libc/include/wctype.h +++ b/libc/include/wctype.h @@ -35,7 +35,7 @@ __BEGIN_DECLS -#if __ANDROID_API__ >= 21 +#if __ANDROID_API__ >= __ANDROID_API_L__ int iswalnum_l(wint_t, locale_t) __INTRODUCED_IN(21); int iswalpha_l(wint_t, locale_t) __INTRODUCED_IN(21); int iswblank_l(wint_t, locale_t) __INTRODUCED_IN(21); diff --git a/linker/linker.cpp b/linker/linker.cpp index f8531b69b..266ca6e81 100644 --- a/linker/linker.cpp +++ b/linker/linker.cpp @@ -44,8 +44,6 @@ #include <vector> // Private C library headers. -#include "private/KernelArgumentBlock.h" -#include "private/ScopedPthreadMutexLocker.h" #include "private/ScopeGuard.h" #include "linker.h" @@ -66,11 +64,6 @@ #include "android-base/stringprintf.h" #include "ziparchive/zip_archive.h" -extern void __libc_init_globals(KernelArgumentBlock&); -extern void __libc_init_AT_SECURE(KernelArgumentBlock&); - -extern "C" void _start(); - // Override macros to use C++ style casts. #undef ELF_ST_TYPE #define ELF_ST_TYPE(x) (static_cast<uint32_t>(x) & 0xf) @@ -154,8 +147,8 @@ static bool is_greylisted(const char* name, const soinfo* needed_by) { nullptr }; - // limit greylisting to apps targeting sdk version 23 and below - if (get_application_target_sdk_version() > 23) { + // If you're targeting N, you don't get the greylist. + if (get_application_target_sdk_version() >= __ANDROID_API_N__) { return false; } @@ -776,9 +769,10 @@ static const ElfW(Sym)* dlsym_linear_lookup(android_namespace_t* ns, for (auto it = start, end = soinfo_list.end(); it != end; ++it) { soinfo* si = *it; // Do not skip RTLD_LOCAL libraries in dlsym(RTLD_DEFAULT, ...) - // if the library is opened by application with target api level <= 22 + // if the library is opened by application with target api level < M. // See http://b/21565766 - if ((si->get_rtld_flags() & RTLD_GLOBAL) == 0 && si->get_target_sdk_version() > 22) { + if ((si->get_rtld_flags() & RTLD_GLOBAL) == 0 && + si->get_target_sdk_version() >= __ANDROID_API_M__) { continue; } @@ -1031,7 +1025,7 @@ static int open_library(android_namespace_t* ns, const char* fix_dt_needed(const char* dt_needed, const char* sopath __unused) { #if !defined(__LP64__) // Work around incorrect DT_NEEDED entries for old apps: http://b/21364029 - if (get_application_target_sdk_version() <= 22) { + if (get_application_target_sdk_version() < __ANDROID_API_M__) { const char* bname = basename(dt_needed); if (bname != dt_needed) { DL_WARN("library \"%s\" has invalid DT_NEEDED entry \"%s\"", sopath, dt_needed); @@ -3031,12 +3025,12 @@ bool soinfo::prelink_image() { // In the case when dt_soname is absent some apps stop working // because they can't find dt_needed library by soname. // This workaround should keep them working. (applies only - // for apps targeting sdk version <=22). Make an exception for + // for apps targeting sdk version < M). Make an exception for // the main executable and linker; they do not need to have dt_soname if (soname_ == nullptr && this != solist_get_somain() && (flags_ & FLAG_LINKER) == 0 && - get_application_target_sdk_version() <= 22) { + get_application_target_sdk_version() < __ANDROID_API_M__) { soname_ = basename(realpath_.c_str()); DL_WARN("%s: is missing DT_SONAME will use basename as a replacement: \"%s\"", get_realpath(), soname_); @@ -3065,8 +3059,8 @@ bool soinfo::link_image(const soinfo_list_t& global_group, const soinfo_list_t& #if !defined(__LP64__) if (has_text_relocations) { - // Fail if app is targeting sdk version > 22 - if (get_application_target_sdk_version() > 22) { + // Fail if app is targeting M or above. + if (get_application_target_sdk_version() >= __ANDROID_API_M__) { DL_ERR_AND_LOG("\"%s\" has text relocations", get_realpath()); return false; } @@ -3226,4 +3220,3 @@ void init_default_namespace() { g_default_namespace.set_default_library_paths(std::move(ld_default_paths)); }; - diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp index 5b0ee491a..973fcf5a2 100644 --- a/linker/linker_phdr.cpp +++ b/linker/linker_phdr.cpp @@ -248,14 +248,26 @@ bool ElfReader::VerifyElfHeader() { } if (header_.e_shentsize != sizeof(ElfW(Shdr))) { - DL_ERR("\"%s\" has unsupported e_shentsize: 0x%x (expected 0x%zx)", - name_.c_str(), header_.e_shentsize, sizeof(ElfW(Shdr))); - return false; + // Fail if app is targeting Android O or above + if (get_application_target_sdk_version() >= __ANDROID_API_O__) { + DL_ERR_AND_LOG("\"%s\" has unsupported e_shentsize: 0x%x (expected 0x%zx)", + name_.c_str(), header_.e_shentsize, sizeof(ElfW(Shdr))); + return false; + } + DL_WARN("\"%s\" has unsupported e_shentsize: 0x%x (expected 0x%zx)", + name_.c_str(), header_.e_shentsize, sizeof(ElfW(Shdr))); + add_dlwarning(name_.c_str(), "has invalid ELF header"); } if (header_.e_shstrndx == 0) { - DL_ERR("\"%s\" has invalid e_shstrndx", name_.c_str()); - return false; + // Fail if app is targeting Android O or above + if (get_application_target_sdk_version() >= __ANDROID_API_O__) { + DL_ERR_AND_LOG("\"%s\" has invalid e_shstrndx", name_.c_str()); + return false; + } + + DL_WARN("\"%s\" has invalid e_shstrndx", name_.c_str()); + add_dlwarning(name_.c_str(), "has invalid ELF header"); } return true; @@ -608,7 +620,7 @@ bool ElfReader::LoadSegments() { int prot = PFLAGS_TO_PROT(phdr->p_flags); if ((prot & (PROT_EXEC | PROT_WRITE)) == (PROT_EXEC | PROT_WRITE)) { // W + E PT_LOAD segments are not allowed in O. - if (get_application_target_sdk_version() > 25) { + if (get_application_target_sdk_version() >= __ANDROID_API_O__) { DL_ERR_AND_LOG("\"%s\": W + E load segments are not allowed", name_.c_str()); return false; } diff --git a/linker/linker_soinfo.cpp b/linker/linker_soinfo.cpp index 59bdc4dfe..16e42c2bc 100644 --- a/linker/linker_soinfo.cpp +++ b/linker/linker_soinfo.cpp @@ -726,7 +726,7 @@ uintptr_t soinfo::get_handle() const { } void* soinfo::to_handle() { - if (get_application_target_sdk_version() <= 23 || !has_min_version(3)) { + if (get_application_target_sdk_version() < __ANDROID_API_N__ || !has_min_version(3)) { return this; } @@ -791,5 +791,3 @@ uint32_t SymbolName::gnu_hash() { return gnu_hash_; } - - diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp index 8527b0024..ed50ea5a7 100644 --- a/tests/dlext_test.cpp +++ b/tests/dlext_test.cpp @@ -1191,10 +1191,9 @@ TEST(dlext, dlopen_handle_value_platform) { } TEST(dlext, dlopen_handle_value_app_compat) { - android_set_application_target_sdk_version(23); + android_set_application_target_sdk_version(__ANDROID_API_M__); void* handle = dlopen("libtest_dlsym_from_this.so", RTLD_NOW | RTLD_LOCAL); ASSERT_TRUE(reinterpret_cast<uintptr_t>(handle) % sizeof(uintptr_t) == 0) << "dlopen should return valid pointer"; dlclose(handle); } - diff --git a/tests/prebuilt-elf-files/arm/libtest_empty.so b/tests/prebuilt-elf-files/arm/libtest_empty.so Binary files differnew file mode 100755 index 000000000..cfcf57440 --- /dev/null +++ b/tests/prebuilt-elf-files/arm/libtest_empty.so diff --git a/tests/prebuilt-elf-files/arm64/libtest_empty.so b/tests/prebuilt-elf-files/arm64/libtest_empty.so Binary files differnew file mode 100755 index 000000000..39580abb8 --- /dev/null +++ b/tests/prebuilt-elf-files/arm64/libtest_empty.so diff --git a/tests/prebuilt-elf-files/mips/libtest_empty.so b/tests/prebuilt-elf-files/mips/libtest_empty.so Binary files differnew file mode 100755 index 000000000..57a8f8c7a --- /dev/null +++ b/tests/prebuilt-elf-files/mips/libtest_empty.so diff --git a/tests/prebuilt-elf-files/mips64/libtest_empty.so b/tests/prebuilt-elf-files/mips64/libtest_empty.so Binary files differnew file mode 100755 index 000000000..d0bec3ad3 --- /dev/null +++ b/tests/prebuilt-elf-files/mips64/libtest_empty.so diff --git a/tests/prebuilt-elf-files/x86/libtest_empty.so b/tests/prebuilt-elf-files/x86/libtest_empty.so Binary files differnew file mode 100755 index 000000000..a731550ff --- /dev/null +++ b/tests/prebuilt-elf-files/x86/libtest_empty.so diff --git a/tests/prebuilt-elf-files/x86_64/libtest_empty.so b/tests/prebuilt-elf-files/x86_64/libtest_empty.so Binary files differnew file mode 100755 index 000000000..df26a069e --- /dev/null +++ b/tests/prebuilt-elf-files/x86_64/libtest_empty.so diff --git a/tests/semaphore_test.cpp b/tests/semaphore_test.cpp index 7dc72259a..24a2dbe5b 100644 --- a/tests/semaphore_test.cpp +++ b/tests/semaphore_test.cpp @@ -188,7 +188,7 @@ static void* SemWaitEINTRThreadFn(void* arg) { TEST(semaphore, sem_wait_no_EINTR_in_sdk_less_equal_than_23) { #if defined(__BIONIC__) - android_set_application_target_sdk_version(23U); + android_set_application_target_sdk_version(__ANDROID_API_M__); sem_t s; ASSERT_EQ(0, sem_init(&s, 0, 0)); ScopedSignalHandler handler(SIGUSR1, sem_wait_test_signal_handler); |