qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Joel Stanley <joel@jms.id.au>
To: Helge Deller <deller@gmx.de>
Cc: qemu-devel@nongnu.org, Laurent Vivier <laurent@vivier.eu>,
	 Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <richard.henderson@linaro.org>
Subject: Re: [PATCH v5 0/3] linux-user: Fix and optimize target memory layout
Date: Mon, 31 Jul 2023 10:08:40 +0000	[thread overview]
Message-ID: <CACPK8XeyqcEDyyL3Jw2WYWs_gGdtTCf2=Ly04CMgkshSMdj7RA@mail.gmail.com> (raw)
In-Reply-To: <20230728173127.259192-1-deller@gmx.de>

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


      parent reply	other threads:[~2023-07-31 10:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACPK8XeyqcEDyyL3Jw2WYWs_gGdtTCf2=Ly04CMgkshSMdj7RA@mail.gmail.com' \
    --to=joel@jms.id.au \
    --cc=deller@gmx.de \
    --cc=laurent@vivier.eu \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).