Message ID | 20230728173127.259192-1-deller@gmx.de (mailing list archive) |
---|---|
Headers | show |
Series | linux-user: Fix and optimize target memory layout | expand |
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
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