Merge "bionic: Add crt_pad_segment" into main
diff --git a/libc/Android.bp b/libc/Android.bp
index fdf34eb..139fd0e 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -2319,6 +2319,17 @@
defaults: ["crt_defaults"],
}
+cc_object {
+ name: "crt_pad_segment",
+ local_include_dirs: [
+ "include",
+ "private", // crt_pad_segment.S depends on private/bionic_asm_note.h
+ ],
+ srcs: ["arch-common/bionic/crt_pad_segment.S"],
+
+ defaults: ["crt_defaults"],
+}
+
cc_library_static {
name: "note_memtag_heap_async",
arch: {
diff --git a/libc/arch-common/bionic/crt_pad_segment.S b/libc/arch-common/bionic/crt_pad_segment.S
new file mode 100644
index 0000000..86c730d
--- /dev/null
+++ b/libc/arch-common/bionic/crt_pad_segment.S
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <private/bionic_asm_note.h>
+
+ .section ".note.android.pad_segment", "a", %note
+ .balign 4
+ .long 1f - 0f // int32_t namesz
+ .long 3f - 2f // int32_t descsz
+ .long NT_ANDROID_TYPE_PAD_SEGMENT // int32_t type
+0:
+ .asciz "Android" // char name[]
+1:
+ .balign 2
+2:
+ .long 1 // 1 indicates to pad p_filesz/p_memsz,
+ // such that the current segment ends
+ // where the next segment begins.
+ // If/when padding becomes the default,
+ // 0 can be used to disable this behavior.
+3:
+ .balign 2
diff --git a/libc/private/bionic_asm_note.h b/libc/private/bionic_asm_note.h
index d8559ff..9a533c0 100644
--- a/libc/private/bionic_asm_note.h
+++ b/libc/private/bionic_asm_note.h
@@ -31,3 +31,4 @@
#define NT_ANDROID_TYPE_IDENT 1
#define NT_ANDROID_TYPE_KUSER 3
#define NT_ANDROID_TYPE_MEMTAG 4
+#define NT_ANDROID_TYPE_PAD_SEGMENT 5