platform_build_soong/cc/config
Kalesh Singh fa1ebf5943 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] 733198152d: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>
2024-03-12 17:04:50 -07:00
..
Android.bp Add riscv64-linux-android support 2022-10-03 08:43:13 -07:00
arm64_device.go soong: ldflags: Add separate-loadable-segments 2024-03-12 17:04:50 -07:00
arm64_linux_host.go Reapply "Use zstd to compress debug info in cc libraries" 2023-10-20 16:01:14 +00:00
arm_device.go Disable shrink-wrap optimization for arm32 devices 2024-01-26 21:55:19 +00:00
arm_linux_host.go Reapply "Use zstd to compress debug info in cc libraries" 2023-10-20 16:01:14 +00:00
bionic.go soong: Add crt_pad_segment to .so's 2024-01-31 19:42:31 -08:00
cfi_exports.map
clang.go Remove unused-but-set-{variable,parameter} from ClangUnknownCflags 2021-09-13 06:25:41 +00:00
darwin_host.go Remove macros that Darwin never used. 2024-02-07 18:30:22 +00:00
global.go Remove wtautological warnings added during toolchain update 2024-02-16 19:44:26 +00:00
integer_overflow_blocklist.txt Rename CFI blocklist files. 2020-07-27 18:37:48 +00:00
OWNERS Update OWNERS file for actual Android LLVM members. 2023-09-01 14:48:34 -07:00
riscv64_device.go Update unaligned-vector-mem to -munaligned-access 2024-02-28 06:14:57 +00:00
tidy.go Revert "Remove flags rejected by RBE input processor" 2023-11-21 19:54:27 +00:00
tidy_test.go Revert "Make lots of tests run in parallel" 2020-10-09 18:34:24 -07:00
toolchain.go soong: Add crt_pad_segment to .so's 2024-01-31 19:42:31 -08:00
vndk.go Revert "Add libdumpstateutil to vendor variant list" 2023-08-03 13:56:54 +00:00
x86_64_device.go soong: ldflags: Add separate-loadable-segments 2024-03-12 17:04:50 -07:00
x86_device.go Replace goldmont-without-xsaves build with goldmont-without-sha-xsaves 2024-01-24 16:27:56 +09:00
x86_linux_bionic_host.go Reapply "Use zstd to compress debug info in cc libraries" 2023-10-20 16:01:14 +00:00
x86_linux_host.go Remove macros that the Linux host no longer needs. 2024-02-09 16:43:34 +00:00
x86_windows_host.go Remove __STDC_FORMAT_MACROS. 2024-02-07 20:45:25 +00:00