From patchwork Thu May 3 21:39:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 908313 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 40cT8Y4YNSz9s27 for ; Fri, 4 May 2018 07:40:28 +1000 (AEST) Received: from localhost ([::1]:59202 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fELxh-0004lD-RV for incoming@patchwork.ozlabs.org; Thu, 03 May 2018 17:40:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54821) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fELwo-0004jG-OF for qemu-devel@nongnu.org; Thu, 03 May 2018 17:39:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fELwk-00056a-Oe for qemu-devel@nongnu.org; Thu, 03 May 2018 17:39:30 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:57747) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fELwk-00054P-CN for qemu-devel@nongnu.org; Thu, 03 May 2018 17:39:26 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0LjsL3-1ecY9Y1bSr-00br4p; Thu, 03 May 2018 23:39:13 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Thu, 3 May 2018 23:39:00 +0200 Message-Id: <20180503213903.30335-4-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180503213903.30335-1-laurent@vivier.eu> References: <20180503213903.30335-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:yBA/G5LEImaQWJL6v6bSgbdgQvbfcu8KAOUOv62KmN7fTFQje+B hs11zmJmz3aKd6zUbZ2RUL9m2ijeWURzvwLhFd4OFWE+hTmpQ+eMqjN3uEUZfTb0xU+P3FJ qNPzH3J+ATMjTpBEQkITIHZfnKsfvncjB3C/0/S8tPqkHSZ4p2Fi1pdXoN3DL7teOP5uUfc lxybrN8TV4SsKVQn0KjiA== X-UI-Out-Filterresults: notjunk:1; V01:K0:FTohLbnJRhY=:HGIMddToXBYOKfL2FC3586 UsRqH0pJNiYWB0iDOsb7YvX6ZU+Cyna8YPGkS1CxyWq1+hurGmS2Oi6hNtptPEp23WQHCmBT0 fTzONOeXnh6itPo5QhkYLdv2ujHLXfFIStHqJgiS1Lt596lyzM3QDBi3aXlEWD2rdffpob+Wv XznZs1aNmcTT0AUgPYRqckXXiNU8YPVoPN5WO4yVGBGHG57Ykec7GlU6m+mKD9nwW0VDGG9XW 4J1CmwXXNNlPO/BFqZl1xjJe1CrLSr2vH6W7t41Ng9NBLdvskvp67rX/XsVIg/8cFmpxKgQjX Rr+owldZF1vkMk74dIMs6WMyf5Ma24Xn69kKeeRhgRD0mrjC3jYFAZwJLWwex5o3l1e55U0P/ 4Ob9I+tWqkpVwpEHcDAS8YGTHWduJpnowN4I/nyAG9/9iyT5HQDzzA0WdUcnjZU4EYZcDWB9N iw7sjMc8BqXAfxxFth0FtZeTxrbpecrxvWpT6w7XXeqYodueUWadUK6fG1rlUg/GrKrJnF5xb nynOhu9y69VyhLDa3NjrKmocOkVxLt8iqMnAxCTkjHI3ZOhOjFE8wD6fJEMAqxBjjGGUwwyVO +RjtEqx6x6Y5J1oQEgs3LtYTl95U08q4gz1pCH5ILEfonwJemS1yTiLZr9G2HVba+XxILio1T oRK0Os0BjAQO/ihU7bYcDegq1DRx5HUP5N2xksBo3yLMlzxr+3PE5ShbdiO2FxBlJeyGhSRVZ h7QEsFUyCSJ767xd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.10 Subject: [Qemu-devel] [PULL 3/6] linux-user: ARM-FDPIC: Add support of FDPIC for ARM. 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: Christophe Lyon , Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Christophe Lyon Add FDPIC info into image_info structure since interpreter info is on stack and needs to be saved to be accessed later on. Co-Authored-By: Mickaël Guêné Signed-off-by: Christophe Lyon Reviewed-by: Peter Maydell Message-Id: <20180430080404.7323-4-christophe.lyon@st.com> Signed-off-by: Laurent Vivier --- linux-user/elfload.c | 29 +++++++++++++++++++++++++++++ linux-user/qemu.h | 9 +++++++++ 2 files changed, 38 insertions(+) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 76d7718b3d..36d52194bc 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -78,6 +78,11 @@ enum { */ #define personality(pers) (pers & PER_MASK) +int info_is_fdpic(struct image_info *info) +{ + return info->personality == PER_LINUX_FDPIC; +} + /* this flag is uneffective under linux too, should be deleted */ #ifndef MAP_DENYWRITE #define MAP_DENYWRITE 0 @@ -287,6 +292,25 @@ static inline void init_thread(struct target_pt_regs *regs, /* For uClinux PIC binaries. */ /* XXX: Linux does this only on ARM with no MMU (do we care ?) */ regs->uregs[10] = infop->start_data; + + /* Support ARM FDPIC. */ + if (info_is_fdpic(infop)) { + /* As described in the ABI document, r7 points to the loadmap info + * prepared by the kernel. If an interpreter is needed, r8 points + * to the interpreter loadmap and r9 points to the interpreter + * PT_DYNAMIC info. If no interpreter is needed, r8 is zero, and + * r9 points to the main program PT_DYNAMIC info. + */ + regs->uregs[7] = infop->loadmap_addr; + if (infop->interpreter_loadmap_addr) { + /* Executable is dynamically loaded. */ + regs->uregs[8] = infop->interpreter_loadmap_addr; + regs->uregs[9] = infop->interpreter_pt_dynamic_addr; + } else { + regs->uregs[8] = 0; + regs->uregs[9] = infop->pt_dynamic_addr; + } + } } #define ELF_NREG 18 @@ -1745,6 +1769,11 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, if (interp_info) { interp_info->other_info = info; sp = loader_build_fdpic_loadmap(interp_info, sp); + info->interpreter_loadmap_addr = interp_info->loadmap_addr; + info->interpreter_pt_dynamic_addr = interp_info->pt_dynamic_addr; + } else { + info->interpreter_loadmap_addr = 0; + info->interpreter_pt_dynamic_addr = 0; } } diff --git a/linux-user/qemu.h b/linux-user/qemu.h index da3b51724c..c55c8e294b 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -57,6 +57,8 @@ struct image_info { uint16_t nsegs; void *loadsegs; abi_ulong pt_dynamic_addr; + abi_ulong interpreter_loadmap_addr; + abi_ulong interpreter_pt_dynamic_addr; struct image_info *other_info; }; @@ -183,6 +185,13 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp, struct target_pt_regs * regs, struct image_info *infop, struct linux_binprm *); +/* Returns true if the image uses the FDPIC ABI. If this is the case, + * we have to provide some information (loadmap, pt_dynamic_info) such + * that the program can be relocated adequately. This is also useful + * when handling signals. + */ +int info_is_fdpic(struct image_info *info); + uint32_t get_elf_eflags(int fd); int load_elf_binary(struct linux_binprm *bprm, struct image_info *info); int load_flt_binary(struct linux_binprm *bprm, struct image_info *info);