summaryrefslogtreecommitdiffstats
path: root/linux-user/elfload.c
Commit message (Collapse)AuthorAgeFilesLines
* linux-user/elfload: Implement ELF_HWCAP for RISC-VKito Cheng2021-07-071-0/+13
| | | | | | | | | Set I, M, A, F, D and C bit for hwcap if misa is set. Signed-off-by: Kito Cheng <kito.cheng@sifive.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20210706035015.122899-1-kito.cheng@sifive.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* Merge remote-tracking branch ↵Peter Maydell2021-06-221-1/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 'remotes/vivier2/tags/linux-user-for-6.1-pull-request' into staging Linux-user pull request 20210621 # gpg: Signature made Mon 21 Jun 2021 12:03:53 BST # gpg: using RSA key CD2F75DDC8E3A4DC2E4F5173F30C38BD3F2FBE3C # gpg: issuer "laurent@vivier.eu" # gpg: Good signature from "Laurent Vivier <lvivier@redhat.com>" [full] # gpg: aka "Laurent Vivier <laurent@vivier.eu>" [full] # gpg: aka "Laurent Vivier (Red Hat) <lvivier@redhat.com>" [full] # Primary key fingerprint: CD2F 75DD C8E3 A4DC 2E4F 5173 F30C 38BD 3F2F BE3C * remotes/vivier2/tags/linux-user-for-6.1-pull-request: linux-user: Use public sigev_notify_thread_id member if available linux-user: Fix incorrect use of feature-test-macros linux-user: Check for ieee128 fpbits in PPC64 HWCAP2 feature list tests/tcg/linux-test: Check that sigaction can query SIGKILL/SIGSTOP linux-user: Let sigaction query SIGKILL/SIGSTOP linux-user: Implement pivot_root linux-user/trace-events: fix minor typo in format string linux-user: Disable static assert involving __SIGRTMAX if it is missing linux-user: Set CF_PARALLEL when mapping shared memory Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
| * linux-user: Check for ieee128 fpbits in PPC64 HWCAP2 feature listKhem Raj2021-06-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | glibc 2.34 is now checking for this in hwcaps at runtime [1] and failing to run the binary if machine does not support 128bit IEEE fp Fixes Fatal glibc error: CPU lacks float128 support (POWER 9 or later required) [1] https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=d337345ce145e23c5f3a956f349d924fdf54ce2d;hp=eb24865637a271ab7dad13190330105eab0d478d Signed-off-by: Khem Raj <raj.khem@gmail.com> Cc: Florian Weimer <fweimer@redhat.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20210614191729.2981488-1-raj.khem@gmail.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* | linux-user: elf: s390x: Prepare for Vector enhancements facilityDavid Hildenbrand2021-06-211-0/+1
|/ | | | | | | | | | | Let's check for S390_FEAT_VECTOR_ENH and set HWCAP_S390_VXRS_EXT accordingly. Add all missing HWCAP defined in upstream Linux. Cc: Laurent Vivier <laurent@vivier.eu> Acked-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: David Hildenbrand <david@redhat.com> Message-Id: <20210608092337.12221-25-david@redhat.com> Signed-off-by: Cornelia Huck <cohuck@redhat.com>
* linux-user/aarch64: Enable hwcap bits for bfloat16Richard Henderson2021-06-031-0/+2
| | | | | | | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20210525225817.400336-12-richard.henderson@linaro.org Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* linux-user/aarch64: Enable hwcap bits for sve2 and related extensionsRichard Henderson2021-05-251-0/+10
| | | | | | | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20210525010358.152808-92-richard.henderson@linaro.org Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* linux-user/elfload: add s390x core dumping supportIlya Leoshkevich2021-05-181-0/+33
| | | | | | | | | | | | | | Provide the following definitions required by the common code: * ELF_NREG: with the value of sizeof(s390_regs) / sizeof(long). * target_elf_gregset_t: define it like all the other arches do. * elf_core_copy_regs(): similar to kernel's s390_regs_get(). * USE_ELF_CORE_DUMP. * ELF_EXEC_PAGESIZE. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Message-Id: <20210413205608.22587-1-iii@linux.ibm.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* linux-user/elfload: fix filling psinfo->pr_psargsIlya Leoshkevich2021-05-181-2/+3
| | | | | | | | | | | | | | | | The current code dumps the memory between arg_start and arg_end, which contains the argv pointers. This results in the Core was generated by `<garbage>` message when opening the core file in GDB. This is because the code is supposed to dump the actual arg strings. Fix by using arg_strings and env_strings instead of arg_start and arg_end. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Message-Id: <20210413205814.22821-1-iii@linux.ibm.com> [lv: add missing braces] Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* linux-user: use GDateTime for formatting timestamp for core fileDaniel P. Berrangé2021-05-181-27/+9Star
| | | | | | | | | | | | The GDateTime APIs provided by GLib avoid portability pitfalls, such as some platforms where 'struct timeval.tv_sec' field is still 'long' instead of 'time_t'. When combined with automatic cleanup, GDateTime often results in simpler code too. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20210505103702.521457-7-berrange@redhat.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* linux-user/sparc: Clean up init_threadRichard Henderson2021-05-151-28/+5Star
| | | | | | | | | | Share code between sparc32 and sparc64, removing a bit of pointless difference wrt psr/tstate. Use sizeof(abi_ulong) for allocating initial register window. Use TARGET_STACK_BIAS. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20210426025334.1168495-7-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* linux-user/aarch64: Enable hwcap for RND, BTI, and MTERichard Henderson2021-05-101-0/+13
| | | | | | | | | | | These three features are already enabled by TCG, but are missing their hwcap bits. Update HWCAP2 from linux v5.12. Cc: qemu-stable@nongnu.org (for 6.0.1) Buglink: https://bugs.launchpad.net/bugs/1926044 Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20210427214108.88503-1-richard.henderson@linaro.org Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* linux-user/elfload: fix address calculation in fallback scenarioVincent Fazio2021-03-131-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Previously, guest_loaddr was not taken into account when returning an address from pgb_find_hole when /proc/self/maps was unavailable which caused an improper guest_base address to be calculated. This could cause a SIGSEGV later in load_elf_image -> target_mmap for ET_EXEC type images since the mmap MAP_FIXED flag is specified which could clobber existing mappings at the address returnd by g2h(). mmap(0xd87000, 16846912, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE|0x100000, -1, 0) = 0xd87000 munmap(0xd87000, 16846912) = 0 write(2, "Locating guest address space @ 0"..., 40Locating guest address space @ 0xd87000) = 40 mmap(0x1187000, 16850944, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0x1187000 --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_ACCERR, si_addr=0x2188310} --- +++ killed by SIGSEGV +++ Now, pgd_find_hole accounts for guest_loaddr in this scenario. Fixes: ad592e37dfcc ("linux-user: provide fallback pgd_find_hole for bare chroots") Signed-off-by: Vincent Fazio <vfazio@gmail.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20210131061948.15990-1-vfazio@xes-inc.com> [lv: updated it to check if ret == -1] Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* linux-user/elfload: do not assume MAP_FIXED_NOREPLACE kernel supportVincent Fazio2021-03-131-2/+1Star
| | | | | | | | | | | | | | | | | Previously, pgd_find_hole_fallback assumed that if the build host's libc had MAP_FIXED_NOREPLACE defined that the address returned by mmap would match the requested address. This is not a safe assumption for Linux kernels prior to 4.17 Now, we always compare mmap's resultant address with the requested address and no longer short-circuit based on MAP_FIXED_NOREPLACE. Fixes: 2667e069e7b5 ("linux-user: don't use MAP_FIXED in pgd_find_hole_fallback") Signed-off-by: Vincent Fazio <vfazio@gmail.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20210131061930.14554-1-vfazio@xes-inc.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* linux-user/elfload: munmap proper address in pgd_find_hole_fallbackVincent Fazio2021-03-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | Previously, if the build host's libc did not define MAP_FIXED_NOREPLACE or if the running kernel didn't support that flag, it was possible for pgd_find_hole_fallback to munmap an incorrect address which could lead to SIGSEGV if the range happened to overlap with the mapped address of the QEMU binary. mmap(0x1000, 22261224, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0x7f889d331000 munmap(0x1000, 22261224) = 0 --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x84b817} --- ++ killed by SIGSEGV +++ Now, always munmap the address returned by mmap. Fixes: 2667e069e7b5 ("linux-user: don't use MAP_FIXED in pgd_find_hole_fallback") Signed-off-by: Vincent Fazio <vfazio@gmail.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20210131061849.12615-1-vfazio@xes-inc.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* Remove deprecated target tilegxThomas Huth2021-03-091-23/+0Star
| | | | | | | | | | | | | | | TILE-Gx was only implemented in linux-user mode, but support for this CPU was removed from the upstream Linux kernel in 2018, and it has also been dropped from glibc, so there is no new Linux development taking place with this architecture. For running the old binaries, users can simply use older versions of QEMU. Signed-off-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Acked-by: Richard Henderson <richard.henderson@linaro.org> Acked-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20210224183952.80463-1-thuth@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
* Hexagon (linux-user/hexagon) Linux user emulationTaylor Simpson2021-02-181-0/+16
| | | | | | | | | | | | Implementation of Linux user emulation for Hexagon Some common files modified in addition to new files in linux-user/hexagon Acked-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Taylor Simpson <tsimpson@quicinc.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <1612763186-18161-31-git-send-email-tsimpson@quicinc.com> [rth: Fix termbits.h on review by Laurent] Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
* linux-user: Use cpu_untagged_addr in access_ok; split out *_untaggedRichard Henderson2021-02-161-1/+1
| | | | | | | | | | | Provide both tagged and untagged versions of access_ok. In a few places use thread_cpu, as the user is several callees removed from do_syscall1. Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20210212184902.1251044-17-richard.henderson@linaro.org Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* exec: Use cpu_untagged_addr in g2h; split out g2h_untaggedRichard Henderson2021-02-161-6/+6
| | | | | | | | | | | | | | | | | | | | | | | Use g2h_untagged in contexts that have no cpu, e.g. the binary loaders that operate before the primary cpu is created. As a colollary, target_mmap and friends must use untagged addresses, since they are used by the loaders. Use g2h_untagged on values returned from target_mmap, as the kernel never applies a tag itself. Use g2h_untagged on all pc values. The only current user of tags, aarch64, removes tags from code addresses upon branch, so "pc" is always untagged. Use g2h with the cpu context on hand wherever possible. Use g2h_untagged in lock_user, which will be updated soon. Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20210212184902.1251044-13-richard.henderson@linaro.org Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* exec: Use uintptr_t for guest_baseRichard Henderson2021-02-161-2/+2
| | | | | | | | | | | This is more descriptive than 'unsigned long'. No functional change, since these match on all linux+bsd hosts. Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-id: 20210212184902.1251044-4-richard.henderson@linaro.org Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* linux-user: Fix loading of BSS segmentsGiuseppe Musacchio2021-02-131-10/+20
| | | | | | | | | | | | | | | | | | | | | | | Some ELF binaries encode the .bss section as an extension of the data ones by setting the segment p_memsz > p_filesz. Some other binaries take a different route and encode it as a stand-alone PT_LOAD segment with p_filesz = 0 and p_memsz > 0. Both the encodings are actually correct per ELF specification but the ELF loader had some troubles in handling the former: with the old logic it was very likely to get Qemu to crash in zero_bss when trying to access unmapped memory. zero_bss isn't meant to allocate whole zero-filled segments but to "complete" a previously mapped segment with the needed zero bits. The fix is pretty simple, if the segment is completely zero-filled we simply allocate one or more pages (according to p_memsz) and avoid calling zero_bss altogether. Signed-off-by: Giuseppe Musacchio <thatlemon@gmail.com> Message-Id: <c9106487-dc4d-120a-bd48-665b3c617287@gmail.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* linux-user: Add support for MIPS Loongson 2F/3APhilippe Mathieu-Daudé2020-12-171-0/+2
| | | | | | | | | | | | | | | Userland ELF binaries using Loongson SIMD instructions have the HWCAP_LOONGSON_MMI bit set [1]. Binaries compiled for Loongson 3A [2] have the HWCAP_LOONGSON_EXT bit set for the LQ / SQ instructions. [1] commit 8e2d5831e4b ("target/mips: Legalize Loongson insn flags") [2] commit af868995e1b ("target/mips: Add Loongson-3 CPU definition") Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <20201214003215.344522-7-f4bug@amsat.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* linux-user/elfload: Update HWCAP bits from linux 5.7Philippe Mathieu-Daudé2020-12-171-0/+13
| | | | | | | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <20201214003215.344522-6-f4bug@amsat.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* linux-user/elfload: Introduce MIPS GET_FEATURE_REG_EQU() macroPhilippe Mathieu-Daudé2020-12-171-1/+11
| | | | | | | | | | | | | | | ISA features are usually denoted in read-only bits from CPU registers. Add the GET_FEATURE_REG_EQU() macro which checks if a CPU register has bits set to a specific value. Use the macro to check the 'Architecture Revision' level of the Config0 register, which is '2' when the Release 6 ISA is implemented. Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <20201214003215.344522-5-f4bug@amsat.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* linux-user/elfload: Introduce MIPS GET_FEATURE_REG_SET() macroPhilippe Mathieu-Daudé2020-12-171-1/+5
| | | | | | | | | | | | | | ISA features are usually denoted in read-only bits from CPU registers. Add the GET_FEATURE_REG_SET() macro which checks if a CPU register has bits set. Use the macro to check for MSA (which sets the MSAP bit of the Config3 register when the ASE implementation is present). Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <20201214003215.344522-4-f4bug@amsat.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* linux-user/elfload: Rename MIPS GET_FEATURE() as GET_FEATURE_INSN()Philippe Mathieu-Daudé2020-12-171-4/+4
| | | | | | | | | | | We want to add macros similar to GET_FEATURE(). As this one use the 'insn_flags' field, rename it GET_FEATURE_INSN(). Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <20201214003215.344522-3-f4bug@amsat.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* linux-user/elfload: Move GET_FEATURE macro out of get_elf_hwcap() bodyPhilippe Mathieu-Daudé2020-12-171-5/+5
| | | | | | | | | As we are going to add more macros, keep the function body clear. Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <20201214003215.344522-2-f4bug@amsat.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* linux-user: Check copy_from_user() return value in vma_dump_size()Peter Maydell2020-11-041-1/+3
| | | | | | | | | | | | | | Coverity points out that we don't check the return value from copy_from_user() in vma_dump_size(). This is to some extent a "can't happen" error since we've already checked the page with an access_ok() call earlier, but it's simple enough to handle the error anyway. Fixes: Coverity CID 1432362 Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20201103141532.19912-1-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* linux-user: Use "!= 0" when checking if MAP_FIXED_NOREPLACE is non-zeroPeter Maydell2020-11-041-1/+2
| | | | | | | | | | | | | | | | | | | In pgd_find_hole_fallback(), Coverity doesn't like the use of "if (MAP_FIXED_NOREPLACE || ...)" because it's using a logical operator on a constant other than 0 or 1 and its heuristic thinks we might have intended a bitwise operator instead. The logic is correct (we are checking whether the host really has a MAP_FIXED_NOREPLACE or whether we fell back to the "#define as 0 to ignore" from osdep.h); make Coverity happier by explicitly writing out the comparison with zero. Fixes: Coverity CID 1431059 Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <20201103142636.21125-1-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* linux-user/elfload: Parse GNU_PROPERTY_AARCH64_FEATURE_1_ANDRichard Henderson2020-10-271-2/+46
| | | | | | | | | Use the new generic support for NT_GNU_PROPERTY_TYPE_0. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20201021173749.111103-12-richard.henderson@linaro.org Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notesRichard Henderson2020-10-271-0/+157
| | | | | | | | | This is generic support, with the code disabled for all targets. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20201021173749.111103-11-richard.henderson@linaro.org Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* linux-user/elfload: Use Error for load_elf_interpRichard Henderson2020-10-271-7/+8
| | | | | | | | | | | This is slightly clearer than just using strerror, though the different forms produced by error_setg_file_open and error_setg_errno isn't entirely convenient. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20201021173749.111103-10-richard.henderson@linaro.org Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* linux-user/elfload: Use Error for load_elf_imageRichard Henderson2020-10-271-17/+20
| | | | | | | | | | This is a bit clearer than open-coding some of this with a bare c string. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20201021173749.111103-9-richard.henderson@linaro.org Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* linux-user/elfload: Move PT_INTERP detection to first loopRichard Henderson2020-10-271-29/+31
| | | | | | | | | | For BTI, we need to know if the executable is static or dynamic, which means looking for PT_INTERP earlier. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20201021173749.111103-8-richard.henderson@linaro.org Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* linux-user/elfload: Adjust iteration over phdrRichard Henderson2020-10-271-4/+5
| | | | | | | | | | | The second loop uses a loop induction variable, and the first does not. Transform the first to match the second, to simplify a following patch moving code between them. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20201021173749.111103-7-richard.henderson@linaro.org Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* linux-user/elfload: Fix coding style in load_elf_imageRichard Henderson2020-10-271-3/+9
| | | | | | | | | Fixing this now will clarify following patches. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20201021173749.111103-6-richard.henderson@linaro.org Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* linux-user/elfload: Avoid leaking interp_name using GLib memory APIPhilippe Mathieu-Daudé2020-10-271-4/+4
| | | | | | | | | | | | | Fix an unlikely memory leak in load_elf_image(). Fixes: bf858897b7 ("linux-user: Re-use load_elf_image for the main binary.") Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20201021173749.111103-5-richard.henderson@linaro.org Message-Id: <20201003174944.1972444-1-f4bug@amsat.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* linux-user: test, don't assert addr != test in pgb_reserved_vaAlex Bennée2020-09-161-5/+4Star
| | | | | | | | | | | | | | | | On older kernels which don't implement MAP_FIXED_NOREPLACE the kernel may still fail to give us the address we asked for despite having already probed the map for a valid hole. Asserting isn't particularly useful to the user so let us move the check up and expand the error_report a little to give them a fighting chance of working around the problem. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Cc: Bug 1895080 <1895080@bugs.launchpad.net> Ameliorates: ee94743034 Message-Id: <20200915134317.11110-2-alex.bennee@linaro.org>
* linux-user: Correctly start brk after executableTimothy E Baldwin2020-09-051-4/+3Star
| | | | | | | | | | | | | info->brk was erroneously set to the end of highest addressed writable segment which could result it in overlapping the executable. As per load_elf_binary in fs/binfmt_elf.c in Linux, it should be set to end of highest addressed segment. Signed-off-by: Timothy E Baldwin <T.E.Baldwin99@members.leeds.ac.uk> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20200728224615.326675-1-T.E.Baldwin99@members.leeds.ac.uk> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* target/microblaze: Split out MSR[C] to its own variableRichard Henderson2020-09-011-1/+1
| | | | | | | | | | Having the MSR[C] bit separate will improve arithmetic that operates on the carry bit. Having mb_cpu_read_msr() populate MSR[CC] will prevent the carry copy not matching the carry bit. Tested-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
* target/microblaze: Split out EDR from env->sregsRichard Henderson2020-09-011-3/+6
| | | | | | | | | Finish eliminating the sregs array in favor of individual members. Does not correct the width of EDR, yet. Tested-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
* linux-user: detect mismatched ELF ABI in qemu-mips[n32][el]Carlo Marcelo Arenas Belón2020-08-271-0/+11
| | | | | | | | | | | | | | | | | | | | | | | MIPS provides 2 ILP32 ABIs, and therefore 4 possible qemu-mips binaries with 2 pairs using the same endianess and bitness. This could lead to an O32 image loading in the N32 binary or vice versa and in cryptic errors (if lucky that the CPU doesn't match the FPU used) like : qemu: Unexpected FPU mode (o32 ELF loaded to qemu-mipsn32[el]) ELF binary's NaN mode not supported by CPU (n32 -> qemu-mips[el]) Add an ABI check macro that could be used while checking the ELF header that relies in the ABI2 flag to identify n32 binaries and abort instead early with a more descriptive error : Invalid ELF image for this architecture Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20200823101703.18451-1-carenas@gmail.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* linux-user: don't use MAP_FIXED in pgd_find_hole_fallbackAlex Bennée2020-07-271-4/+6
| | | | | | | | | | | | | Plain MAP_FIXED has the undesirable behaviour of splatting exiting maps so we don't actually achieve what we want when looking for gaps. We should be using MAP_FIXED_NOREPLACE. As this isn't always available we need to potentially check the returned address to see if the kernel gave us what we asked for. Fixes: ad592e37dfc ("linux-user: provide fallback pgd_find_hole for bare chroots") Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20200724064509.331-9-alex.bennee@linaro.org>
* linux-user/elfload: use MAP_FIXED_NOREPLACE in pgb_reserved_vaAlex Bennée2020-07-111-3/+7
| | | | | | | | | | | | | Given we assert the requested address matches what we asked we should also make that clear in the mmap flags. Otherwise we see failures in the GitLab environment for some currently unknown but allowable reason. We use MAP_FIXED_NOREPLACE if we can so we don't just clobber an existing mapping. Also include the strerror string for a bit more info on failure. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20200701135652.1366-34-alex.bennee@linaro.org>
* linux-user: deal with address wrap for ARM_COMMPAGE on 32 bitAlex Bennée2020-06-081-14/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | We rely on the pointer to wrap when accessing the high address of the COMMPAGE so it lands somewhere reasonable. However on 32 bit hosts we cannot afford just to map the entire 4gb address range. The old mmap trial and error code handled this by just checking we could map both the guest_base and the computed COMMPAGE address. We can't just manipulate loadaddr to get what we want so we introduce an offset which pgb_find_hole can apply when looking for a gap for guest_base that ensures there is space left to map the COMMPAGE afterwards. This is arguably a little inefficient for the one 32 bit value (kuser_helper_version) we need to keep there given all the actual code entries are picked up during the translation phase. Fixes: ee94743034b Bug: https://bugs.launchpad.net/qemu/+bug/1880225 Cc: Bug 1880225 <1880225@bugs.launchpad.net> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Tested-by: Aleksandar Markovic <aleksandar.qemu.devel@gmail.com> Cc: Richard Henderson <richard.henderson@linaro.org> Cc: Peter Maydell <peter.maydell@linaro.org> Message-Id: <20200605154929.26910-13-alex.bennee@linaro.org>
* linux-user: provide fallback pgd_find_hole for bare chrootsAlex Bennée2020-06-081-0/+48
| | | | | | | | | | | | | | | | | | | When running QEMU out of a chroot environment we may not have access to /proc/self/maps. As there is no other "official" way to introspect our memory map we need to fall back to the original technique of repeatedly trying to mmap an address range until we find one that works. Fortunately it's not quite as ugly as the original code given we already re-factored the complications of dealing with the ARM_COMMPAGE. We do make an attempt to skip over brk() which is about the only concrete piece of information we have about the address map at this moment. Fixes: ee9474303 Reported-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20200605154929.26910-12-alex.bennee@linaro.org>
* linux-user: limit check to HOST_LONG_BITS < TARGET_ABI_BITSAlex Bennée2020-05-281-0/+2
| | | | | | | | | | | | | | | | | | | | | Newer clangs rightly spot that you can never exceed the full address space of 64 bit hosts with: linux-user/elfload.c:2076:41: error: result of comparison 'unsigned long' > 18446744073709551615 is always false [-Werror,-Wtautological-type-limit-compare] 4685 if ((guest_hiaddr - guest_base) > ~(uintptr_t)0) { 4686 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~ 4687 1 error generated. So lets limit the check to 32 bit hosts only. Fixes: ee94743034bf Reported-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20200525131823.715-8-thuth@redhat.com> [thuth: Use HOST_LONG_BITS < TARGET_ABI_BITS instead of HOST_LONG_BITS == 32] Signed-off-by: Thomas Huth <thuth@redhat.com>
* linux-user: completely re-write init_guest_spaceAlex Bennée2020-05-151-253/+250Star
| | | | | | | | | | | | | | | | | | | | | | | | | | | First we ensure all guest space initialisation logic comes through probe_guest_base once we understand the nature of the binary we are loading. The convoluted init_guest_space routine is removed and replaced with a number of pgb_* helpers which are called depending on what requirements we have when loading the binary. We first try to do what is requested by the host. Failing that we try and satisfy the guest requested base address. If all those options fail we fall back to finding a space in the memory map using our recently written read_self_maps() helper. There are some additional complications we try and take into account when looking for holes in the address space. We try not to go directly after the system brk() space so there is space for a little growth. We also don't want to have to use negative offsets which would result in slightly less efficient code on x86 when it's unable to use the segment offset register. Less mind-binding gotos and hopefully clearer logic throughout. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Acked-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20200513175134.19619-5-alex.bennee@linaro.org>
* linux-user: more debug for init_guest_spaceAlex Bennée2020-04-071-1/+7
| | | | | | | | | | | | Searching for memory space can cause problems so lets extend the CPU_LOG_PAGE output so you can watch init_guest_space fail to allocate memory. A more involved fix is actually required to make this function play nicely with the large guard pages the sanitiser likes to use. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20200403191150.863-5-alex.bennee@linaro.org>
* linux-user: Add AT_EXECFN auxvalLirong Yuan2020-03-201-1/+2
| | | | | | | | | This change adds the support for AT_EXECFN auxval. Signed-off-by: Lirong Yuan <yuanzi@google.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20200302193153.66415-1-yuanzi@google.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
* target/arm: Implement v8.4-RCPCPeter Maydell2020-02-281-0/+1
| | | | | | | | | | | | | | | | | The v8.4-RCPC extension implements some new instructions: * LDAPUR, LDAPURB, LDAPURH, LDAPRSB, LDAPRSH, LDAPRSW * STLUR, STLURB, STLURH These are all in a new subgroup of encodings that sits below the top-level "Loads and Stores" group in the Arm ARM. The STLUR* instructions have standard store-release semantics; the LDAPUR* have Load-AcquirePC semantics, but (as with LDAPR*) we choose to implement them as the slightly stronger Load-Acquire. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20200224172846.13053-4-peter.maydell@linaro.org