soong: ldflags: Add separate-loadable-segments
To suport >4KB page sizes, the loader may extend LOAD segment mappings to be contiguous in the virtual address space. This is done in order to reduce the use of unreclaimable kernel slab memory for the otherwise necessary gap VMAs (when the runtime-page-size < ELF-segment-p_align). Such mappings may beyond the end of the backing file when extended; which breaks the common userspace assumption that file memory maps are entirely backed by the underlying file. Existing apps (not yet updated for larger page size support) may encounter breakages if they parse /proc/self/[s]maps and use the [start, end] addresses to operate on system libraries that have crt_pad_segment optimization (VMA extension) [1]. In order to avoid breaking exisiting apps, update the build system to ensure the platform ELFs' segments are entirely backed by the file even when the VMA is extended to be contiguous with the subsequent segment's. This is achieved using the linker flag -z separate-loadable-segments, which inserts enough padding (zeros) to also align each segment's offset on file by it's p_align (max-page-size). Although laying out the ELF segments on disk to respect the p_align causes an increase in the file's apparent size (i_size), on Android the actual disk usage increase is not significant due to most of the padding being zero blocks which don't get alloacted in the read-only partitions. The following results were obtained on an ARM64 device on a recent git_main build: No Separate Separate Delta Delta % Partition Loadable Loadable Segments Segments 4208.90MB 4214.6MB 5.70MB 0.14% All RO Partitions Note: The overhead of -z separate-loadable-segments is minimized by the fact that ARM64 android already builds with -z separate-code. [2] [1] https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/arch-common/bionic/crt_pad_segment.S [2] https://cs.android.com/android/platform/superproject/main/+/733198152db4efc0efbdc6407ed1cb6e4af6277c:build/soong/cc/config/arm64_device.go;l=53 Bug: 328797737 Test: Manually test previously crashing application Change-Id: Icb14ad10b5c9282855d54c7945b065b7b4184163 Signed-off-by:Kalesh Singh <kaleshsingh@google.com>
Loading
Please register or sign in to comment