From patchwork Wed Oct 24 02:38:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 10654037 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C097414BD for ; Wed, 24 Oct 2018 02:39:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A5412A2AF for ; Wed, 24 Oct 2018 02:39:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E1FA2A2CA; Wed, 24 Oct 2018 02:39:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,FROM_LOCAL_NOVOWEL,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E66C42A2AF for ; Wed, 24 Oct 2018 02:39:42 +0000 (UTC) Received: from localhost ([::1]:45304 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gF95B-0001ZR-Kr for patchwork-qemu-devel@patchwork.kernel.org; Tue, 23 Oct 2018 22:39:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51201) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gF94Q-0001I3-7W for qemu-devel@nongnu.org; Tue, 23 Oct 2018 22:38:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gF94N-00062n-0k for qemu-devel@nongnu.org; Tue, 23 Oct 2018 22:38:53 -0400 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]:46559) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gF94M-00060G-LO for qemu-devel@nongnu.org; Tue, 23 Oct 2018 22:38:50 -0400 Received: by mail-lj1-x243.google.com with SMTP id x3-v6so3254808lji.13 for ; Tue, 23 Oct 2018 19:38:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=sLrTsNBVoufW7tF0JwmVmbRFAJdWygbqK9GiWB9p0JM=; b=OYdS4MUZFux/dBOT9MqJixVMm/wMnTzBNJ9PfK05wSlsjRAkH2+OcmKrShjdKq3V/u Qbcj6D/98o2wY98djxjEIYo593ZTs0O0ObMx5PlzYqIz46S5uU1QQTZ6HVryy5Wa9x8e k3xEg91HfXsh7QTbRk2cOCneNHHNYcx6wBY6tXqshpJJR/s8yQXhNSTJrq6xjYp/Nlai F5iVp0PNm156AtOgSc8lJI2dS/T1vfKcs8rx5I5UUoXMgPpUAORlsb8kH5sN3Gj0WFkc e9XqxxUhAm0wvJejt8YcHH0m2VEPOaCFZ9DM9URkU3BpJNJAPs/YL9rVrRsS2a+AfFow UxaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=sLrTsNBVoufW7tF0JwmVmbRFAJdWygbqK9GiWB9p0JM=; b=jKB0jGzUe/Ilnvt2XJiUpjMy4ChytzEvr3OlRgXY+lYGNNM3t9goS6Mt/mYjdb+uHI JR4X/n+QwuM0aTx5mlRUaRYprvJ2JsYD7hBwITfq2OP7tBpf5OHLvW6TNtXaAxsPWun+ sOMf/BWjsgS7TTe0t9qjeL5HAaJPG9xzglLqGEELBWsu/9TB9NfKoRp1rAtwU5P8mNSj Rr5Wuf6t8seuMxlvnURFP92KfZtF7ZjpAUx2tVp3NyRHdK286E/abTaaGbWEWxUOCF9Q Zp5fqWQ/LWvKhQtlGzFtBvlFKjl6Q6iP8NSs+nOs0ZcDY4h/sW+s+GNkayMLirO4X/lv Q9ng== X-Gm-Message-State: AGRZ1gKohyO0uA8+slwvFAaYqo/UXz00/Jv7D1LiEdaUl1SEdJrGAMKQ 6ogSNLGRNT2VRm4mLyhfVxTFjFhc X-Google-Smtp-Source: AJdET5ewJ24Ilt53H1E987JbcA6Q4CwABf8nE+PQbxVvnRIjjEKicGEYpZ23/OMtKTB7M2BI4l3Vrw== X-Received: by 2002:a2e:574f:: with SMTP id r15-v6mr473903ljd.106.1540348725820; Tue, 23 Oct 2018 19:38:45 -0700 (PDT) Received: from octofox.cadence.com (jcmvbkbc-1-pt.tunnel.tserv24.sto1.ipv6.he.net. [2001:470:27:1fa::2]) by smtp.gmail.com with ESMTPSA id q2-v6sm465395lfc.67.2018.10.23.19.38.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Oct 2018 19:38:44 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Tue, 23 Oct 2018 19:38:31 -0700 Message-Id: <20181024023831.2529-1-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::243 Subject: [Qemu-devel] [PATCH] linux-user/flatload: fix initial stack pointer alignment X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Max Filippov , Laurent Vivier Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Stack pointer alignment code incorrectly adds stack_size to sp instead of subtracting it. It also does not take flat_argvp_envp_on_stack() into account when calculating stack_size. This results in initial stack pointer misalignment with certain set of command line arguments and environment variables and correct alignment for the same binary with a different set of arguments. This misalignment causes failures in the following tests in the testsuite of gcc built for xtensa uclinux: gcc.dg/torture/vshuf-v64qi.c gcc.dg/torture/vshuf-v8sf.c gcc.dg/torture/vshuf-v8si.c Signed-off-by: Max Filippov --- linux-user/flatload.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/linux-user/flatload.c b/linux-user/flatload.c index 2eefe55e5000..1893966b5b30 100644 --- a/linux-user/flatload.c +++ b/linux-user/flatload.c @@ -771,10 +771,12 @@ int load_flt_binary(struct linux_binprm *bprm, struct image_info *info) /* Enforce final stack alignment of 16 bytes. This is sufficient for all current targets, and excess alignment is harmless. */ stack_len = bprm->envc + bprm->argc + 2; - stack_len += 3; /* argc, arvg, argp */ + stack_len += flat_argvp_envp_on_stack() ? 2 : 0; /* arvg, argp */ + stack_len += 1; /* argc */ stack_len *= sizeof(abi_ulong); - if ((sp + stack_len) & 15) - sp -= 16 - ((sp + stack_len) & 15); + if ((sp - stack_len) & 15) { + sp -= ((sp - stack_len) & 15); + } sp = loader_build_argptr(bprm->envc, bprm->argc, sp, p, flat_argvp_envp_on_stack());