From patchwork Wed Aug 17 11:46:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 9285689 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 03CC860459 for ; Wed, 17 Aug 2016 11:54:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE5C72928D for ; Wed, 17 Aug 2016 11:54:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2B3D29290; Wed, 17 Aug 2016 11:54:19 +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=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F14AD2928C for ; Wed, 17 Aug 2016 11:54:18 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bZzOg-0004zp-QJ; Wed, 17 Aug 2016 11:52:38 +0000 Received: from mail-sn1nam02on0069.outbound.protection.outlook.com ([104.47.36.69] helo=NAM02-SN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bZzL0-0000ej-5x for linux-arm-kernel@lists.infradead.org; Wed, 17 Aug 2016 11:49:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-caviumnetworks-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=ukUlwu31dppePdg/CFu8p80wA+fuOaNkJWQSArMnz5E=; b=Ol0YykqI7A576dWpi9hJ+Z/xHdASaQhEASSbh4qrSm3lFS98rhcYWvuNaYYMJBoohb5Fzznb1M6JBB/iTNUuLE3iY27HGX2gd2COl4XWf/fp3zM1e/TFz771+lK9YXp7wxTmg2V4mGucNsDzw+pGoJvl2l1mo3uwUb6vQLiIVZ4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Yuri.Norov@caviumnetworks.com; Received: from localhost (95.143.213.121) by DM3PR07MB2252.namprd07.prod.outlook.com (10.164.33.150) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.549.15; Wed, 17 Aug 2016 11:48:24 +0000 From: Yury Norov To: , , , , , , Subject: [PATCH 10/18] arm64: ilp32: introduce binfmt_ilp32.c Date: Wed, 17 Aug 2016 14:46:35 +0300 Message-ID: <1471434403-25291-11-git-send-email-ynorov@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1471434403-25291-1-git-send-email-ynorov@caviumnetworks.com> References: <1471434403-25291-1-git-send-email-ynorov@caviumnetworks.com> MIME-Version: 1.0 X-Originating-IP: [95.143.213.121] X-ClientProxiedBy: AM3PR03CA037.eurprd03.prod.outlook.com (10.141.191.165) To DM3PR07MB2252.namprd07.prod.outlook.com (10.164.33.150) X-MS-Office365-Filtering-Correlation-Id: 0d5733b4-c753-4abd-b666-08d3c6946572 X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2252; 2:DylOJghLBen8Sb0atLojdOE77g4PXCWisXg/+drS2Tq4YtqwXQ8axK7Gl9+uzq9gGKkyK6mgtgGCPsQGXyO7KTikQ5mFdouJsK3SQarYSWmv4OCuyIltAml2a0QNoa+SwtAlKzG1JZ+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ostics: 1; DM3PR07MB2252; 31:dW9ikWLMRh1Ah+l9uB4/REFLTh+E9h3NjrcpGcoxavnnjt6d7puoppOy0u7J7AzokLJ/qajlmPxlOSGE/1HgNkSpKNhGicx6cvsvJ2ADkg4jcmnUjEkjIaFSP1hXrP9bjakshRRaJhaIXNs/zeGlD5WOVf9VAOU9bJiI1FUhXmmhZigM/AdtsVeD17zADnpuxypo3cq+yTQJxmaqpFVWmm2amqbJp2viP2MTPeZbBnA=; 20:HvahbzQxS0mLHyadjHDaZRPUy5Q4b5WQKzSjqbEo1xRxto/dAibDZxqvKEbdd+7650WZEPbMekCIPYQFANLsdxme/DKLVIZwkpO3Y1W9jRt6t84kMZRKsSfYa4+JiaQ2s7uH0v+TyDooTG+o682rTZKqnACiUTL4v241mhyKbJGKEXSg4ZE7/zVckQ02oZm/f+tDicP1z95+PoNPftbaUwTmVp0zh5RdZpIYbFap0l6IQy8dqlnbsGYgVOftInW9v5Cp7VqsKICkOtG+i7Ql18v1EqkIFw6vTsNTr/fshB3hFe8ZVw+sbeYf8l9Z3RDKxPD3YUmh67yZuQZgCRMEcmbPd8FlFkBV0fdEdbrmYdqb6WUXpr1CguZ1XhKeV+fKevK4XXwKAXHdycE3T0icxOnU2jHa3sJ7d/5bSR+KF/ONXmYk53KdcG4uQ6V0PEXzcmjZZ/eF0EeIdJS7nAsE1cm70O3S5ypMFlR7nQDAPsILCCOKo8F87uhpk9UCGp2uxp9RUk3TsO5+Jy3uWy+Ie6KJiefdemZle+srNlO9S/oRprB+JSget1OT6pbirMFvx+KCNweTsPd0xjKMXCtbPxoyxCoXaq2kKHcbaj2s4dw= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046); SRVR:DM3PR07MB2252; BCL:0; PCL:0; RULEID:; SRVR:DM3PR07MB2252; X-Microsoft-Exchange-Diagnostics: 1; DM3PR07MB2252; 4:dXouzTHozFTeZM3Zp5CejLdgiXebwFq8dIul5ug9RQHkvLuXuNpmEb+4axz4SA0bK4X0O4YevfwB9Erf4+Tejo8uUDda/WUmLm/mDH2eNuYR1xpu5QT7IeBk2RpMWWBbKHPBtDx41MhTp96mWTYgy62kCxT1j5BfHKNlBa8VJij9apdEmKIR/+pj0QjfHOuGVHqAF1L9r4ghQ79u/TgVI/hEl4Q7ObbPBHUQBoWO3ROVoH+Bvo+g/UGpWrrLOqpcGVHXaZ2qYTC04dfmnlf1ndaEhRVYlw02KpjEy5jD08UE1S0ULhUDwjbUHGTGD1CBiVnV9WtohLM79WCeYRY2yQMQs0VF2NqtAxsNd+uYiPGV83/lS+yyOhH+kL9h0PODLm3mjEHmwtk/C/ttPAbfNw== X-Forefront-PRVS: 0037FD6480 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(6069001)(7916002)(189002)(199003)(5001770100001)(4326007)(8676002)(68736007)(36756003)(19580395003)(229853001)(33646002)(2906002)(305945005)(66066001)(3846002)(2201001)(7846002)(7736002)(47776003)(81156014)(6116002)(101416001)(19580405001)(81166006)(97736004)(7416002)(42186005)(586003)(189998001)(50466002)(77096005)(48376002)(2950100001)(106356001)(105586002)(5003940100001)(76506005)(50226002)(92566002)(76176999)(50986999)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:DM3PR07MB2252; H:localhost; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: caviumnetworks.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM3PR07MB2252; 23:QMJrjyqopxVW2AXk0KgOgY7jH5jAmBMZJi5iYMKRa?= =?us-ascii?Q?kiex+K1A483zurH4DLukYIjqSqKdOU1j97lL/DhlffupAVNRAfE1eZBW7mZ3?= =?us-ascii?Q?ZDkstlgF5MTxrBFxu4Y7ZC0jrhLHmOOYwxDMxz6wbD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viumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2016 11:48:24.5064 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR07MB2252 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160817_044850_768743_3A8EE938 X-CRM114-Status: GOOD ( 11.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: szabolcs.nagy@arm.com, heiko.carstens@de.ibm.com, cmetcalf@ezchip.com, ynorov@caviumnetworks.com, philipp.tomsich@theobroma-systems.com, joseph@codesourcery.com, zhouchengming1@huawei.com, Prasun.Kapoor@caviumnetworks.com, agraf@suse.de, geert@linux-m68k.org, kilobyte@angband.pl, manuel.montezelo@gmail.com, pinskia@gmail.com, linyongting@huawei.com, klimov.linux@gmail.com, broonie@kernel.org, bamvor.zhangjian@huawei.com, maxim.kuvyrkov@linaro.org, Nathan_Lynch@mentor.com, schwidefsky@de.ibm.com, davem@davemloft.net, christoph.muellner@theobroma-systems.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP binfmt_ilp32.c is needed to handle ILP32 binaries Signed-off-by: Yury Norov --- arch/arm64/include/asm/elf.h | 6 +++ arch/arm64/kernel/Makefile | 1 + arch/arm64/kernel/binfmt_ilp32.c | 96 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 arch/arm64/kernel/binfmt_ilp32.c diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h index f259fe8..be29dde 100644 --- a/arch/arm64/include/asm/elf.h +++ b/arch/arm64/include/asm/elf.h @@ -175,10 +175,16 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm, #define COMPAT_ELF_ET_DYN_BASE (2 * TASK_SIZE_32 / 3) +#ifndef USE_AARCH64_GREG /* AArch32 registers. */ #define COMPAT_ELF_NGREG 18 typedef unsigned int compat_elf_greg_t; typedef compat_elf_greg_t compat_elf_gregset_t[COMPAT_ELF_NGREG]; +#else /* AArch64 registers for AARCH64/ILP32 */ +#define COMPAT_ELF_NGREG ELF_NGREG +#define compat_elf_greg_t elf_greg_t +#define compat_elf_gregset_t elf_gregset_t +#endif /* AArch32 EABI. */ #define EF_ARM_EABI_MASK 0xff000000 diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 949187c..9b6c324 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -27,6 +27,7 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE arm64-obj-$(CONFIG_AARCH32_EL0) += sys32.o kuser32.o signal32.o \ sys_compat.o entry32.o binfmt_elf32.o +arm64-obj-$(CONFIG_ARM64_ILP32) += binfmt_ilp32.o arm64-obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o entry-ftrace.o arm64-obj-$(CONFIG_MODULES) += arm64ksyms.o module.o arm64-obj-$(CONFIG_ARM64_MODULE_PLTS) += module-plts.o diff --git a/arch/arm64/kernel/binfmt_ilp32.c b/arch/arm64/kernel/binfmt_ilp32.c new file mode 100644 index 0000000..416b3f5 --- /dev/null +++ b/arch/arm64/kernel/binfmt_ilp32.c @@ -0,0 +1,96 @@ +/* + * Support for ILP32 Linux/aarch64 ELF binaries. + */ +#define USE_AARCH64_GREG + +#include +#include + +#undef ELF_CLASS +#define ELF_CLASS ELFCLASS32 + +#undef elfhdr +#undef elf_phdr +#undef elf_shdr +#undef elf_note +#undef elf_addr_t +#define elfhdr elf32_hdr +#define elf_phdr elf32_phdr +#define elf_shdr elf32_shdr +#define elf_note elf32_note +#define elf_addr_t Elf32_Addr + +/* + * Some data types as stored in coredump. + */ +#define user_long_t compat_long_t +#define user_siginfo_t compat_siginfo_t +#define copy_siginfo_to_user copy_siginfo_to_user32 + +/* + * The machine-dependent core note format types are defined in elfcore-compat.h, + * which requires asm/elf.h to define compat_elf_gregset_t et al. + */ +#define elf_prstatus compat_elf_prstatus +#define elf_prpsinfo compat_elf_prpsinfo + +/* + * Compat version of cputime_to_compat_timeval, perhaps this + * should be an inline in . + */ +static void cputime_to_compat_timeval(const cputime_t cputime, + struct compat_timeval *value) +{ + struct timeval tv; + cputime_to_timeval(cputime, &tv); + value->tv_sec = tv.tv_sec; + value->tv_usec = tv.tv_usec; +} + +#undef cputime_to_timeval +#define cputime_to_timeval cputime_to_compat_timeval + +/* AARCH64 ILP32 EABI. */ +#undef elf_check_arch +#define elf_check_arch(x) (((x)->e_machine == EM_AARCH64) \ + && (x)->e_ident[EI_CLASS] == ELFCLASS32) + +#undef SET_PERSONALITY +#define SET_PERSONALITY(ex) \ +do { \ + set_thread_flag(TIF_32BIT_AARCH64); \ + clear_thread_flag(TIF_32BIT); \ +} while (0) + +#undef ARCH_DLINFO +#define ARCH_DLINFO \ +do { \ + NEW_AUX_ENT(AT_SYSINFO_EHDR, \ + (elf_addr_t)(long)current->mm->context.vdso); \ +} while (0) + +#undef ELF_PLATFORM +#ifdef __AARCH64EB__ +#define ELF_PLATFORM ("aarch64_be:ilp32") +#else +#define ELF_PLATFORM ("aarch64:ilp32") +#endif + +#undef ELF_ET_DYN_BASE +#define ELF_ET_DYN_BASE COMPAT_ELF_ET_DYN_BASE + +#undef ELF_HWCAP +#undef ELF_HWCAP2 +#define ELF_HWCAP ((u32) elf_hwcap) +#define ELF_HWCAP2 ((u32) (elf_hwcap >> 32)) + +/* + * Rename a few of the symbols that binfmt_elf.c will define. + * These are all local so the names don't really matter, but it + * might make some debugging less confusing not to duplicate them. + */ +#define elf_format compat_elf_format +#define init_elf_binfmt init_compat_elf_binfmt +#define exit_elf_binfmt exit_compat_elf_binfmt + +#include "../../../fs/binfmt_elf.c"