From patchwork Wed Oct 24 18:35:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 10654867 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 D2CD513B5 for ; Wed, 24 Oct 2018 18:36:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B62B92B0B9 for ; Wed, 24 Oct 2018 18:36:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3D962B15A; Wed, 24 Oct 2018 18:36:49 +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 242962B0B9 for ; Wed, 24 Oct 2018 18:36:49 +0000 (UTC) Received: from localhost ([::1]:49816 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFO1P-0004Va-CI for patchwork-qemu-devel@patchwork.kernel.org; Wed, 24 Oct 2018 14:36:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53563) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFO0H-0003sx-Kd for qemu-devel@nongnu.org; Wed, 24 Oct 2018 14:35:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFO0G-0004te-QR for qemu-devel@nongnu.org; Wed, 24 Oct 2018 14:35:37 -0400 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]:40296) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gFO0G-0004t4-I7 for qemu-devel@nongnu.org; Wed, 24 Oct 2018 14:35:36 -0400 Received: by mail-lj1-x244.google.com with SMTP id t22-v6so5729867lji.7 for ; Wed, 24 Oct 2018 11:35:36 -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=mmte2uNA1wkKeOUK+2pRl3mQP73Cb5jhkDrN5VBE628=; b=E58ArqIuKmGcYqSV9TM7sZP8zQs/FpcpBLvcQfG/nJuSbuXtLEU7jZs0acQtX3eMBV B3QtWHjZSkpxNSj5x7dkjDl/GLGLUy6EKOEDk8ZEiEb8MbJL5LQkD+QNiJXsrl5TJ0a1 RNN+J9+Jxw2XLWYcAN5rQwJI/oJViVUUHf7puyIZFbsRLbop0wuTkarOjKgmBivJoW7e kENRnh0wA+ueRq8qCF47ZEzoZFwEu+d0n6p7bQS+UaJq+iqLknMD9DSz02B+LknJgXrG HMa51uFSVGel/IENcg/SRFG/Bfw2fPVImNSfNGWvSIou2JHnqu9kQfL+N/reN0WnRLXh pMdg== 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=mmte2uNA1wkKeOUK+2pRl3mQP73Cb5jhkDrN5VBE628=; b=Tfyn7a0JBWCRYcG61WkH7onZQ3ybi1fNjfXn6k4tPabcu8lCUcHz8HICclK8B3A9Se WrvVzPbL4G31ugGFqXxbZGIpYPb5tWlyQn+OSQpH4JYs7cMX1C+tw7xVPHfQHe5LWfeg gUkri9sHPb53yIcgIEk28zzF6hmSinTYf/bDSmqN3JjJnkTjDdjuy4k1tZRe71BDHC/U QsKNkAOzvGJ8wOMM9gGX9TvFAlAXxXKWpL4qPbxZv9XBAWzESxlKQuqwgicpsE88ITpS nQzLu7igatx7hqhJxkQ1E2HT3h/6lAFwKvE7aK4O0PKYov/DbAKnRQLTMWiZAN4VdZJg dPEg== X-Gm-Message-State: AGRZ1gLgqqEKrDo6YK7rKX6N4GyaUBFQF7V1jpM3ntAM65Ee+XZj5cUP Ol8WP9qXbUqTnbxuYMSOgV1owNnC/wc= X-Google-Smtp-Source: AJdET5e4k4GfgmEdogpcqwW6tQkF3nj7yqQvbkd+m7v13uqRFBLiIjt5mjRrL0ffnD+/AnHxzF4acA== X-Received: by 2002:a2e:197:: with SMTP id f23-v6mr2516017lji.144.1540406134809; Wed, 24 Oct 2018 11:35:34 -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 b123-v6sm843107lfe.54.2018.10.24.11.35.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Oct 2018 11:35:33 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Wed, 24 Oct 2018 11:35:19 -0700 Message-Id: <20181024183519.27354-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::244 Subject: [Qemu-devel] [PATCH v2] 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 Reviewed-by: Laurent Vivier --- Changes v1->v2: - make sp adjustment unconditional linux-user/flatload.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux-user/flatload.c b/linux-user/flatload.c index 2eefe55e5000..0122ab3afe65 100644 --- a/linux-user/flatload.c +++ b/linux-user/flatload.c @@ -771,10 +771,10 @@ 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); + sp -= (sp - stack_len) & 15; sp = loader_build_argptr(bprm->envc, bprm->argc, sp, p, flat_argvp_envp_on_stack());