From patchwork Mon Jul 16 19:53:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 944581 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41TvJs0rcqz9s3x for ; Tue, 17 Jul 2018 05:55:07 +1000 (AEST) Received: from localhost ([::1]:53444 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ff9aK-0004i8-Es for incoming@patchwork.ozlabs.org; Mon, 16 Jul 2018 15:55:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ff9Zz-0004hc-4D for qemu-devel@nongnu.org; Mon, 16 Jul 2018 15:54:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ff9Zu-0008Ki-8X for qemu-devel@nongnu.org; Mon, 16 Jul 2018 15:54:43 -0400 Received: from mout.kundenserver.de ([212.227.126.133]:37104) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ff9Zt-0008KJ-T2 for qemu-devel@nongnu.org; Mon, 16 Jul 2018 15:54:38 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue004 [212.227.15.167]) with ESMTPSA (Nemesis) id 0MCMK5-1foBzU3p5t-009CqE; Mon, 16 Jul 2018 21:53:54 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Mon, 16 Jul 2018 21:53:49 +0200 Message-Id: <20180716195349.29959-1-laurent@vivier.eu> X-Mailer: git-send-email 2.17.1 X-Provags-ID: V03:K1:GrGQzdiUSL4ZS9yD677MdkPlRRd9BMhcJUIs/kcP6TIkcCxvaR4 R4A7doL+dazQzj7P7bfxhbk1mr5sZbUcI9lw2JsrS7VYSxmrIFR6Ks7US/+5h7bcva9a667 6H0DJzIcp2I6aTmF/pjgX4FH6xaE6M898Bif9wUrZwE8rfCP6/XSFZMqLiYVb+JwlgZj2jM dcYCZNq43UPQlhYzFwE/w== X-UI-Out-Filterresults: notjunk:1; V01:K0:Ui/yHqNNNq8=:L7yrT2rQljh79CfTa8aNRj kzHm+u3fCgcIZQETa06yfjbOO98vwEjN6GdFBl5qq6dvWVF0nb7DCoe+5g2/l4idm9Z5DRRVE /5u5UQzXebJ30TnemSep7Vcq0Ywy1BjlYPYiAErkLX3v2taEO53gc01ZvSwQAneN/Px0awFWu vkXtJgzas9jhEyZMWz3euae/+o2a7F86w9iCAWA6BpNzNj8Q/RlqBjVJHC+CT7BnATr7n1ioI 8IBORFxm2FXG2Prvkk8E2sF1TRhVi3oetWuMSj5N+6yRmoTh3jozU+yRao3SYa9cCMNEbiNtx OweIixL7qA6+UUSVzfRljCbqY93zPfaMPiWb6RI3kjbCYoHpqHpMahnIQw74k8h38gXctIqIM LLIRaFl1Qa54aiWH3XKZkec6df54J47TjrvyW1OUzzX1aMhPRCqvDrBWRp1x4SvwPsplTDWxe ZNInaiAYPrcssnzCvV2rC2qykqzzZHtMWebBiuER1zCe+0XSAymxvrKlL07ppVc3VBYmUziYv Aa6JOOXGKLUtHTyQizhU7+7LqM6jBNyRUfPc7dC0FZmN7P/S728aK24+9ux31glBCubUjcd56 O7a6EbQ6lgc1lBE1zw2+a4595yrcR3f03/9GbhTKcUD8oFH93qem5/RQx5QNXxGFOon5SrPkI kTDfU/oZChFnf+veJLFiq6YZgbUlgbKtX8WTCIm99y+4qUDQ+D//lCH1rkN3tOemIsUU= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.126.133 Subject: [Qemu-devel] [PATCH] linux-user: fix ELF load alignment error 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: Riku Voipio , Richard Henderson , Alexander Graf , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" When we try to use some targets on ppc64, it can happen the target doesn't support the host page size to align ELF load sections and fails with: ELF load command alignment not page-aligned Since commit a70daba3771 ("linux-user: Tell guest about big host page sizes") the host page size is used to align ELF sections, but this doesn't work if the alignment required by the load section is smaller than the host one. For these cases, we continue to use the TARGET_PAGE_SIZE instead of the host one. I have tested this change on ppc64, and it fixes qemu linux-user for: s390x, m68k, i386, arm, aarch64, hppa and I have tested it doesn't break the following targets: x86_64, mips64el, sh4 mips and mipsel abort, but I think for another reason. Signed-off-by: Laurent Vivier Reviewed-by: Richard Henderson --- linux-user/elfload.c | 10 +++++++++- linux-user/qemu.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 942a1b661f..3a42fbd89d 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1875,7 +1875,13 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, NEW_AUX_ENT(AT_PHDR, (abi_ulong)(info->load_addr + exec->e_phoff)); NEW_AUX_ENT(AT_PHENT, (abi_ulong)(sizeof (struct elf_phdr))); NEW_AUX_ENT(AT_PHNUM, (abi_ulong)(exec->e_phnum)); - NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(MAX(TARGET_PAGE_SIZE, getpagesize()))); + if ((info->alignment & ~qemu_host_page_mask) != 0) { + /* Target doesn't support host page size alignment */ + NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(TARGET_PAGE_SIZE)); + } else { + NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(MAX(TARGET_PAGE_SIZE, + qemu_host_page_size))); + } NEW_AUX_ENT(AT_BASE, (abi_ulong)(interp_info ? interp_info->load_addr : 0)); NEW_AUX_ENT(AT_FLAGS, (abi_ulong)0); NEW_AUX_ENT(AT_ENTRY, info->entry); @@ -2202,6 +2208,7 @@ static void load_elf_image(const char *image_name, int image_fd, /* Find the maximum size of the image and allocate an appropriate amount of memory to handle that. */ loaddr = -1, hiaddr = 0; + info->alignment |= 0; for (i = 0; i < ehdr->e_phnum; ++i) { if (phdr[i].p_type == PT_LOAD) { abi_ulong a = phdr[i].p_vaddr - phdr[i].p_offset; @@ -2213,6 +2220,7 @@ static void load_elf_image(const char *image_name, int image_fd, hiaddr = a; } ++info->nsegs; + info->alignment |= phdr[i].p_align; } } diff --git a/linux-user/qemu.h b/linux-user/qemu.h index bb85c81aa4..7b16a1cdea 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -51,6 +51,7 @@ struct image_info { abi_ulong file_string; uint32_t elf_flags; int personality; + abi_ulong alignment; /* The fields below are used in FDPIC mode. */ abi_ulong loadmap_addr;