From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 19E75C433EF for ; Thu, 24 Mar 2022 08:30:31 +0000 (UTC) Received: from localhost ([::1]:46406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nXIrV-0001Lj-Rv for qemu-devel@archiver.kernel.org; Thu, 24 Mar 2022 04:30:29 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXIhy-0006Er-6i for qemu-devel@nongnu.org; Thu, 24 Mar 2022 04:20:38 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:51307) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nXIhw-0003TU-4H for qemu-devel@nongnu.org; Thu, 24 Mar 2022 04:20:37 -0400 Received: from quad ([82.142.12.150]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MwQCb-1oNTsn0nKf-00sNcl; Thu, 24 Mar 2022 09:20:20 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 01/10] linux-user: Fix syscall parameter handling for MIPS n32 Date: Thu, 24 Mar 2022 09:20:07 +0100 Message-Id: <20220324082016.3463521-2-laurent@vivier.eu> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220324082016.3463521-1-laurent@vivier.eu> References: <20220324082016.3463521-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding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laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Andreas=20K=20=2E=20H=C3=BCttel?= , Richard Henderson , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , WANG Xuerui Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: WANG Xuerui The MIPS n32 ABI is basically n64 with the address space (i.e. pointer width) shrinked to 32 bits. Meanwhile the current code treats it as o32-like based on TARGET_ABI_BITS, which causes problems with n32 syscalls utilizing 64-bit offsets, like pread64, affecting most (if not all) recently built n32 binaries. This partially solves issue #909 ("qemu-mipsn32(el) user mode emulator fails to execute any recently built n32 binaries"); with this change applied, the built qemu-mipsn32el is able to progress beyond the pread64, and finish _dl_start_user for the "getting ld.so load libc.so" case. The program later dies with SIGBUS, though, due to _dl_start_user not maintaining stack alignment after removing ld.so itself from argv, and qemu-user starting to enforce alignment recently, but that is orthogonal to the issue here; the more common case of chrooting is working, verified with my own-built Gentoo n32 sysroot. (Depending on the exact ISA used, one may have to explicitly specify QEMU_CPU, which is the case for my chroot.) Buglink: https://gitlab.com/qemu-project/qemu/-/issues/909 Signed-off-by: WANG Xuerui Cc: Laurent Vivier Cc: Philippe Mathieu-Daudé Cc: Jiaxun Yang Cc: Andreas K. Hüttel Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20220320052259.1610883-1-xen0n@gentoo.org> Signed-off-by: Laurent Vivier --- linux-user/user-internals.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux-user/user-internals.h b/linux-user/user-internals.h index a8fdd6933b23..ee152ccfaa8f 100644 --- a/linux-user/user-internals.h +++ b/linux-user/user-internals.h @@ -112,7 +112,7 @@ static inline int is_error(abi_long ret) return (abi_ulong)ret >= (abi_ulong)(-4096); } -#if TARGET_ABI_BITS == 32 +#if (TARGET_ABI_BITS == 32) && !defined(TARGET_ABI_MIPSN32) static inline uint64_t target_offset64(uint32_t word0, uint32_t word1) { #ifdef TARGET_WORDS_BIGENDIAN @@ -121,7 +121,7 @@ static inline uint64_t target_offset64(uint32_t word0, uint32_t word1) return ((uint64_t)word1 << 32) | word0; #endif } -#else /* TARGET_ABI_BITS == 32 */ +#else /* TARGET_ABI_BITS == 32 && !defined(TARGET_ABI_MIPSN32) */ static inline uint64_t target_offset64(uint64_t word0, uint64_t word1) { return word0; @@ -136,7 +136,7 @@ static inline int regpairs_aligned(void *cpu_env, int num) { return ((((CPUARMState *)cpu_env)->eabi) == 1) ; } -#elif defined(TARGET_MIPS) && (TARGET_ABI_BITS == 32) +#elif defined(TARGET_MIPS) && defined(TARGET_ABI_MIPSO32) static inline int regpairs_aligned(void *cpu_env, int num) { return 1; } #elif defined(TARGET_PPC) && !defined(TARGET_PPC64) /* -- 2.35.1