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: 134924 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp87646lji; Thu, 3 May 2018 14:42:34 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoZQ/3i1f93LYID7sEkuiI+gg1Th7R64bwy2QXqn8phtOox/9a26lyye7PoXHkqFmUni1Pi X-Received: by 2002:ac8:18f9:: with SMTP id o54-v6mr22420026qtk.353.1525383754416; Thu, 03 May 2018 14:42:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525383754; cv=none; d=google.com; s=arc-20160816; b=NRptiyGeWw4p8yNy/ixhwtogWssW82HKye+w9FTz9dCHvrgbbzEJGi/81tCXcSb/L4 f9f4J3TkjDBFSCuQOO8mEXeKU5Oo66MdL5cMPZhRYg96yanmzCbG2bgi8npUFdN7cjn7 fxYujuxjbhG00iGl4r9NuQpbnPJh7z6VBLOjXtLgGukw/+xDIsPcQdGNoOqG0pPnxvS5 a5Y3KNcPoq+YHZ6lmPOb8qw4y1lI7myeeXQWuDh55MdKBAxpSAM/GcWnU5ZBT9g32jcn Ja6GPnyyMlUgAejum9I5O3C3YzyJvAAh6GSZgg71BypnK1rNGr7dmrm41mN/ZWqYqCR1 IxoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:arc-authentication-results; bh=WCtgnzb1ZaG5e46DDwna7TSO7aC1sO7jhW5HlBdj/ZU=; b=jmvNr8SGZZbYOM2QWngQQlmtiXj2M4YjA7A1W5A4ak0v80DAoTswIZWgnnZdLi5pGF rFISO6Wx3v9g3YsRM7b9ZlqgN9ovm7Os6ZR5aJWrqYtRoXXPiM6pmBtoZ+1f279aEmZM /jVh8qy1aP6mYbwOmwNvJH/5Pxf783u0GhPldPd+0sfBb4oR8cdP+0Uw+Vfo/UzNlL/2 ZyEjfImkxTmIiiTaIHzCdb/C9S3jHa5iSKyxOTsVbXJ5aN39Kq3RFbV9pd6OMFvqlv0w FYNGAFJmabQm0IaloUwnw94Y9qhdzswdkSq3XQGJnGdi1HQCAnfgr5jIoTGfHSTbljNu m+vw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id j9si6604400qke.0.2018.05.03.14.42.34 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 03 May 2018 14:42:34 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:59216 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fELzl-0007Rn-SC for patch@linaro.org; Thu, 03 May 2018 17:42:33 -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+patch=linaro.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(+) -- 2.14.3 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);