| Elliott Hughes | a348174 | 2017-11-28 14:47:17 -0800 | [diff] [blame^] | 1 | # 32-bit ABI bugs |
| Elliott Hughes | 0bfcbaf | 2017-08-28 09:18:34 -0700 | [diff] [blame] | 2 | |
| Elliott Hughes | a348174 | 2017-11-28 14:47:17 -0800 | [diff] [blame^] | 3 | ## 32-bit `off_t` and `_FILE_OFFSET_BITS=64` |
| Elliott Hughes | 0bfcbaf | 2017-08-28 09:18:34 -0700 | [diff] [blame] | 4 | |
| 5 | On 32-bit Android, `off_t` is a signed 32-bit integer. This limits functions |
| 6 | that use `off_t` to working on files no larger than 2GiB. |
| 7 | |
| 8 | Android does not require the `_LARGEFILE_SOURCE` macro to be used to make |
| 9 | `fseeko` and `ftello` available. Instead they're always available from API |
| 10 | level 24 where they were introduced, and never available before then. |
| 11 | |
| 12 | Android also does not require the `_LARGEFILE64_SOURCE` macro to be used |
| 13 | to make `off64_t` and corresponding functions such as `ftruncate64` available. |
| 14 | Instead, whatever subset of those functions was available at your target API |
| 15 | level will be visible. |
| 16 | |
| 17 | There are a couple of exceptions to note. Firstly, `off64_t` and the single |
| 18 | function `lseek64` were available right from the beginning in API 3. Secondly, |
| 19 | Android has always silently inserted `O_LARGEFILE` into any open call, so if |
| 20 | all you need are functions like `read` that don't take/return `off_t`, large |
| 21 | files have always worked. |
| 22 | |
| 23 | Android support for `_FILE_OFFSET_BITS=64` (which turns `off_t` into `off64_t` |
| 24 | and replaces each `off_t` function with its `off64_t` counterpart, such as |
| 25 | `lseek` in the source becoming `lseek64` at runtime) was added late. Even when |
| 26 | it became available for the platform, it wasn't available from the NDK until |
| 27 | r15. Before NDK r15, `_FILE_OFFSET_BITS=64` silently did nothing: all code |
| 28 | compiled with that was actually using a 32-bit `off_t`. With a new enough NDK, |
| 29 | the situation becomes complicated. If you're targeting an API before 21, almost |
| 30 | all functions that take an `off_t` become unavailable. You've asked for their |
| 31 | 64-bit equivalents, and none of them (except `lseek`/`lseek64`) exist. As you |
| 32 | increase your target API level, you'll have more and more of the functions |
| 33 | available. API 12 adds some of the `<unistd.h>` functions, API 21 adds `mmap`, |
| 34 | and by API 24 you have everything including `<stdio.h>`. See the |
| Elliott Hughes | a348174 | 2017-11-28 14:47:17 -0800 | [diff] [blame^] | 35 | [linker map](libc/libc.map.txt) for full details. Note also that in NDK r16 and |
| 36 | later, we inline an mmap64 implementation in the headers when you target an API |
| 37 | before 21 because it's an easy special case that's often needed. This means |
| 38 | that code using `_FILE_OFFSET_BITS=64` and `mmap` will always compile. |
| 39 | |
| 40 | If your code stops compiling when you move to NDK r15 or later, removing any |
| 41 | definition of `_FILE_OFFSET_BITS=64` will restore the behavior you used to have: |
| 42 | you'll have a 32-bit `off_t` and use the 32-bit functions. |
| Elliott Hughes | 0bfcbaf | 2017-08-28 09:18:34 -0700 | [diff] [blame] | 43 | |
| 44 | In the 64-bit ABI, `off_t` is always 64-bit. |
| 45 | |
| 46 | |
| Elliott Hughes | a348174 | 2017-11-28 14:47:17 -0800 | [diff] [blame^] | 47 | ## `sigset_t` is too small for real-time signals |
| Elliott Hughes | 0bfcbaf | 2017-08-28 09:18:34 -0700 | [diff] [blame] | 48 | |
| 49 | On 32-bit Android, `sigset_t` is too small for ARM and x86 (but correct for |
| 50 | MIPS). This means that there is no support for real-time signals in 32-bit |
| 51 | code. |
| 52 | |
| 53 | In the 64-bit ABI, `sigset_t` is the correct size for every architecture. |
| 54 | |
| 55 | |
| Elliott Hughes | a348174 | 2017-11-28 14:47:17 -0800 | [diff] [blame^] | 56 | ## `time_t` is 32-bit |
| Elliott Hughes | 0bfcbaf | 2017-08-28 09:18:34 -0700 | [diff] [blame] | 57 | |
| 58 | On 32-bit Android, `time_t` is 32-bit. The header `<time64.h>` and type |
| 59 | `time64_t` exist as a workaround, but the kernel interfaces exposed on 32-bit |
| 60 | Android all use the 32-bit `time_t`. |
| 61 | |
| 62 | In the 64-bit ABI, `time_t` is 64-bit. |
| Elliott Hughes | 1d01fe8 | 2017-10-23 10:07:55 -0700 | [diff] [blame] | 63 | |
| Elliott Hughes | a348174 | 2017-11-28 14:47:17 -0800 | [diff] [blame^] | 64 | ## `pthread_mutex_t` is too small for large pids |
| Elliott Hughes | 1d01fe8 | 2017-10-23 10:07:55 -0700 | [diff] [blame] | 65 | |
| 66 | This doesn't generally affect Android devices, because on devices |
| 67 | `/proc/sys/kernel/pid_max` is usually too small to hit the 16-bit limit, |
| 68 | but 32-bit bionic's `pthread_mutex` is a total of 32 bits, leaving just |
| 69 | 16 bits for the owner thread id. This means bionic isn't able to support |
| 70 | mutexes for tids that don't fit in 16 bits. This typically manifests as |
| 71 | a hang in `pthread_mutex_lock` if the libc startup code doesn't detect |
| 72 | this condition and abort. |