]> git.proxmox.com Git - mirror_qemu.git/commitdiff
linux-user: Define ELF_ET_DYN_BASE in $guest/target_mman.h
authorRichard Henderson <richard.henderson@linaro.org>
Wed, 2 Aug 2023 22:17:33 +0000 (15:17 -0700)
committerRichard Henderson <richard.henderson@linaro.org>
Tue, 8 Aug 2023 20:27:15 +0000 (13:27 -0700)
Copy each guest kernel's default value, then bound it
against reserved_va or the host address space.

Tested-by: Helge Deller <deller@gmx.de>
Reviewed-by: Helge Deller <deller@gmx.de>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
23 files changed:
linux-user/aarch64/target_mman.h
linux-user/alpha/target_mman.h
linux-user/arm/target_mman.h
linux-user/cris/target_mman.h
linux-user/hexagon/target_mman.h
linux-user/hppa/target_mman.h
linux-user/i386/target_mman.h
linux-user/loongarch64/target_mman.h
linux-user/m68k/target_mman.h
linux-user/main.c
linux-user/microblaze/target_mman.h
linux-user/mips/target_mman.h
linux-user/mmap.c
linux-user/nios2/target_mman.h
linux-user/openrisc/target_mman.h
linux-user/ppc/target_mman.h
linux-user/riscv/target_mman.h
linux-user/s390x/target_mman.h
linux-user/sh4/target_mman.h
linux-user/sparc/target_mman.h
linux-user/user-mmap.h
linux-user/x86_64/target_mman.h
linux-user/xtensa/target_mman.h

index 4d3eecfb26abbe87335ec2b372ca4a8053da57a1..69ec5d5739ca52d8b5cdd28de05c48441aae7982 100644 (file)
@@ -14,6 +14,9 @@
  */
 #define TASK_UNMAPPED_BASE      (1ull << (48 - 2))
 
+/* arch/arm64/include/asm/elf.h */
+#define ELF_ET_DYN_BASE         TARGET_PAGE_ALIGN((1ull << 48) / 3 * 2)
+
 #include "../generic/target_mman.h"
 
 #endif
index c90b4937117027f100a95c0ed5d0bf7cc0a7ecc9..8edfe2b88ccccbec7ff66e898a4e4d014d41878d 100644 (file)
@@ -28,6 +28,9 @@
  */
 #define TASK_UNMAPPED_BASE      0x20000000000ull
 
+/* arch/alpha/include/asm/elf.h */
+#define ELF_ET_DYN_BASE         (TASK_UNMAPPED_BASE + 0x1000000)
+
 #include "../generic/target_mman.h"
 
 #endif
index 76275b2c7e0f1b7a1ad7906e33e3c02ed093bee8..51005da869f3169327cbc90e42224f5c2ee28624 100644 (file)
@@ -6,4 +6,7 @@
  */
 #define TASK_UNMAPPED_BASE   0x40000000
 
+/* arch/arm/include/asm/elf.h */
+#define ELF_ET_DYN_BASE      0x00400000
+
 #include "../generic/target_mman.h"
index 9df7b1eda589f1e02df5e108ff9e4ed8a2b00f01..9ace8ac292584cd3288b2e8ddb47bb1b6bd6988f 100644 (file)
@@ -7,4 +7,7 @@
  */
 #define TASK_UNMAPPED_BASE TARGET_PAGE_ALIGN(0xb0000000 / 3)
 
+/* arch/cris/include/uapi/asm/elf.h */
+#define ELF_ET_DYN_BASE    (TASK_UNMAPPED_BASE * 2)
+
 #include "../generic/target_mman.h"
index c5ae336e07d3267f84ad8d4c14ed2b6916c3d6ba..e6b5e2ca36ba5ae5751802f42376e4463fcce496 100644 (file)
@@ -8,4 +8,7 @@
  */
 #define TASK_UNMAPPED_BASE   0x40000000
 
+/* arch/hexagon/include/asm/elf.h */
+#define ELF_ET_DYN_BASE      0x08000000
+
 #include "../generic/target_mman.h"
index 6459e7dbddc5c9b6e38e034e1b99f68571697d0e..ccda46e842b132efaf5ecd9328e3afafff45d9b9 100644 (file)
@@ -27,6 +27,9 @@
 /* arch/parisc/include/asm/processor.h: DEFAULT_MAP_BASE32 */
 #define TASK_UNMAPPED_BASE      0x40000000
 
+/* arch/parisc/include/asm/elf.h */
+#define ELF_ET_DYN_BASE         (TASK_UNMAPPED_BASE + 0x01000000)
+
 #include "../generic/target_mman.h"
 
 #endif
index cc3382007fe49c952f2a0df5a0f9cba86101dc15..e3b8e1eaa62e8f12fb89c6574c0e4a23598b1db2 100644 (file)
@@ -11,4 +11,7 @@
  */
 #define TASK_UNMAPPED_BASE    0x40000000
 
+/* arch/x86/include/asm/elf.h */
+#define ELF_ET_DYN_BASE       0x00400000
+
 #include "../generic/target_mman.h"
index d70e44d44c68290735f2b61be346928c7839be5c..8c2a3d5596038a5fd03e4b6c40e2c519dbd89414 100644 (file)
@@ -6,4 +6,7 @@
 #define TASK_UNMAPPED_BASE \
     TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3)
 
+/* arch/loongarch/include/asm/elf.h */
+#define ELF_ET_DYN_BASE       (TASK_UNMAPPED_BASE * 2)
+
 #include "../generic/target_mman.h"
index d3eceb663be0546d43dcf1028b63ad7efa636d57..20cfe750c5bc7416f26cf2f5cbbe38354880b89b 100644 (file)
@@ -1,4 +1,6 @@
 /* arch/m68k/include/asm/processor.h */
 #define TASK_UNMAPPED_BASE      0xC0000000
+/* arch/m68k/include/asm/elf.h */
+#define ELF_ET_DYN_BASE         0xD0000000
 
 #include "../generic/target_mman.h"
index be621dc792e220a3fd5a0073ea59496e7c52e1e4..96be354897dd22e622de2854557066e1f5add11a 100644 (file)
@@ -847,6 +847,21 @@ int main(int argc, char **argv, char **envp)
     }
     mmap_next_start = task_unmapped_base;
 
+    /* Similarly for elf_et_dyn_base. */
+    if (reserved_va) {
+        if (ELF_ET_DYN_BASE < reserved_va) {
+            elf_et_dyn_base = ELF_ET_DYN_BASE;
+        } else {
+            /* The most common default formula is TASK_SIZE / 3 * 2. */
+            elf_et_dyn_base = TARGET_PAGE_ALIGN(reserved_va / 3) * 2;
+        }
+    } else if (ELF_ET_DYN_BASE < UINTPTR_MAX) {
+        elf_et_dyn_base = ELF_ET_DYN_BASE;
+    } else {
+        /* 32-bit host: pick something medium size. */
+        elf_et_dyn_base = 0x18000000;
+    }
+
 #pragma GCC diagnostic pop
 
     {
index ffee869db4cebe6dce9b139d45d57f66e5682fb7..6b3dd54f898bb6629f26904e256870f6ea28b75a 100644 (file)
@@ -6,4 +6,7 @@
  */
 #define TASK_UNMAPPED_BASE      0x48000000
 
+/* arch/microblaze/include/uapi/asm/elf.h */
+#define ELF_ET_DYN_BASE         0x08000000
+
 #include "../generic/target_mman.h"
index fe1eec2d0b8b42b101b02bcca3e8339bb9d2874b..b84fe1e8a8678438432ce4c15b5135f37a5f1936 100644 (file)
@@ -21,6 +21,9 @@
 #define TASK_UNMAPPED_BASE \
     TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3)
 
+/* arch/mips/include/asm/elf.h */
+#define ELF_ET_DYN_BASE       (TASK_UNMAPPED_BASE * 2)
+
 #include "../generic/target_mman.h"
 
 #endif
index 84436d45c84bca6aef839c1a9a50ef58a4d74db2..9aab48d4a30e1b3a2daae5124cde23641001d75b 100644 (file)
@@ -300,6 +300,7 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last,
 }
 
 abi_ulong task_unmapped_base;
+abi_ulong elf_et_dyn_base;
 abi_ulong mmap_next_start;
 
 /*
index ce18f4f8713e078395528dc8ceba91d99157dccb..ab16ad4f03cb26d035f97cc6b28fd8dd0eab4070 100644 (file)
@@ -5,4 +5,7 @@
  */
 #define TASK_UNMAPPED_BASE    TARGET_PAGE_ALIGN(0x7FFF0000 / 3)
 
+/* arch/nios2/include/asm/elf.h */
+#define ELF_ET_DYN_BASE       0xD0000000
+
 #include "../generic/target_mman.h"
index f1aaad809d032527a6088b3696f80de01d4e02cb..243c1d5f26c63ccab9f3b770f9d412758bfb0eac 100644 (file)
@@ -5,4 +5,7 @@
  */
 #define TASK_UNMAPPED_BASE      0x30000000
 
+/* arch/openrisc/include/asm/elf.h */
+#define ELF_ET_DYN_BASE         0x08000000
+
 #include "../generic/target_mman.h"
index 04f99c60770a7083e2ca987abb6b2681350ba48a..646d1ccae74fa4427039357c797113927eca316d 100644 (file)
 #define TASK_UNMAPPED_BASE      0x40000000
 #endif
 
+/* arch/powerpc/include/asm/elf.h */
+#ifdef TARGET_PPC64
+#define ELF_ET_DYN_BASE         0x100000000ull
+#else
+#define ELF_ET_DYN_BASE         0x000400000
+#endif
+
 #include "../generic/target_mman.h"
 
 #endif
index 0f06dadbd4b325aa919bb2e184d61cae5a00ab86..3049bcc67db95597eb5ef19ae37e932512f4af61 100644 (file)
@@ -5,4 +5,7 @@
 #define TASK_UNMAPPED_BASE \
     TARGET_PAGE_ALIGN((1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 1)) / 3)
 
+/* arch/riscv/include/asm/elf.h */
+#define ELF_ET_DYN_BASE       (TASK_UNMAPPED_BASE * 2)
+
 #include "../generic/target_mman.h"
index 40d149b3296824aba462f751bc7df292d09d7fa9..c82435e3813a8360aa44fe48fffd789faaa70ff1 100644 (file)
@@ -8,4 +8,14 @@
  */
 #define TASK_UNMAPPED_BASE      (1ull << 41)
 
+/*
+ * arch/s390/include/asm/elf.h:
+ * ELF_ET_DYN_BASE              (STACK_TOP / 3 * 2) & ~((1UL << 32) - 1)
+ *
+ * arch/s390/include/asm/processor.h:
+ * STACK_TOP                    VDSO_LIMIT - VDSO_SIZE - PAGE_SIZE
+ * VDSO_LIMIT                   _REGION2_SIZE
+ */
+#define ELF_ET_DYN_BASE         (((1ull << 42) / 3 * 2) & ~0xffffffffull)
+
 #include "../generic/target_mman.h"
index bbbc223398dd8ab1216702998f66692f85f8036b..dd9016081e9fc9bed1005bc443bf153b260b0f3c 100644 (file)
@@ -2,4 +2,7 @@
 #define TASK_UNMAPPED_BASE \
     TARGET_PAGE_ALIGN((1u << TARGET_VIRT_ADDR_SPACE_BITS) / 3)
 
+/* arch/sh/include/asm/elf.h */
+#define ELF_ET_DYN_BASE       (TASK_UNMAPPED_BASE * 2)
+
 #include "../generic/target_mman.h"
index 692ebf9dd73dbd54cfff73d67d1845d2664b66b6..696ca73fe47e038e22ac983aa5014b569ed29151 100644 (file)
 #define TASK_UNMAPPED_BASE      (1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 2))
 #endif
 
+/*
+ * arch/sparc/include/asm/elf_64.h
+ * Except that COMPAT_ELF_ET_DYN_BASE exactly matches TASK_UNMAPPED_BASE,
+ * so move it up a bit.
+ */
+#ifdef TARGET_ABI32
+#define ELF_ET_DYN_BASE         0x78000000
+#else
+#define ELF_ET_DYN_BASE         0x0000010000000000ull
+#endif
+
 #include "../generic/target_mman.h"
 
 #endif
index f844ba4e619f17c764ad29ff4ed4bc88a49ad463..0f4883eb5719e79b65661316b1470b748a3d2632 100644 (file)
  * TASK_UNMAPPED_BASE: For mmap without hint (addr != 0), the search
  * for unused virtual memory begins at TASK_UNMAPPED_BASE.
  *
- * task_unmapped_base: When the guest address space is limited via -R,
- * the value of TASK_UNMAPPED_BASE is adjusted to fit.
+ * ELF_ET_DYN_BASE: When the executable is ET_DYN (i.e. PIE), and requires
+ * an interpreter (i.e. not -static-pie), use ELF_ET_DYN_BASE instead of
+ * TASK_UNMAPPED_BASE for selecting the address of the executable.
+ * This provides some distance between the executable and the interpreter,
+ * which allows the initial brk to be placed immediately after the
+ * executable and also have room to grow.
+ *
+ * task_unmapped_base, elf_et_dyn_base: When the guest address space is
+ * limited via -R, the values of TASK_UNMAPPED_BASE and ELF_ET_DYN_BASE
+ * must be adjusted to fit.
  */
 extern abi_ulong task_unmapped_base;
+extern abi_ulong elf_et_dyn_base;
 
 /*
  * mmap_next_start: The base address for the next mmap without hint,
index f9ff652b377e61baecc5c6c3283e23ac72cf5e28..48fbf20b424728883d08f18933f904ff4c87b213 100644 (file)
@@ -10,4 +10,7 @@
 #define TASK_UNMAPPED_BASE \
     TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3)
 
+/* arch/x86/include/asm/elf.h */
+#define ELF_ET_DYN_BASE       (TASK_UNMAPPED_BASE * 2)
+
 #include "../generic/target_mman.h"
index c4f671adb71cbc4173846164a0671de55a7ab129..8fa6337a976d82fc5a57856d0e31ce21bc949aad 100644 (file)
  */
 #define TASK_UNMAPPED_BASE      (1u << (TARGET_VIRT_ADDR_SPACE_BITS - 1))
 
+/* arch/xtensa/include/asm/elf.h */
+#define ELF_ET_DYN_BASE \
+    TARGET_PAGE_ALIGN((1u << TARGET_VIRT_ADDR_SPACE_BITS) / 3)
+
 #include "../generic/target_mman.h"
 
 #endif