From patchwork Mon Apr 30 08:03:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christophe Lyon X-Patchwork-Id: 134696 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp3483319lji; Mon, 30 Apr 2018 01:09:08 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoaZUUUPaiarb2HBTcuy71bMw3U3TkNB/d7m4ossG58ZWfvdQpg4Po8tfreZliwJadTvkme X-Received: by 10.55.190.1 with SMTP id o1mr10230032qkf.101.1525075748548; Mon, 30 Apr 2018 01:09:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525075748; cv=none; d=google.com; s=arc-20160816; b=FumimAEX7yhS//1/T9ebG2/j5Uz4YmTuYj/q2doa+MapDHjAtBxWfhEMsWFFi1VF4B J4zuVqWsarcvJIqNYnL50YCElik1gzV4DEjx5OlfiGw2Bv5ZqPcnkP5iGcL5CqhFI7RD h4N2D2iqi+ccBP/h/oBlUiTerFwLE+Y51pJ5em6rKxzH6uAutzOaNKkcnbNY/fB9+EOg k290WPffosz6rWmA/aJOXYs7iHGr8I1VfivFhPncpX1BysEXGNDe233AtYOBPisPAnTz n5Y0kn9skw3PIWuMXsdOKlD93FoYAip+qx+uyiB8R/jPQgymn0Yl6d5sN99OoTXR66cA je4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=xASpxjZRrCTYWSbqDOrskFNSDVrdtx0wQBzvvraHnG4=; b=kJRFT2qgnBm2wq3HmUZdsgDkD3drf8zCtS7uf4RCeFlko1UV/Wo+9KyV2jTos11Swv fe/oYJ8c4K2qr1KlIBQqao/Wr7QQ9R8uq3SmZ6tc20nngVmrQEjdOG+/AawYm9CxA6pf EOLIVZseIKSxG8IMB5aUhoLzgxZ37pKlMSSD2UQ7KqEc9jS7CwRZ7sdrQsQYCI6SuJ42 HjTz6rrLGsV5NK2bNK3hVz1k2No5F1yID2TZq9kPobKMYLoKpA1D44tjJPOQdPl45LpG EC7x6enLi+os6DXsKZlWFlQR/izlVa8bnAZ3HZafQhl1iWcWw+/xWeVWDTBRpH96rZWB ndRQ== 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 z207si3950058qkb.25.2018.04.30.01.09.08 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 30 Apr 2018 01:09:08 -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]:58276 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fD3rw-0005Vz-2n for patch@linaro.org; Mon, 30 Apr 2018 04:09:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47604) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fD3oH-0003Bt-1s for qemu-devel@nongnu.org; Mon, 30 Apr 2018 04:05:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fD3oF-0002f7-TD for qemu-devel@nongnu.org; Mon, 30 Apr 2018 04:05:20 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:37675 helo=mx07-00178001.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fD3oF-0002eu-Jq for qemu-devel@nongnu.org; Mon, 30 Apr 2018 04:05:19 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w3U84YlJ026214; Mon, 30 Apr 2018 10:05:15 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2hmfufytp0-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 30 Apr 2018 10:05:15 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 05DC131; Mon, 30 Apr 2018 08:05:15 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag5node1.st.com [10.75.127.13]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id E2EC12531; Mon, 30 Apr 2018 08:05:14 +0000 (GMT) Received: from gnb.st.com (10.75.127.46) by SFHDAG5NODE1.st.com (10.75.127.13) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Mon, 30 Apr 2018 10:05:14 +0200 From: Christophe Lyon To: , , , , Date: Mon, 30 Apr 2018 10:03:43 +0200 Message-ID: <20180430080404.7323-4-christophe.lyon@st.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20180430080404.7323-1-christophe.lyon@st.com> References: <20180430080404.7323-1-christophe.lyon@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG1NODE3.st.com (10.75.127.3) To SFHDAG5NODE1.st.com (10.75.127.13) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-04-30_03:, , signatures=0 X-MIME-Autoconverted: from 8bit to quoted-printable by mx08-.pphosted.com id w3U84YlJ026214 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 91.207.212.93 Subject: [Qemu-devel] [ARM/FDPIC v4 3/4] 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 -- 2.6.3 diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 76d7718..36d5219 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 da3b517..c55c8e2 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);