qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 0/3] linux-user: Fix and optimize target memory layout
@ 2023-07-28 17:31 Helge Deller
  2023-07-28 17:31 ` [PATCH v5 1/3] linux-user: Show heap address in /proc/pid/maps Helge Deller
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Helge Deller @ 2023-07-28 17:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent Vivier, Paolo Bonzini, Richard Henderson, Helge Deller

While trying to fix a bug which prevents running a static
armhf binary with linux-user, I noticed a whole bunch of
memory layout issues on various platforms. Most noteably
the free heap space was very limited in the current setup.
A large heap is important for example, if you want to
use qemu-user for building Linux packages where gcc requires
lots of space (e.g. using qemu-user as buildd for debian
packages).

Those findings led to this patch series, which
- fixes qemu-arm to run static armhf binaries
- shows the address of heap in /proc/self/maps output on
  all architectures
- optimizes address layout of loaded executable
- increases free heap for guest apps

NOTE:
- this patch series is for qemu v8.1.0-rc ONLY.
- do not apply on top of v8.0-stable series, which uses
  a different search algorithm for free mmap memory
  and thus will give incorrect memory layouts.

If people want to check, you may pull from here:
https://github.com/hdeller/qemu-hppa/tree/brk-fixes-2

It would be great if other people would test as well, and
if this patch series would be considered for inclusion into
8.0-rc release.

I tested the patch series on top of git head with chroots of alpha, arm,
armel, arm64, hppa, m68k, mips64el, mipsel, powerpc, ppc64, ppc64el,
s390x, sh4 and sparc64 on a x86-64 host.
The memory layout of git head and the layout with this patch series are
both shown below as reference.

Changes:
v5:
- Runtime-checked on many target architectures
- Calculate valid memory layout based on GUEST_ADDR_MAX limit
- Really fixed showing heap in /proc/self/maps for all architectures
v4:
- add note that patch series is for v8.1.0-rc only
- changed TASK_UNMAPPED_BASE for 32- on 64-bit userspace

------------------------------------------------------------------------------------
Memory layout with this patch series applied:
(output of: "uname -a && cat /proc/self/maps" from inside the chroot)

alpha-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 alpha GNU/Linux
120000000-12000a000 r-xp 00000000 fd:00 417269                           /usr/bin/cat
12000a000-12001e000 ---p 00000000 00:00 0
12001e000-120020000 r--p 0000e000 fd:00 417269                           /usr/bin/cat
120020000-120022000 rw-p 00000000 00:00 0
120022000-120044000 rw-p 00000000 00:00 0                                [heap]
7000000000-7000002000 ---p 00000000 00:00 0
7000002000-7000802000 rw-p 00000000 00:00 0                              [stack]
7000802000-7000830000 r-xp 00000000 fd:00 421566                         /usr/lib/alpha-linux-gnu/ld-linux.so.2
7000830000-7000840000 ---p 00000000 00:00 0
7000840000-7000842000 r--p 0002e000 fd:00 421566                         /usr/lib/alpha-linux-gnu/ld-linux.so.2
7000842000-7000844000 rw-p 00030000 fd:00 421566                         /usr/lib/alpha-linux-gnu/ld-linux.so.2
7000844000-7000846000 r-xp 00000000 00:00 0
7000850000-7000a30000 r-xp 00000000 fd:00 421569                         /usr/lib/alpha-linux-gnu/libc.so.6.1
7000a30000-7000a3c000 ---p 001e0000 fd:00 421569                         /usr/lib/alpha-linux-gnu/libc.so.6.1
7000a3c000-7000a40000 r--p 001ec000 fd:00 421569                         /usr/lib/alpha-linux-gnu/libc.so.6.1
7000a40000-7000a42000 rw-p 001f0000 fd:00 421569                         /usr/lib/alpha-linux-gnu/libc.so.6.1
7000a42000-7000a50000 rw-p 00000000 00:00 0
7000a56000-7000a5a000 rw-p 00000000 00:00 0
7f3a0c000000-7f3a0c000000 ---p 00000000 00:00 0
7f3a11e00000-7f3a11e00000 ---p 00000000 00:00 0

arm64-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 aarch64 GNU/Linux
5500000000-5500009000 r-xp 00000000 fd:00 570430                         /usr/bin/cat
5500009000-550001f000 ---p 00000000 00:00 0
550001f000-5500020000 r--p 0000f000 fd:00 570430                         /usr/bin/cat
5500020000-5500021000 rw-p 00010000 fd:00 570430                         /usr/bin/cat
5500021000-5500042000 rw-p 00000000 00:00 0                              [heap]
7000000000-7000001000 ---p 00000000 00:00 0
7000001000-7000801000 rw-p 00000000 00:00 0                              [stack]
7000801000-7000827000 r-xp 00000000 fd:00 571555                         /usr/lib/aarch64-linux-gnu/ld-linux-aarch64.so.1
7000827000-700083f000 ---p 00000000 00:00 0
700083f000-7000841000 r--p 0002e000 fd:00 571555                         /usr/lib/aarch64-linux-gnu/ld-linux-aarch64.so.1
7000841000-7000843000 rw-p 00030000 fd:00 571555                         /usr/lib/aarch64-linux-gnu/ld-linux-aarch64.so.1
7000843000-7000844000 r-xp 00000000 00:00 0
7000844000-7000846000 rw-p 00000000 00:00 0
7000850000-70009d7000 r-xp 00000000 fd:00 571558                         /usr/lib/aarch64-linux-gnu/libc.so.6
70009d7000-70009ed000 ---p 00187000 fd:00 571558                         /usr/lib/aarch64-linux-gnu/libc.so.6
70009ed000-70009f0000 r--p 0018d000 fd:00 571558                         /usr/lib/aarch64-linux-gnu/libc.so.6
70009f0000-70009f2000 rw-p 00190000 fd:00 571558                         /usr/lib/aarch64-linux-gnu/libc.so.6
70009f2000-70009ff000 rw-p 00000000 00:00 0

armel-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 armv7l GNU/Linux
00300000-00308000 r-xp 00000000 fd:00 801471                             /usr/bin/cat
00308000-0031f000 ---p 00000000 00:00 0
0031f000-00320000 r--p 0000f000 fd:00 801471                             /usr/bin/cat
00320000-00321000 rw-p 00010000 fd:00 801471                             /usr/bin/cat
00321000-00342000 rw-p 00000000 00:00 0                                  [heap]
f3000000-f3001000 ---p 00000000 00:00 0
f3001000-f3801000 rw-p 00000000 00:00 0                                  [stack]
f3801000-f3827000 r-xp 00000000 fd:00 802599                             /usr/lib/arm-linux-gnueabi/ld-linux.so.3
f3827000-f3828000 r--p 00026000 fd:00 802599                             /usr/lib/arm-linux-gnueabi/ld-linux.so.3
f3828000-f3829000 rw-p 00027000 fd:00 802599                             /usr/lib/arm-linux-gnueabi/ld-linux.so.3
f3829000-f382a000 r-xp 00000000 00:00 0
f382a000-f382c000 rw-p 00000000 00:00 0
f382c000-f399e000 r-xp 00000000 fd:00 802602                             /usr/lib/arm-linux-gnueabi/libc.so.6
f399e000-f39a0000 r--p 00172000 fd:00 802602                             /usr/lib/arm-linux-gnueabi/libc.so.6
f39a0000-f39a1000 rw-p 00174000 fd:00 802602                             /usr/lib/arm-linux-gnueabi/libc.so.6
f39a1000-f39ab000 rw-p 00000000 00:00 0
ffff0000-ffff1000 r-xp 00000000 00:00 0

hppa-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 parisc GNU/Linux
00000000-00001000 --xp 00000000 00:00 0
00010000-00019000 r-xp 00000000 fd:00 1061893                            /usr/bin/cat
00019000-0001a000 rwxp 00009000 fd:00 1061893                            /usr/bin/cat
0001a000-0003b000 rw-p 00000000 00:00 0                                  [heap]
f3000000-f8000000 rwxp 00000000 00:00 0                                  [stack]
f8000000-f802f000 r-xp 00000000 fd:00 1069300                            /usr/lib/hppa-linux-gnu/ld.so.1
f802f000-f8030000 r--p 0002f000 fd:00 1069300                            /usr/lib/hppa-linux-gnu/ld.so.1
f8030000-f8034000 rwxp 00030000 fd:00 1069300                            /usr/lib/hppa-linux-gnu/ld.so.1
f8034000-f8035000 r-xp 00000000 00:00 0
f8035000-f8037000 rw-p 00000000 00:00 0
f8037000-f81f3000 r-xp 00000000 fd:00 1069303                            /usr/lib/hppa-linux-gnu/libc.so.6
f81f3000-f81f5000 r--p 001bc000 fd:00 1069303                            /usr/lib/hppa-linux-gnu/libc.so.6
f81f5000-f81fa000 rwxp 001be000 fd:00 1069303                            /usr/lib/hppa-linux-gnu/libc.so.6

m68k-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 m68k GNU/Linux
80000000-80007000 r-xp 00000000 fd:00 409133                             /usr/bin/cat
80007000-80009000 ---p 00000000 00:00 0
80009000-8000a000 r--p 00007000 fd:00 409133                             /usr/bin/cat
8000a000-8000b000 rw-p 00008000 fd:00 409133                             /usr/bin/cat
8000b000-8002c000 rw-p 00000000 00:00 0                                  [heap]
f3000000-f3001000 ---p 00000000 00:00 0
f3001000-f3801000 rw-p 00000000 00:00 0                                  [stack]
f3801000-f3821000 r-xp 00000000 fd:00 448209                             /usr/lib/m68k-linux-gnu/ld.so.1
f3821000-f3822000 ---p 00000000 00:00 0
f3822000-f3823000 r--p 00021000 fd:00 448209                             /usr/lib/m68k-linux-gnu/ld.so.1
f3823000-f3825000 rw-p 00022000 fd:00 448209                             /usr/lib/m68k-linux-gnu/ld.so.1
f3825000-f3826000 r-xp 00000000 00:00 0
f3826000-f3997000 r-xp 00000000 fd:00 448212                             /usr/lib/m68k-linux-gnu/libc.so.6
f3997000-f3998000 ---p 00171000 fd:00 448212                             /usr/lib/m68k-linux-gnu/libc.so.6
f3998000-f399a000 r--p 00170000 fd:00 448212                             /usr/lib/m68k-linux-gnu/libc.so.6
f399a000-f399e000 rw-p 00172000 fd:00 448212                             /usr/lib/m68k-linux-gnu/libc.so.6
f399e000-f39aa000 rw-p 00000000 00:00 0

mips64el-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 mips64 GNU/Linux
5500000000-550000b000 r-xp 00000000 fd:00 811277                         /usr/bin/cat
550000b000-550001f000 ---p 00000000 00:00 0
550001f000-5500020000 r--p 0000f000 fd:00 811277                         /usr/bin/cat
5500020000-5500021000 rw-p 00010000 fd:00 811277                         /usr/bin/cat
5500021000-5500042000 rw-p 00000000 00:00 0                              [heap]
7000000000-7000001000 ---p 00000000 00:00 0
7000001000-7000801000 rwxp 00000000 00:00 0                              [stack]
7000801000-700082e000 r-xp 00000000 fd:00 812402                         /usr/lib/mips64el-linux-gnuabi64/ld.so.1
700082e000-7000840000 ---p 00000000 00:00 0
7000840000-7000841000 r--p 0002f000 fd:00 812402                         /usr/lib/mips64el-linux-gnuabi64/ld.so.1
7000841000-7000843000 rw-p 00030000 fd:00 812402                         /usr/lib/mips64el-linux-gnuabi64/ld.so.1
7000843000-7000844000 r-xp 00000000 00:00 0
7000844000-7000846000 rw-p 00000000 00:00 0
7000850000-7000a3a000 r-xp 00000000 fd:00 812405                         /usr/lib/mips64el-linux-gnuabi64/libc.so.6
7000a3a000-7000a4a000 ---p 001ea000 fd:00 812405                         /usr/lib/mips64el-linux-gnuabi64/libc.so.6
7000a4a000-7000a50000 r--p 001ea000 fd:00 812405                         /usr/lib/mips64el-linux-gnuabi64/libc.so.6
7000a50000-7000a55000 rw-p 001f0000 fd:00 812405                         /usr/lib/mips64el-linux-gnuabi64/libc.so.6
7000a55000-7000a62000 rw-p 00000000 00:00 0
7000a68000-7000a6a000 rw-p 00000000 00:00 0

mipsel-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 mips GNU/Linux
00300000-00309000 r-xp 00000000 fd:00 818831                             /usr/bin/cat
00309000-0031f000 ---p 00000000 00:00 0
0031f000-00320000 r--p 0000f000 fd:00 818831                             /usr/bin/cat
00320000-00321000 rw-p 00010000 fd:00 818831                             /usr/bin/cat
00321000-00342000 rw-p 00000000 00:00 0                                  [heap]
73000000-73001000 ---p 00000000 00:00 0
73001000-73801000 rwxp 00000000 00:00 0                                  [stack]
73801000-7382d000 r-xp 00000000 fd:00 819956                             /usr/lib/mipsel-linux-gnu/ld.so.1
7382d000-73840000 ---p 00000000 00:00 0
73840000-73841000 r--p 0002f000 fd:00 819956                             /usr/lib/mipsel-linux-gnu/ld.so.1
73841000-73842000 rw-p 00030000 fd:00 819956                             /usr/lib/mipsel-linux-gnu/ld.so.1
73842000-73843000 r-xp 00000000 00:00 0
73843000-73845000 rw-p 00000000 00:00 0
73850000-73a0e000 r-xp 00000000 fd:00 819959                             /usr/lib/mipsel-linux-gnu/libc.so.6
73a0e000-73a1d000 ---p 001be000 fd:00 819959                             /usr/lib/mipsel-linux-gnu/libc.so.6
73a1d000-73a20000 r--p 001bd000 fd:00 819959                             /usr/lib/mipsel-linux-gnu/libc.so.6
73a20000-73a23000 rw-p 001c0000 fd:00 819959                             /usr/lib/mipsel-linux-gnu/libc.so.6
73a23000-73a2d000 rw-p 00000000 00:00 0

powerpc-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 ppc GNU/Linux
000c0000-002d5000 r-xp 00000000 fd:00 538459                             /usr/lib/powerpc-linux-gnu/libc.so.6
002d5000-002eb000 ---p 00215000 fd:00 538459                             /usr/lib/powerpc-linux-gnu/libc.so.6
002eb000-002f0000 r--p 0021b000 fd:00 538459                             /usr/lib/powerpc-linux-gnu/libc.so.6
002f0000-002f1000 rw-p 00220000 fd:00 538459                             /usr/lib/powerpc-linux-gnu/libc.so.6
002f1000-002fb000 rw-p 00000000 00:00 0
00300000-0030b000 r-xp 00000000 fd:00 535994                             /usr/bin/cat
0030b000-0031f000 ---p 00000000 00:00 0
0031f000-00320000 r--p 0000f000 fd:00 535994                             /usr/bin/cat
00320000-00321000 rw-p 00010000 fd:00 535994                             /usr/bin/cat
00321000-00343000 rw-p 00000000 00:00 0                                  [heap]
f3000000-f3001000 ---p 00000000 00:00 0
f3001000-f3801000 rw-p 00000000 00:00 0                                  [stack]
f3801000-f3834000 r-xp 00000000 fd:00 538456                             /usr/lib/powerpc-linux-gnu/ld.so.1
f3834000-f384f000 ---p 00000000 00:00 0
f384f000-f3851000 r--p 0003e000 fd:00 538456                             /usr/lib/powerpc-linux-gnu/ld.so.1
f3851000-f3852000 rw-p 00040000 fd:00 538456                             /usr/lib/powerpc-linux-gnu/ld.so.1
f3852000-f3853000 r-xp 00000000 00:00 0
f3853000-f3855000 rw-p 00000000 00:00 0

ppc64-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 ppc64 GNU/Linux
5500000000-550000c000 r-xp 00000000 fd:00 550284                         /usr/bin/cat
550000c000-550001f000 ---p 00000000 00:00 0
550001f000-5500020000 r--p 0000f000 fd:00 550284                         /usr/bin/cat
5500020000-5500021000 rw-p 00010000 fd:00 550284                         /usr/bin/cat
5500021000-5500042000 rw-p 00000000 00:00 0                              [heap]
7000000000-7000001000 ---p 00000000 00:00 0
7000001000-7000801000 rw-p 00000000 00:00 0                              [stack]
7000801000-7000847000 r-xp 00000000 fd:00 551358                         /usr/lib/powerpc64-linux-gnu/ld64.so.1
7000847000-700085e000 ---p 00000000 00:00 0
700085e000-7000861000 r--p 0004d000 fd:00 551358                         /usr/lib/powerpc64-linux-gnu/ld64.so.1
7000861000-7000863000 rw-p 00050000 fd:00 551358                         /usr/lib/powerpc64-linux-gnu/ld64.so.1
7000863000-7000864000 r-xp 00000000 00:00 0
7000870000-7000a7a000 r-xp 00000000 fd:00 551361                         /usr/lib/powerpc64-linux-gnu/libc.so.6
7000a7a000-7000a87000 ---p 0020a000 fd:00 551361                         /usr/lib/powerpc64-linux-gnu/libc.so.6
7000a87000-7000aa0000 r--p 00217000 fd:00 551361                         /usr/lib/powerpc64-linux-gnu/libc.so.6
7000aa0000-7000aa2000 rw-p 00230000 fd:00 551361                         /usr/lib/powerpc64-linux-gnu/libc.so.6
7000aa2000-7000aaf000 rw-p 00000000 00:00 0
7000ab3000-7000ab5000 rw-p 00000000 00:00 0

ppc64el-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 ppc64le GNU/Linux
5500000000-550000b000 r-xp 00000000 fd:00 826393                         /usr/bin/cat
550000b000-550001f000 ---p 00000000 00:00 0
550001f000-5500020000 r--p 0000f000 fd:00 826393                         /usr/bin/cat
5500020000-5500021000 rw-p 00010000 fd:00 826393                         /usr/bin/cat
5500021000-5500042000 rw-p 00000000 00:00 0                              [heap]
7000000000-7000001000 ---p 00000000 00:00 0
7000001000-7000801000 rw-p 00000000 00:00 0                              [stack]
7000801000-700084e000 r-xp 00000000 fd:00 827518                         /usr/lib/powerpc64le-linux-gnu/ld64.so.2
700084e000-700085f000 ---p 00000000 00:00 0
700085f000-7000861000 r--p 0004e000 fd:00 827518                         /usr/lib/powerpc64le-linux-gnu/ld64.so.2
7000861000-7000863000 rw-p 00050000 fd:00 827518                         /usr/lib/powerpc64le-linux-gnu/ld64.so.2
7000863000-7000864000 r-xp 00000000 00:00 0
7000870000-7000aa4000 r-xp 00000000 fd:00 827521                         /usr/lib/powerpc64le-linux-gnu/libc.so.6
7000aa4000-7000abc000 ---p 00234000 fd:00 827521                         /usr/lib/powerpc64le-linux-gnu/libc.so.6
7000abc000-7000ac0000 r--p 0023c000 fd:00 827521                         /usr/lib/powerpc64le-linux-gnu/libc.so.6
7000ac0000-7000ac2000 rw-p 00240000 fd:00 827521                         /usr/lib/powerpc64le-linux-gnu/libc.so.6
7000ac2000-7000acf000 rw-p 00000000 00:00 0
7000ad3000-7000ad5000 rw-p 00000000 00:00 0

s390x-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 s390x GNU/Linux
5500000000-550000a000 r-xp 00000000 fd:00 833950                         /usr/bin/cat
550000a000-550000b000 r--p 00009000 fd:00 833950                         /usr/bin/cat
550000b000-550000c000 rw-p 0000a000 fd:00 833950                         /usr/bin/cat
550000c000-550002d000 rw-p 00000000 00:00 0                              [heap]
7000000000-7000001000 ---p 00000000 00:00 0
7000001000-7000801000 rw-p 00000000 00:00 0                              [stack]
7000801000-700082b000 r-xp 00000000 fd:00 835075                         /usr/lib/s390x-linux-gnu/ld64.so.1
700082b000-700082d000 r--p 00029000 fd:00 835075                         /usr/lib/s390x-linux-gnu/ld64.so.1
700082d000-700082f000 rw-p 0002b000 fd:00 835075                         /usr/lib/s390x-linux-gnu/ld64.so.1
700082f000-7000830000 r-xp 00000000 00:00 0
7000830000-70009f1000 r-xp 00000000 fd:00 835078                         /usr/lib/s390x-linux-gnu/libc.so.6
70009f1000-70009f5000 r--p 001c1000 fd:00 835078                         /usr/lib/s390x-linux-gnu/libc.so.6
70009f5000-70009f7000 rw-p 001c5000 fd:00 835078                         /usr/lib/s390x-linux-gnu/libc.so.6
70009f7000-7000a06000 rw-p 00000000 00:00 0

sh4-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 sh4 GNU/Linux
00400000-00407000 r-xp 00000000 fd:00 557846                             /usr/bin/cat
00407000-0041f000 ---p 00000000 00:00 0
0041f000-00420000 r--p 0000f000 fd:00 557846                             /usr/bin/cat
00420000-00421000 rw-p 00010000 fd:00 557846                             /usr/bin/cat
00421000-00442000 rw-p 00000000 00:00 0                                  [heap]
73000000-73001000 ---p 00000000 00:00 0
73001000-73801000 rw-p 00000000 00:00 0                                  [stack]
73801000-73822000 r-xp 00000000 fd:00 558920                             /usr/lib/sh4-linux-gnu/ld-linux.so.2
73822000-73840000 ---p 00000000 00:00 0
73840000-73841000 r--p 0002f000 fd:00 558920                             /usr/lib/sh4-linux-gnu/ld-linux.so.2
73841000-73842000 rw-p 00030000 fd:00 558920                             /usr/lib/sh4-linux-gnu/ld-linux.so.2
73842000-73843000 r-xp 00000000 00:00 0
73843000-73845000 rw-p 00000000 00:00 0
73850000-739b8000 r-xp 00000000 fd:00 558923                             /usr/lib/sh4-linux-gnu/libc.so.6
739b8000-739ce000 ---p 00168000 fd:00 558923                             /usr/lib/sh4-linux-gnu/libc.so.6
739ce000-739d0000 r--p 0016e000 fd:00 558923                             /usr/lib/sh4-linux-gnu/libc.so.6
739d0000-739d1000 rw-p 00170000 fd:00 558923                             /usr/lib/sh4-linux-gnu/libc.so.6
739d1000-739db000 rw-p 00000000 00:00 0

sparc64-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 sparc64 GNU/Linux
5500000000-5500008000 r-xp 00000000 fd:00 565395                         /usr/bin/cat
5500008000-55001fe000 ---p 00000000 00:00 0
55001fe000-5500200000 r--p 000fe000 fd:00 565395                         /usr/bin/cat
5500200000-5500202000 rwxp 00100000 fd:00 565395                         /usr/bin/cat
5500202000-5500224000 rw-p 00000000 00:00 0                              [heap]
7000000000-7000002000 ---p 00000000 00:00 0
7000002000-7000802000 rw-p 00000000 00:00 0                              [stack]
7000802000-700082a000 r-xp 00000000 fd:00 525238                         /usr/lib/sparc64-linux-gnu/ld-linux.so.2
700082a000-7000a00000 ---p 00000000 00:00 0
7000a00000-7000a02000 r--p 000fe000 fd:00 525238                         /usr/lib/sparc64-linux-gnu/ld-linux.so.2
7000a02000-7000a04000 rw-p 00100000 fd:00 525238                         /usr/lib/sparc64-linux-gnu/ld-linux.so.2
7000a04000-7000a08000 rw-p 00000000 00:00 0
7000b00000-7000c8c000 r-xp 00000000 fd:00 525241                         /usr/lib/sparc64-linux-gnu/libc.so.6
7000c8c000-7000d04000 ---p 0018c000 fd:00 525241                         /usr/lib/sparc64-linux-gnu/libc.so.6
7000d04000-7000dfc000 ---p 00000000 00:00 0
7000dfc000-7000e00000 r--p 001fc000 fd:00 525241                         /usr/lib/sparc64-linux-gnu/libc.so.6
7000e00000-7000e04000 rwxp 00200000 fd:00 525241                         /usr/lib/sparc64-linux-gnu/libc.so.6
7000e04000-7000e10000 rwxp 00000000 00:00 0
7ff864000000-7ff864000000 ---p 00000000 00:00 0
7ff86b000000-7ff86b000000 ---p 00000000 00:00 0

------------------------------------------------------------------------------------
Memory layout from git head (without this patch series)

alpha-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 alpha GNU/Linux
120000000-12000a000 r-xp 00000000 fd:00 417269                           /usr/bin/cat
12000a000-12001e000 ---p 00000000 00:00 0
12001e000-120020000 r--p 0000e000 fd:00 417269                           /usr/bin/cat
120020000-120021000 rw-p 00000000 00:00 0
120021000-120044000 rw-p 00000000 00:00 0
4000000000-4000002000 ---p 00000000 00:00 0
4000002000-4000802000 rw-p 00000000 00:00 0                              [stack]
4000802000-4000830000 r-xp 00000000 fd:00 421566                         /usr/lib/alpha-linux-gnu/ld-linux.so.2
4000830000-4000840000 ---p 00000000 00:00 0
4000840000-4000842000 r--p 0002e000 fd:00 421566                         /usr/lib/alpha-linux-gnu/ld-linux.so.2
4000842000-4000844000 rw-p 00030000 fd:00 421566                         /usr/lib/alpha-linux-gnu/ld-linux.so.2
4000844000-4000846000 r-xp 00000000 00:00 0
4000850000-4000a30000 r-xp 00000000 fd:00 421569                         /usr/lib/alpha-linux-gnu/libc.so.6.1
4000a30000-4000a3c000 ---p 001e0000 fd:00 421569                         /usr/lib/alpha-linux-gnu/libc.so.6.1
4000a3c000-4000a40000 r--p 001ec000 fd:00 421569                         /usr/lib/alpha-linux-gnu/libc.so.6.1
4000a40000-4000a42000 rw-p 001f0000 fd:00 421569                         /usr/lib/alpha-linux-gnu/libc.so.6.1
4000a42000-4000a50000 rw-p 00000000 00:00 0
4000a56000-4000a5a000 rw-p 00000000 00:00 0

arm64-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 aarch64 GNU/Linux
5500000000-5500009000 r-xp 00000000 fd:00 570430                         /usr/bin/cat
5500009000-550001f000 ---p 00000000 00:00 0
550001f000-5500020000 r--p 0000f000 fd:00 570430                         /usr/bin/cat
5500020000-5500021000 rw-p 00010000 fd:00 570430                         /usr/bin/cat
5500021000-5500042000 rw-p 00000000 00:00 0
5502021000-5502022000 ---p 00000000 00:00 0
5502022000-5502822000 rw-p 00000000 00:00 0                              [stack]
5502822000-5502848000 r-xp 00000000 fd:00 571555                         /usr/lib/aarch64-linux-gnu/ld-linux-aarch64.so.1
5502848000-5502860000 ---p 00000000 00:00 0
5502860000-5502862000 r--p 0002e000 fd:00 571555                         /usr/lib/aarch64-linux-gnu/ld-linux-aarch64.so.1
5502862000-5502864000 rw-p 00030000 fd:00 571555                         /usr/lib/aarch64-linux-gnu/ld-linux-aarch64.so.1
5502864000-5502865000 r-xp 00000000 00:00 0
5502865000-5502867000 rw-p 00000000 00:00 0
5502870000-55029f7000 r-xp 00000000 fd:00 571558                         /usr/lib/aarch64-linux-gnu/libc.so.6
55029f7000-5502a0d000 ---p 00187000 fd:00 571558                         /usr/lib/aarch64-linux-gnu/libc.so.6
5502a0d000-5502a10000 r--p 0018d000 fd:00 571558                         /usr/lib/aarch64-linux-gnu/libc.so.6
5502a10000-5502a12000 rw-p 00190000 fd:00 571558                         /usr/lib/aarch64-linux-gnu/libc.so.6
5502a12000-5502a1f000 rw-p 00000000 00:00 0

armel-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 armv7l GNU/Linux
40000000-40008000 r-xp 00000000 fd:00 801471                             /usr/bin/cat
40008000-4001f000 ---p 00000000 00:00 0
4001f000-40020000 r--p 0000f000 fd:00 801471                             /usr/bin/cat
40020000-40021000 rw-p 00010000 fd:00 801471                             /usr/bin/cat
40021000-40023000 rw-p 00000000 00:00 0
40023000-40195000 r-xp 00000000 fd:00 802602                             /usr/lib/arm-linux-gnueabi/libc.so.6
40195000-40197000 r--p 00172000 fd:00 802602                             /usr/lib/arm-linux-gnueabi/libc.so.6
40197000-40198000 rw-p 00174000 fd:00 802602                             /usr/lib/arm-linux-gnueabi/libc.so.6
40198000-402a2000 rw-p 00000000 00:00 0
41021000-41022000 ---p 00000000 00:00 0
41022000-41822000 rw-p 00000000 00:00 0                                  [stack]
41822000-41848000 r-xp 00000000 fd:00 802599                             /usr/lib/arm-linux-gnueabi/ld-linux.so.3
41848000-41849000 r--p 00026000 fd:00 802599                             /usr/lib/arm-linux-gnueabi/ld-linux.so.3
41849000-4184a000 rw-p 00027000 fd:00 802599                             /usr/lib/arm-linux-gnueabi/ld-linux.so.3
4184a000-4184b000 r-xp 00000000 00:00 0
ffff0000-ffff1000 r-xp 00000000 00:00 0

hppa-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 parisc GNU/Linux
0-1000 --xp 00000000 00:00 0
10000-19000 r-xp 00000000 fd:00 1061893                                  /usr/bin/cat
19000-1a000 rwxp 00009000 fd:00 1061893                                  /usr/bin/cat
1a000-3b000 rw-p 00000000 00:00 0
fa000000-ff000000 rwxp 00000000 00:00 0                                  [stack]
ff000000-ff02f000 r-xp 00000000 fd:00 1062984                            /usr/lib/hppa-linux-gnu/ld.so.1
ff02f000-ff030000 r--p 0002f000 fd:00 1062984                            /usr/lib/hppa-linux-gnu/ld.so.1
ff030000-ff034000 rwxp 00030000 fd:00 1062984                            /usr/lib/hppa-linux-gnu/ld.so.1
ff034000-ff035000 r-xp 00000000 00:00 0
ff035000-ff037000 rw-p 00000000 00:00 0
ff037000-ff1f3000 r-xp 00000000 fd:00 1062987                            /usr/lib/hppa-linux-gnu/libc.so.6
ff1f3000-ff1f5000 r--p 001bc000 fd:00 1062987                            /usr/lib/hppa-linux-gnu/libc.so.6
ff1f5000-ff1fa000 rwxp 001be000 fd:00 1062987                            /usr/lib/hppa-linux-gnu/libc.so.6

m68k-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 m68k GNU/Linux
40000000-40001000 ---p 00000000 00:00 0
40001000-40801000 rw-p 00000000 00:00 0                                  [stack]
40801000-40821000 r-xp 00000000 fd:00 448209                             /usr/lib/m68k-linux-gnu/ld.so.1
40821000-40822000 ---p 00000000 00:00 0
40822000-40823000 r--p 00021000 fd:00 448209                             /usr/lib/m68k-linux-gnu/ld.so.1
40823000-40825000 rw-p 00022000 fd:00 448209                             /usr/lib/m68k-linux-gnu/ld.so.1
40825000-40826000 r-xp 00000000 00:00 0
40826000-40997000 r-xp 00000000 fd:00 448212                             /usr/lib/m68k-linux-gnu/libc.so.6
40997000-40998000 ---p 00171000 fd:00 448212                             /usr/lib/m68k-linux-gnu/libc.so.6
40998000-4099a000 r--p 00170000 fd:00 448212                             /usr/lib/m68k-linux-gnu/libc.so.6
4099a000-4099e000 rw-p 00172000 fd:00 448212                             /usr/lib/m68k-linux-gnu/libc.so.6
4099e000-409aa000 rw-p 00000000 00:00 0
80000000-80007000 r-xp 00000000 fd:00 409133                             /usr/bin/cat
80007000-80009000 ---p 00000000 00:00 0
80009000-8000a000 r--p 00007000 fd:00 409133                             /usr/bin/cat
8000a000-8000b000 rw-p 00008000 fd:00 409133                             /usr/bin/cat
8000b000-8002c000 rw-p 00000000 00:00 0

mips64el-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 mips64 GNU/Linux
4000000000-400000b000 r-xp 00000000 fd:00 811277                         /usr/bin/cat
400000b000-400001f000 ---p 00000000 00:00 0
400001f000-4000020000 r--p 0000f000 fd:00 811277                         /usr/bin/cat
4000020000-4000021000 rw-p 00010000 fd:00 811277                         /usr/bin/cat
4000021000-4000042000 rw-p 00000000 00:00 0
4002021000-4002022000 ---p 00000000 00:00 0
4002022000-4002822000 rwxp 00000000 00:00 0                              [stack]
4002822000-400284f000 r-xp 00000000 fd:00 812402                         /usr/lib/mips64el-linux-gnuabi64/ld.so.1
400284f000-4002861000 ---p 00000000 00:00 0
4002861000-4002862000 r--p 0002f000 fd:00 812402                         /usr/lib/mips64el-linux-gnuabi64/ld.so.1
4002862000-4002864000 rw-p 00030000 fd:00 812402                         /usr/lib/mips64el-linux-gnuabi64/ld.so.1
4002864000-4002865000 r-xp 00000000 00:00 0
4002865000-4002867000 rw-p 00000000 00:00 0
4002870000-4002a5a000 r-xp 00000000 fd:00 812405                         /usr/lib/mips64el-linux-gnuabi64/libc.so.6
4002a5a000-4002a6a000 ---p 001ea000 fd:00 812405                         /usr/lib/mips64el-linux-gnuabi64/libc.so.6
4002a6a000-4002a70000 r--p 001ea000 fd:00 812405                         /usr/lib/mips64el-linux-gnuabi64/libc.so.6
4002a70000-4002a75000 rw-p 001f0000 fd:00 812405                         /usr/lib/mips64el-linux-gnuabi64/libc.so.6
4002a75000-4002a82000 rw-p 00000000 00:00 0
4002a89000-4002a8b000 rw-p 00000000 00:00 0

mipsel-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 mips GNU/Linux
40000000-40009000 r-xp 00000000 fd:00 818831                             /usr/bin/cat
40009000-4001f000 ---p 00000000 00:00 0
4001f000-40020000 r--p 0000f000 fd:00 818831                             /usr/bin/cat
40020000-40021000 rw-p 00010000 fd:00 818831                             /usr/bin/cat
40021000-40023000 rw-p 00000000 00:00 0
40030000-401ee000 r-xp 00000000 fd:00 819959                             /usr/lib/mipsel-linux-gnu/libc.so.6
401ee000-401fd000 ---p 001be000 fd:00 819959                             /usr/lib/mipsel-linux-gnu/libc.so.6
401fd000-40200000 r--p 001bd000 fd:00 819959                             /usr/lib/mipsel-linux-gnu/libc.so.6
40200000-40203000 rw-p 001c0000 fd:00 819959                             /usr/lib/mipsel-linux-gnu/libc.so.6
40203000-4030d000 rw-p 00000000 00:00 0
41021000-41022000 ---p 00000000 00:00 0
41022000-41822000 rwxp 00000000 00:00 0                                  [stack]
41822000-4184e000 r-xp 00000000 fd:00 819956                             /usr/lib/mipsel-linux-gnu/ld.so.1
4184e000-41861000 ---p 00000000 00:00 0
41861000-41862000 r--p 0002f000 fd:00 819956                             /usr/lib/mipsel-linux-gnu/ld.so.1
41862000-41863000 rw-p 00030000 fd:00 819956                             /usr/lib/mipsel-linux-gnu/ld.so.1
41863000-41864000 r-xp 00000000 00:00 0

powerpc-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 ppc GNU/Linux
3fdc0000-3ffd5000 r-xp 00000000 fd:00 538459                             /usr/lib/powerpc-linux-gnu/libc.so.6
3ffd5000-3ffeb000 ---p 00215000 fd:00 538459                             /usr/lib/powerpc-linux-gnu/libc.so.6
3ffeb000-3fff0000 r--p 0021b000 fd:00 538459                             /usr/lib/powerpc-linux-gnu/libc.so.6
3fff0000-3fff1000 rw-p 00220000 fd:00 538459                             /usr/lib/powerpc-linux-gnu/libc.so.6
3fff1000-3fffb000 rw-p 00000000 00:00 0
40000000-4000b000 r-xp 00000000 fd:00 535994                             /usr/bin/cat
4000b000-4001f000 ---p 00000000 00:00 0
4001f000-40020000 r--p 0000f000 fd:00 535994                             /usr/bin/cat
40020000-40021000 rw-p 00010000 fd:00 535994                             /usr/bin/cat
40021000-40123000 rw-p 00000000 00:00 0
41021000-41022000 ---p 00000000 00:00 0
41022000-41822000 rw-p 00000000 00:00 0                                  [stack]
41822000-41855000 r-xp 00000000 fd:00 538456                             /usr/lib/powerpc-linux-gnu/ld.so.1
41855000-41870000 ---p 00000000 00:00 0
41870000-41872000 r--p 0003e000 fd:00 538456                             /usr/lib/powerpc-linux-gnu/ld.so.1
41872000-41873000 rw-p 00040000 fd:00 538456                             /usr/lib/powerpc-linux-gnu/ld.so.1
41873000-41874000 r-xp 00000000 00:00 0

ppc64-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 ppc64 GNU/Linux
4000000000-400000c000 r-xp 00000000 fd:00 550284                         /usr/bin/cat
400000c000-400001f000 ---p 00000000 00:00 0
400001f000-4000020000 r--p 0000f000 fd:00 550284                         /usr/bin/cat
4000020000-4000021000 rw-p 00010000 fd:00 550284                         /usr/bin/cat
4000021000-4000042000 rw-p 00000000 00:00 0
4002021000-4002022000 ---p 00000000 00:00 0
4002022000-4002822000 rw-p 00000000 00:00 0                              [stack]
4002822000-4002868000 r-xp 00000000 fd:00 551358                         /usr/lib/powerpc64-linux-gnu/ld64.so.1
4002868000-400287f000 ---p 00000000 00:00 0
400287f000-4002882000 r--p 0004d000 fd:00 551358                         /usr/lib/powerpc64-linux-gnu/ld64.so.1
4002882000-4002884000 rw-p 00050000 fd:00 551358                         /usr/lib/powerpc64-linux-gnu/ld64.so.1
4002884000-4002885000 r-xp 00000000 00:00 0
4002890000-4002a9a000 r-xp 00000000 fd:00 551361                         /usr/lib/powerpc64-linux-gnu/libc.so.6
4002a9a000-4002aa7000 ---p 0020a000 fd:00 551361                         /usr/lib/powerpc64-linux-gnu/libc.so.6
4002aa7000-4002ac0000 r--p 00217000 fd:00 551361                         /usr/lib/powerpc64-linux-gnu/libc.so.6
4002ac0000-4002ac2000 rw-p 00230000 fd:00 551361                         /usr/lib/powerpc64-linux-gnu/libc.so.6
4002ac2000-4002acf000 rw-p 00000000 00:00 0
4002ad4000-4002ad6000 rw-p 00000000 00:00 0

ppc64el-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 ppc64le GNU/Linux
4000000000-400000b000 r-xp 00000000 fd:00 826393                         /usr/bin/cat
400000b000-400001f000 ---p 00000000 00:00 0
400001f000-4000020000 r--p 0000f000 fd:00 826393                         /usr/bin/cat
4000020000-4000021000 rw-p 00010000 fd:00 826393                         /usr/bin/cat
4000021000-4000042000 rw-p 00000000 00:00 0
4002021000-4002022000 ---p 00000000 00:00 0
4002022000-4002822000 rw-p 00000000 00:00 0                              [stack]
4002822000-400286f000 r-xp 00000000 fd:00 827518                         /usr/lib/powerpc64le-linux-gnu/ld64.so.2
400286f000-4002880000 ---p 00000000 00:00 0
4002880000-4002882000 r--p 0004e000 fd:00 827518                         /usr/lib/powerpc64le-linux-gnu/ld64.so.2
4002882000-4002884000 rw-p 00050000 fd:00 827518                         /usr/lib/powerpc64le-linux-gnu/ld64.so.2
4002884000-4002885000 r-xp 00000000 00:00 0
4002890000-4002ac4000 r-xp 00000000 fd:00 827521                         /usr/lib/powerpc64le-linux-gnu/libc.so.6
4002ac4000-4002adc000 ---p 00234000 fd:00 827521                         /usr/lib/powerpc64le-linux-gnu/libc.so.6
4002adc000-4002ae0000 r--p 0023c000 fd:00 827521                         /usr/lib/powerpc64le-linux-gnu/libc.so.6
4002ae0000-4002ae2000 rw-p 00240000 fd:00 827521                         /usr/lib/powerpc64le-linux-gnu/libc.so.6
4002ae2000-4002aef000 rw-p 00000000 00:00 0
4002af4000-4002af6000 rw-p 00000000 00:00 0

s390x-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 s390x GNU/Linux
4000000000-400000a000 r-xp 00000000 fd:00 833950                         /usr/bin/cat
400000a000-400000b000 r--p 00009000 fd:00 833950                         /usr/bin/cat
400000b000-400000c000 rw-p 0000a000 fd:00 833950                         /usr/bin/cat
400000c000-400002d000 rw-p 00000000 00:00 0
400200c000-400200d000 ---p 00000000 00:00 0
400200d000-400280d000 rw-p 00000000 00:00 0                              [stack]
400280d000-4002837000 r-xp 00000000 fd:00 835075                         /usr/lib/s390x-linux-gnu/ld64.so.1
4002837000-4002839000 r--p 00029000 fd:00 835075                         /usr/lib/s390x-linux-gnu/ld64.so.1
4002839000-400283b000 rw-p 0002b000 fd:00 835075                         /usr/lib/s390x-linux-gnu/ld64.so.1
400283b000-400283c000 r-xp 00000000 00:00 0
400283c000-40029fd000 r-xp 00000000 fd:00 835078                         /usr/lib/s390x-linux-gnu/libc.so.6
40029fd000-4002a01000 r--p 001c1000 fd:00 835078                         /usr/lib/s390x-linux-gnu/libc.so.6
4002a01000-4002a03000 rw-p 001c5000 fd:00 835078                         /usr/lib/s390x-linux-gnu/libc.so.6
4002a03000-4002a12000 rw-p 00000000 00:00 0

sh4-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 sh4 GNU/Linux
400000-407000 r-xp 00000000 fd:00 557846                                 /usr/bin/cat
407000-41f000 ---p 00000000 00:00 0
41f000-420000 r--p 0000f000 fd:00 557846                                 /usr/bin/cat
420000-421000 rw-p 00010000 fd:00 557846                                 /usr/bin/cat
421000-442000 rw-p 00000000 00:00 0
40000000-40001000 ---p 00000000 00:00 0
40001000-40801000 rw-p 00000000 00:00 0                                  [stack]
40801000-40822000 r-xp 00000000 fd:00 558920                             /usr/lib/sh4-linux-gnu/ld-linux.so.2
40822000-40840000 ---p 00000000 00:00 0
40840000-40841000 r--p 0002f000 fd:00 558920                             /usr/lib/sh4-linux-gnu/ld-linux.so.2
40841000-40842000 rw-p 00030000 fd:00 558920                             /usr/lib/sh4-linux-gnu/ld-linux.so.2
40842000-40843000 r-xp 00000000 00:00 0
40843000-40845000 rw-p 00000000 00:00 0
40850000-409b8000 r-xp 00000000 fd:00 558923                             /usr/lib/sh4-linux-gnu/libc.so.6
409b8000-409ce000 ---p 00168000 fd:00 558923                             /usr/lib/sh4-linux-gnu/libc.so.6
409ce000-409d0000 r--p 0016e000 fd:00 558923                             /usr/lib/sh4-linux-gnu/libc.so.6
409d0000-409d1000 rw-p 00170000 fd:00 558923                             /usr/lib/sh4-linux-gnu/libc.so.6
409d1000-409db000 rw-p 00000000 00:00 0

sparc64-chroot
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 sparc64 GNU/Linux
4000000000-4000008000 r-xp 00000000 fd:00 565395                         /usr/bin/cat
4000008000-40001fe000 ---p 00000000 00:00 0
40001fe000-4000200000 r--p 000fe000 fd:00 565395                         /usr/bin/cat
4000200000-4000201000 rwxp 00100000 fd:00 565395                         /usr/bin/cat
4002202000-4002204000 ---p 00000000 00:00 0
4002204000-4002a04000 rw-p 00000000 00:00 0                              [stack]
4002a04000-4002a2c000 r-xp 00000000 fd:00 525238                         /usr/lib/sparc64-linux-gnu/ld-linux.so.2
4002a2c000-4002c02000 ---p 00000000 00:00 0
4002c02000-4002c04000 r--p 000fe000 fd:00 525238                         /usr/lib/sparc64-linux-gnu/ld-linux.so.2
4002c04000-4002c06000 rw-p 00100000 fd:00 525238                         /usr/lib/sparc64-linux-gnu/ld-linux.so.2
4002c06000-4002c0a000 rw-p 00000000 00:00 0
4002d00000-4002e8c000 r-xp 00000000 fd:00 525241                         /usr/lib/sparc64-linux-gnu/libc.so.6
4002e8c000-4002f04000 ---p 0018c000 fd:00 525241                         /usr/lib/sparc64-linux-gnu/libc.so.6
4002f04000-4002ffc000 ---p 00000000 00:00 0
4002ffc000-4003000000 r--p 001fc000 fd:00 525241                         /usr/lib/sparc64-linux-gnu/libc.so.6
4003000000-4003004000 rwxp 00200000 fd:00 525241                         /usr/lib/sparc64-linux-gnu/libc.so.6
4003004000-4003010000 rwxp 00000000 00:00 0

Helge Deller (3):
  linux-user: Show heap address in /proc/pid/maps
  linux-user: Optimize memory layout for static and dynamic executables
  linux-user: Load pie executables at upper memory

 include/exec/cpu_ldst.h |  4 +--
 linux-user/elfload.c    | 59 +++++++++++++----------------------------
 linux-user/loader.h     | 12 +++++++++
 linux-user/main.c       |  2 ++
 linux-user/mmap.c       | 33 ++++++++++++-----------
 linux-user/qemu.h       |  4 +--
 linux-user/syscall.c    | 13 ++++++---
 7 files changed, 64 insertions(+), 63 deletions(-)

--
2.41.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v5 1/3] linux-user: Show heap address in /proc/pid/maps
  2023-07-28 17:31 [PATCH v5 0/3] linux-user: Fix and optimize target memory layout Helge Deller
@ 2023-07-28 17:31 ` Helge Deller
  2023-07-28 17:31 ` [PATCH v5 2/3] linux-user: Optimize memory layout for static and dynamic executables Helge Deller
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Helge Deller @ 2023-07-28 17:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent Vivier, Paolo Bonzini, Richard Henderson, Helge Deller

Show the memory location of the heap in the /proc/pid/maps file inside
the guest. Store the heap address in ts->heap_base, which requires to
make that variable accessible for all guest architectures, not just
architectures for semihosted binaries (arm, m68k, riscv).

Note that /proc/pid/maps in the guest needs to show target-aligned
addresses. This is fixed in this patch, so now the heap and stack
address for architectures like sparc64 and alpha now show up in that
output as well.

Show 32- and 64-bit pointers with 8 digits and leading zeros (%08x/%08lx).
For 64-bit we could use %16lx, but we mimic the Linux kernel, which shows
even 64-bit addresses with %08lx.

Example:

user@machine:/# uname -a
Linux paq 5.15.88+ #47 SMP Sun Jan 15 12:53:11 CET 2023 aarch64 GNU/Linux

user@machine:/# cat /proc/self/maps
Linux p100 6.4.4-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 19 16:32:49 UTC 2023 aarch64 GNU/Linux
5500000000-5500009000 r-xp 00000000 fd:00 570430                         /usr/bin/cat
5500009000-550001f000 ---p 00000000 00:00 0
550001f000-5500020000 r--p 0000f000 fd:00 570430                         /usr/bin/cat
5500020000-5500021000 rw-p 00010000 fd:00 570430                         /usr/bin/cat
5500021000-5500042000 rw-p 00000000 00:00 0                              [heap]
7000000000-7000001000 ---p 00000000 00:00 0
7000001000-7000801000 rw-p 00000000 00:00 0                              [stack]
7000801000-7000827000 r-xp 00000000 fd:00 571555                         /usr/lib/aarch64-linux-gnu/ld-linux-aarch64.so.1
7000827000-700083f000 ---p 00000000 00:00 0
700083f000-7000841000 r--p 0002e000 fd:00 571555                         /usr/lib/aarch64-linux-gnu/ld-linux-aarch64.so.1
7000841000-7000843000 rw-p 00030000 fd:00 571555                         /usr/lib/aarch64-linux-gnu/ld-linux-aarch64.so.1
7000843000-7000844000 r-xp 00000000 00:00 0
7000844000-7000846000 rw-p 00000000 00:00 0
7000850000-70009d7000 r-xp 00000000 fd:00 571558                         /usr/lib/aarch64-linux-gnu/libc.so.6
70009d7000-70009ed000 ---p 00187000 fd:00 571558                         /usr/lib/aarch64-linux-gnu/libc.so.6
70009ed000-70009f0000 r--p 0018d000 fd:00 571558                         /usr/lib/aarch64-linux-gnu/libc.so.6
70009f0000-70009f2000 rw-p 00190000 fd:00 571558                         /usr/lib/aarch64-linux-gnu/libc.so.6

Signed-off-by: Helge Deller <deller@gmx.de>
---
 include/exec/cpu_ldst.h |  4 ++--
 linux-user/main.c       |  2 ++
 linux-user/qemu.h       |  4 ++--
 linux-user/syscall.c    | 13 +++++++++----
 4 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h
index 645476f0e5..f1e6f31e88 100644
--- a/include/exec/cpu_ldst.h
+++ b/include/exec/cpu_ldst.h
@@ -72,10 +72,10 @@
  */
 #if TARGET_VIRT_ADDR_SPACE_BITS <= 32
 typedef uint32_t abi_ptr;
-#define TARGET_ABI_FMT_ptr "%x"
+#define TARGET_ABI_FMT_ptr "%08x"
 #else
 typedef uint64_t abi_ptr;
-#define TARGET_ABI_FMT_ptr "%"PRIx64
+#define TARGET_ABI_FMT_ptr "%08"PRIx64
 #endif

 #ifndef TARGET_TAGGED_ADDRESSES
diff --git a/linux-user/main.c b/linux-user/main.c
index dba67ffa36..fa6e47510f 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -946,6 +946,7 @@ int main(int argc, char **argv, char **envp)
         }
     }

+    info->brk = TARGET_PAGE_ALIGN(info->brk);
     target_set_brk(info->brk);
     syscall_init();
     signal_init();
@@ -955,6 +956,7 @@ int main(int argc, char **argv, char **envp)
        the real value of GUEST_BASE into account.  */
     tcg_prologue_init(tcg_ctx);

+    ts->heap_base = info->brk;
     target_cpu_copy_regs(env, regs);

     if (gdbstub) {
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 802794db63..7a6adac637 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -121,11 +121,11 @@ typedef struct TaskState {
 #ifdef TARGET_M68K
     abi_ulong tp_value;
 #endif
-#if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_RISCV)
+
     /* Extra fields for semihosted binaries.  */
     abi_ulong heap_base;
     abi_ulong heap_limit;
-#endif
+
     abi_ulong stack_base;
     int used; /* non zero if used */
     struct image_info *info;
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 95727a816a..54abf273dd 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8119,8 +8119,9 @@ static int open_self_maps_1(CPUArchState *cpu_env, int fd, bool smaps)
         MapInfo *e = (MapInfo *) s->data;

         if (h2g_valid(e->start)) {
-            unsigned long min = e->start;
-            unsigned long max = e->end;
+            /* show page granularity of guest in /proc/pid/maps */
+            unsigned long min = TARGET_PAGE_ALIGN(e->start);
+            unsigned long max = TARGET_PAGE_ALIGN(e->end);
             int flags = page_get_flags(h2g(min));
             const char *path;

@@ -8131,14 +8132,18 @@ static int open_self_maps_1(CPUArchState *cpu_env, int fd, bool smaps)
                 continue;
             }

+            path = e->path;
+
+            if (ts->heap_base && h2g(min) == ts->heap_base) {
+                path = "[heap]";
+            }
+
 #ifdef TARGET_HPPA
             if (h2g(max) == ts->info->stack_limit) {
 #else
             if (h2g(min) == ts->info->stack_limit) {
 #endif
                 path = "[stack]";
-            } else {
-                path = e->path;
             }

             count = dprintf(fd, TARGET_ABI_FMT_ptr "-" TARGET_ABI_FMT_ptr
--
2.41.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v5 2/3] linux-user: Optimize memory layout for static and dynamic executables
  2023-07-28 17:31 [PATCH v5 0/3] linux-user: Fix and optimize target memory layout Helge Deller
  2023-07-28 17:31 ` [PATCH v5 1/3] linux-user: Show heap address in /proc/pid/maps Helge Deller
@ 2023-07-28 17:31 ` Helge Deller
  2023-07-28 17:31 ` [PATCH v5 3/3] linux-user: Load pie executables at upper memory Helge Deller
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Helge Deller @ 2023-07-28 17:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent Vivier, Paolo Bonzini, Richard Henderson, Helge Deller

Reorganize the guest memory layout to get as much memory as possible for
heap for the guest application.

This patch optimizes the memory layout by loading pie executables
into lower memory and shared libs into higher memory (at
TASK_UNMAPPED_BASE). This leaves a bigger memory area usable for heap
space which will be located directly after the executable.
Up to now, pie executable and shared libs were loaded directly behind
each other in the area at TASK_UNMAPPED_BASE, which leaves very little
space for heap.

I tested this patchset with chroots of alpha, arm, armel, arm64, hppa, m68k,
mips64el, mipsel, powerpc, ppc64, ppc64el, s390x, sh4 and sparc64 on a x86-64
host, and with a static armhf binary (which fails to run without this patch).

This patch temporarily breaks the Thread Sanitizer (TSan) application
which expects specific boundary definitions for memory mappings on
different platforms [1], see commit aab613fb9597 ("linux-user: Update
TASK_UNMAPPED_BASE for aarch64") for aarch64. The follow-up patch fixes it
again.

[1] https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/tsan/rtl/tsan_platform.h

Signed-off-by: Helge Deller <deller@gmx.de>
---
 linux-user/elfload.c | 55 +++++++++++++-------------------------------
 linux-user/mmap.c    |  8 ++++---
 2 files changed, 21 insertions(+), 42 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 861ec07abc..47a118e430 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -3023,6 +3023,7 @@ static void load_elf_image(const char *image_name, int image_fd,
     abi_ulong load_addr, load_bias, loaddr, hiaddr, error;
     int i, retval, prot_exec;
     Error *err = NULL;
+    bool is_main_executable;

     /* First of all, some simple consistency checks */
     if (!elf_check_ident(ehdr)) {
@@ -3106,28 +3107,8 @@ static void load_elf_image(const char *image_name, int image_fd,
         }
     }

-    if (pinterp_name != NULL) {
-        /*
-         * This is the main executable.
-         *
-         * Reserve extra space for brk.
-         * We hold on to this space while placing the interpreter
-         * and the stack, lest they be placed immediately after
-         * the data segment and block allocation from the brk.
-         *
-         * 16MB is chosen as "large enough" without being so large as
-         * to allow the result to not fit with a 32-bit guest on a
-         * 32-bit host. However some 64 bit guests (e.g. s390x)
-         * attempt to place their heap further ahead and currently
-         * nothing stops them smashing into QEMUs address space.
-         */
-#if TARGET_LONG_BITS == 64
-        info->reserve_brk = 32 * MiB;
-#else
-        info->reserve_brk = 16 * MiB;
-#endif
-        hiaddr += info->reserve_brk;
-
+    is_main_executable = (pinterp_name != NULL);
+    if (is_main_executable) {
         if (ehdr->e_type == ET_EXEC) {
             /*
              * Make sure that the low address does not conflict with
@@ -3136,7 +3117,7 @@ static void load_elf_image(const char *image_name, int image_fd,
             probe_guest_base(image_name, loaddr, hiaddr);
         } else {
             /*
-             * The binary is dynamic, but we still need to
+             * The binary is dynamic (pie-executabe), but we still need to
              * select guest_base.  In this case we pass a size.
              */
             probe_guest_base(image_name, 0, hiaddr - loaddr);
@@ -3159,7 +3140,7 @@ static void load_elf_image(const char *image_name, int image_fd,
      */
     load_addr = target_mmap(loaddr, (size_t)hiaddr - loaddr + 1, PROT_NONE,
                             MAP_PRIVATE | MAP_ANON | MAP_NORESERVE |
-                            (ehdr->e_type == ET_EXEC ? MAP_FIXED : 0),
+                            (is_main_executable ? MAP_FIXED : 0),
                             -1, 0);
     if (load_addr == -1) {
         goto exit_mmap;
@@ -3194,7 +3175,8 @@ static void load_elf_image(const char *image_name, int image_fd,
     info->end_code = 0;
     info->start_data = -1;
     info->end_data = 0;
-    info->brk = 0;
+    /* possible start for brk is behind all sections of this ELF file. */
+    info->brk = TARGET_PAGE_ALIGN(hiaddr);
     info->elf_flags = ehdr->e_flags;

     prot_exec = PROT_EXEC;
@@ -3288,9 +3270,6 @@ static void load_elf_image(const char *image_name, int image_fd,
                     info->end_data = vaddr_ef;
                 }
             }
-            if (vaddr_em > info->brk) {
-                info->brk = vaddr_em;
-            }
 #ifdef TARGET_MIPS
         } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) {
             Mips_elf_abiflags_v0 abiflags;
@@ -3618,6 +3597,15 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)

     if (elf_interpreter) {
         load_elf_interp(elf_interpreter, &interp_info, bprm->buf);
+        /*
+	 * Use brk address of interpreter if it was loaded above the
+	 * executable and leaves less than 16 MB for heap.
+	 * This happens e.g. with static binaries on armhf.
+         */
+        if (interp_info.brk > info->brk &&
+            interp_info.load_bias - info->brk < 16 * MiB)  {
+            info->brk = interp_info.brk;
+        }

         /* If the program interpreter is one of these two, then assume
            an iBCS2 image.  Otherwise assume a native linux image.  */
@@ -3672,17 +3660,6 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
     bprm->core_dump = &elf_core_dump;
 #endif

-    /*
-     * If we reserved extra space for brk, release it now.
-     * The implementation of do_brk in syscalls.c expects to be able
-     * to mmap pages in this space.
-     */
-    if (info->reserve_brk) {
-        abi_ulong start_brk = HOST_PAGE_ALIGN(info->brk);
-        abi_ulong end_brk = HOST_PAGE_ALIGN(info->brk + info->reserve_brk);
-        target_munmap(start_brk, end_brk - start_brk);
-    }
-
     return 0;
 }

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index a5dfb56545..848d2fd4bb 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -299,14 +299,16 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last,
 #ifdef TARGET_AARCH64
 # define TASK_UNMAPPED_BASE  0x5500000000
 #else
-# define TASK_UNMAPPED_BASE  (1ul << 38)
+# define TASK_UNMAPPED_BASE  0x4000000000
 #endif
-#else
+#elif HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 32
 #ifdef TARGET_HPPA
 # define TASK_UNMAPPED_BASE  0xfa000000
 #else
-# define TASK_UNMAPPED_BASE  0x40000000
+# define TASK_UNMAPPED_BASE  0xe0000000
 #endif
+#else /* HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 32 */
+# define TASK_UNMAPPED_BASE  0x40000000
 #endif
 abi_ulong mmap_next_start = TASK_UNMAPPED_BASE;

--
2.41.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v5 3/3] linux-user: Load pie executables at upper memory
  2023-07-28 17:31 [PATCH v5 0/3] linux-user: Fix and optimize target memory layout Helge Deller
  2023-07-28 17:31 ` [PATCH v5 1/3] linux-user: Show heap address in /proc/pid/maps Helge Deller
  2023-07-28 17:31 ` [PATCH v5 2/3] linux-user: Optimize memory layout for static and dynamic executables Helge Deller
@ 2023-07-28 17:31 ` Helge Deller
  2023-07-31  8:30 ` [PATCH v5 0/3] linux-user: Fix and optimize target memory layout Michael Tokarev
  2023-07-31 10:08 ` Joel Stanley
  4 siblings, 0 replies; 6+ messages in thread
From: Helge Deller @ 2023-07-28 17:31 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent Vivier, Paolo Bonzini, Richard Henderson, Helge Deller

Fix the elf loader to calculate a valid TASK_UNMAPPED_BASE address for all
32-bit architectures, based on the GUEST_ADDR_MAX constant.

Additionally modify the elf loader to load dynamic pie executables at
around:
~ 0x5500000000  for 64-bit guest binaries on 64-bit host,
- 0x00300000    for 32-bit guest binaries on 64-bit host, and
- 0x00000000    for 32-bit guest binaries on 32-bit host.

With this patch the Thread Sanitizer (TSan) application will work again,
as in commit aab613fb9597 ("linux-user: Update TASK_UNMAPPED_BASE for
aarch64").

Signed-off-by: Helge Deller <deller@gmx.de>
---
 linux-user/elfload.c |  6 ++++--
 linux-user/loader.h  | 12 ++++++++++++
 linux-user/mmap.c    | 35 ++++++++++++++++++-----------------
 3 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 47a118e430..8f5a79b537 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -3021,6 +3021,7 @@ static void load_elf_image(const char *image_name, int image_fd,
     struct elfhdr *ehdr = (struct elfhdr *)bprm_buf;
     struct elf_phdr *phdr;
     abi_ulong load_addr, load_bias, loaddr, hiaddr, error;
+    unsigned long load_offset = 0;
     int i, retval, prot_exec;
     Error *err = NULL;
     bool is_main_executable;
@@ -3121,6 +3122,7 @@ static void load_elf_image(const char *image_name, int image_fd,
              * select guest_base.  In this case we pass a size.
              */
             probe_guest_base(image_name, 0, hiaddr - loaddr);
+            load_offset = TASK_UNMAPPED_BASE_PIE;
         }
     }

@@ -3138,7 +3140,7 @@ static void load_elf_image(const char *image_name, int image_fd,
      * In both cases, we will overwrite pages in this range with mappings
      * from the executable.
      */
-    load_addr = target_mmap(loaddr, (size_t)hiaddr - loaddr + 1, PROT_NONE,
+    load_addr = target_mmap(loaddr + load_offset, (size_t)hiaddr - loaddr + 1, PROT_NONE,
                             MAP_PRIVATE | MAP_ANON | MAP_NORESERVE |
                             (is_main_executable ? MAP_FIXED : 0),
                             -1, 0);
@@ -3176,7 +3178,7 @@ static void load_elf_image(const char *image_name, int image_fd,
     info->start_data = -1;
     info->end_data = 0;
     /* possible start for brk is behind all sections of this ELF file. */
-    info->brk = TARGET_PAGE_ALIGN(hiaddr);
+    info->brk = TARGET_PAGE_ALIGN(load_offset + hiaddr);
     info->elf_flags = ehdr->e_flags;

     prot_exec = PROT_EXEC;
diff --git a/linux-user/loader.h b/linux-user/loader.h
index 59cbeacf24..d0e4ac4c07 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -18,6 +18,18 @@
 #ifndef LINUX_USER_LOADER_H
 #define LINUX_USER_LOADER_H

+/* where to map binaries? */
+#if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64
+# define TASK_UNMAPPED_BASE_PIE 0x5500000000
+# define TASK_UNMAPPED_BASE	0x7000000000
+#elif HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 32
+# define TASK_UNMAPPED_BASE_PIE	0x00300000
+# define TASK_UNMAPPED_BASE	(GUEST_ADDR_MAX - 0xd000000 + 1)
+#else /* HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 32 */
+# define TASK_UNMAPPED_BASE_PIE	0x00000000
+# define TASK_UNMAPPED_BASE	0x40000000
+#endif
+
 /*
  * Read a good amount of data initially, to hopefully get all the
  * program headers loaded.
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 848d2fd4bb..59d52b93f9 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -23,6 +23,7 @@
 #include "user-internals.h"
 #include "user-mmap.h"
 #include "target_mman.h"
+#include "loader.h"

 static pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER;
 static __thread int mmap_lock_count;
@@ -295,23 +296,6 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last,
     return true;
 }

-#if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64
-#ifdef TARGET_AARCH64
-# define TASK_UNMAPPED_BASE  0x5500000000
-#else
-# define TASK_UNMAPPED_BASE  0x4000000000
-#endif
-#elif HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 32
-#ifdef TARGET_HPPA
-# define TASK_UNMAPPED_BASE  0xfa000000
-#else
-# define TASK_UNMAPPED_BASE  0xe0000000
-#endif
-#else /* HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 32 */
-# define TASK_UNMAPPED_BASE  0x40000000
-#endif
-abi_ulong mmap_next_start = TASK_UNMAPPED_BASE;
-
 unsigned long last_brk;

 /*
@@ -344,6 +328,23 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align)
     abi_ulong addr;
     int wrapped, repeat;

+    static abi_ulong mmap_next_start;
+
+    /* initialize mmap_next_start if necessary */
+    if (!mmap_next_start) {
+        mmap_next_start = TASK_UNMAPPED_BASE;
+
+        /* do sanity checks on guest memory layout */
+        if (mmap_next_start >= GUEST_ADDR_MAX) {
+            mmap_next_start = GUEST_ADDR_MAX - 0x1000000000 + 1;
+        }
+
+        if (TASK_UNMAPPED_BASE_PIE >= mmap_next_start) {
+            fprintf(stderr, "Memory too small for PIE executables.\n");
+            exit(EXIT_FAILURE);
+        }
+    }
+
     align = MAX(align, qemu_host_page_size);

     /* If 'start' == 0, then a default start address is used. */
--
2.41.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v5 0/3] linux-user: Fix and optimize target memory layout
  2023-07-28 17:31 [PATCH v5 0/3] linux-user: Fix and optimize target memory layout Helge Deller
                   ` (2 preceding siblings ...)
  2023-07-28 17:31 ` [PATCH v5 3/3] linux-user: Load pie executables at upper memory Helge Deller
@ 2023-07-31  8:30 ` Michael Tokarev
  2023-07-31 10:08 ` Joel Stanley
  4 siblings, 0 replies; 6+ messages in thread
From: Michael Tokarev @ 2023-07-31  8:30 UTC (permalink / raw)
  To: Helge Deller, qemu-devel; +Cc: Laurent Vivier, Paolo Bonzini, Richard Henderson

28.07.2023 20:31, Helge Deller wrote:

> NOTE:
> - this patch series is for qemu v8.1.0-rc ONLY.
> - do not apply on top of v8.0-stable series, which uses
>    a different search algorithm for free mmap memory
>    and thus will give incorrect memory layouts.

Hm. I included a previous version of this patchset in debian
qemu 8.0 package.  Wonder what should we do on 8.0 and on
debian..

/mjt


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v5 0/3] linux-user: Fix and optimize target memory layout
  2023-07-28 17:31 [PATCH v5 0/3] linux-user: Fix and optimize target memory layout Helge Deller
                   ` (3 preceding siblings ...)
  2023-07-31  8:30 ` [PATCH v5 0/3] linux-user: Fix and optimize target memory layout Michael Tokarev
@ 2023-07-31 10:08 ` Joel Stanley
  4 siblings, 0 replies; 6+ messages in thread
From: Joel Stanley @ 2023-07-31 10:08 UTC (permalink / raw)
  To: Helge Deller; +Cc: qemu-devel, Laurent Vivier, Paolo Bonzini, Richard Henderson

On Fri, 28 Jul 2023 at 18:58, Helge Deller <deller@gmx.de> wrote:
>
> While trying to fix a bug which prevents running a static
> armhf binary with linux-user, I noticed a whole bunch of
> memory layout issues on various platforms. Most noteably
> the free heap space was very limited in the current setup.
> A large heap is important for example, if you want to
> use qemu-user for building Linux packages where gcc requires
> lots of space (e.g. using qemu-user as buildd for debian
> packages).
>
> Those findings led to this patch series, which
> - fixes qemu-arm to run static armhf binaries

Applying this on top of master and trying to run a simple armhf binary
on a ppc64le host fails:

qemu$ ./build/qemu-arm -d guest_errors,page,strace ~/hello-armhf
host mmap_min_addr=0x10000
pgb_find_hole: base @ 10000 for 4294967296 bytes
pgb_static: base @ 10000 for 4294967295 bytes
pgb_reserved_va: base @ 0x10000 for 4294967296 bytes
Locating guest address space @ 0x10000
page layout changed following mmap
start    end      size     prot
00010000-00060000 00050000 ---
00060000-00066000 00006000 ---
ffff0000-00000000 00010000 r-x
page layout changed following mmap
start    end      size     prot
00010000-00060000 00050000 r-x
00060000-00066000 00006000 ---
ffff0000-00000000 00010000 r-x
page layout changed following mmap
start    end      size     prot
00010000-00060000 00050000 r-x
00060000-00064000 00004000 rw-
00064000-00066000 00002000 ---
ffff0000-00000000 00010000 r-x
page layout changed following mmap
start    end      size     prot
00010000-00060000 00050000 r-x
00060000-00064000 00004000 rw-
00064000-00066000 00002000 rw-
f3000000-f3810000 00810000 rw-
ffff0000-00000000 00010000 r-x
page layout changed following mmap
start    end      size     prot
00010000-00060000 00050000 r-x
00060000-00064000 00004000 rw-
00064000-00066000 00002000 rw-
f3000000-f3010000 00010000 ---
f3010000-f3811000 00801000 rw-
ffff0000-00000000 00010000 r-x
guest_base  0x10000
page layout changed following binary load
start    end      size     prot
00010000-00060000 00050000 r-x
00060000-00064000 00004000 rw-
00064000-00066000 00002000 rw-
f3000000-f3010000 00010000 ---
f3010000-f3810000 00800000 rw-
f3810000-f3811000 00001000 r-x
ffff0000-00000000 00010000 r-x
start_brk   0x00000000
end_code    0x0005f9c8
start_code  0x00010000
start_data  0x00060414
end_data    0x0006327c
start_stack 0xf380f420
brk         0x00066000
entry       0x00010341
argv_start  0xf380f424
env_start   0xf380f42c
auxv_start  0xf380f4a8
95718 brk(NULL) = 0x00066000
95718 brk(0x00066874) = 0x00066874
95718 set_tid_address(0x66068) = 95718
95718 set_robust_list(0x6606c,12) = -1 errno=38 (Function not implemented)
95718 Unknown syscall 398
95718 ugetrlimit(3,-209652764,328608,404128,401408,1) = 0
95718 readlinkat(AT_FDCWD,"/proc/self/exe",0xf380e390,4096) = 22
95718 getrandom(0x65940,4,1) = 4
95718 brk(NULL) = 0x00066874
95718 brk(0x00087874)page layout changed following mmap
start    end      size     prot
00010000-00060000 00050000 r-x
00060000-00064000 00004000 rw-
00064000-00066000 00002000 rw-
00070000-00090000 00020000 rw-
f3000000-f3010000 00010000 ---
f3010000-f3810000 00800000 rw-
f3810000-f3811000 00001000 r-x
ffff0000-00000000 00010000 r-x
 = 0x00087874
95718 brk(0x00088000) = 0x00088000
95718 mprotect(0x00060000,8192,PROT_READ) = 0
95718 statx(1,"",AT_EMPTY_PATH|AT_NO_AUTOMOUNT|AT_STATX_SYNC_AS_STAT,STATX_BASIC_STATS,0xf380f078)
= 0
95718 write(1,0x66b08,14) = -1 errno=14 (Bad address)
95718 exit_group(0)

A working arm binary by comparison:

qemu$ ./build/qemu-arm -d guest_errors,page,strace ~/hello
host mmap_min_addr=0x10000
pgb_find_hole: base @ 10000 for 4294967296 bytes
pgb_static: base @ 10000 for 4294967295 bytes
pgb_reserved_va: base @ 0x10000 for 4294967296 bytes
Locating guest address space @ 0x10000
page layout changed following mmap
start    end      size     prot
00010000-00090000 00080000 ---
00090000-0009b000 0000b000 ---
ffff0000-00000000 00010000 r-x
page layout changed following mmap
start    end      size     prot
00010000-00090000 00080000 r-x
00090000-0009b000 0000b000 ---
ffff0000-00000000 00010000 r-x
page layout changed following mmap
start    end      size     prot
00010000-00090000 00080000 r-x
00090000-000a0000 00010000 rw-
ffff0000-00000000 00010000 r-x
page layout changed following mmap
start    end      size     prot
00010000-00090000 00080000 r-x
00090000-000a0000 00010000 rw-
f3000000-f3810000 00810000 rw-
ffff0000-00000000 00010000 r-x
page layout changed following mmap
start    end      size     prot
00010000-00090000 00080000 r-x
00090000-000a0000 00010000 rw-
f3000000-f3010000 00010000 ---
f3010000-f3811000 00801000 rw-
ffff0000-00000000 00010000 r-x
guest_base  0x10000
page layout changed following binary load
start    end      size     prot
00010000-00090000 00080000 r-x
00090000-000a0000 00010000 rw-
f3000000-f3010000 00010000 ---
f3010000-f3810000 00800000 rw-
f3810000-f3811000 00001000 r-x
ffff0000-00000000 00010000 r-x
start_brk   0x00000000
end_code    0x00084f7c
start_code  0x00010000
start_data  0x00095098
end_data    0x00098394
start_stack 0xf380f430
brk         0x0009b000
entry       0x00010418
argv_start  0xf380f434
env_start   0xf380f43c
auxv_start  0xf380f4b8
95733 brk(NULL) = 0x0009b000
95733 brk(0x0009b8fc) = 0x0009b8fc
95733 set_tid_address(0x9b068) = 95733
95733 set_robust_list(0x9b070,12) = -1 errno=38 (Function not implemented)
95733 Unknown syscall 398
95733 uname(0xfffffffff380f270) = 0
95733 ugetrlimit(3,-209652756,469816,622616,618496,1) = 0
95733 readlink("/proc/self/exe",0xf380e380,4096) = 16
95733 getrandom(0x9ab10,4,1) = 4
95733 brk(0x000cb8fc)page layout changed following mmap
start    end      size     prot
00010000-00090000 00080000 r-x
00090000-000a0000 00010000 rw-
000a0000-000d0000 00030000 rw-
f3000000-f3010000 00010000 ---
f3010000-f3810000 00800000 rw-
f3810000-f3811000 00001000 r-x
ffff0000-00000000 00010000 r-x
 = 0x000cb8fc
95733 brk(0x000d0000) = 0x000d0000
95733 statx(1,"",AT_EMPTY_PATH|AT_NO_AUTOMOUNT|AT_STATX_SYNC_AS_STAT,STATX_BASIC_STATS,0xf380f0b8)
= 0
95733 write(1,0x9bb90,14)Hello, World!
 = 14
95733 exit_group(0)

The test program is:

#include <stdio.h>
int main() { printf("Hello, World!\n");}

Built like this:

arm-linux-gnueabihf-gcc -o hello-armhf hello.c -static

arm-linux-gnueabi-gcc -o hello hello.c -static

on an Ubuntu 23.04 host.

Cheers,

Joel


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-07-31 10:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-28 17:31 [PATCH v5 0/3] linux-user: Fix and optimize target memory layout Helge Deller
2023-07-28 17:31 ` [PATCH v5 1/3] linux-user: Show heap address in /proc/pid/maps Helge Deller
2023-07-28 17:31 ` [PATCH v5 2/3] linux-user: Optimize memory layout for static and dynamic executables Helge Deller
2023-07-28 17:31 ` [PATCH v5 3/3] linux-user: Load pie executables at upper memory Helge Deller
2023-07-31  8:30 ` [PATCH v5 0/3] linux-user: Fix and optimize target memory layout Michael Tokarev
2023-07-31 10:08 ` Joel Stanley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).