From patchwork Tue Dec 18 21:04:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vineet Gupta X-Patchwork-Id: 1015611 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=synopsys.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="cS/e6lMA"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=synopsys.com header.i=@synopsys.com header.b="AfA56XNx"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43K9XQ70gWz9sBn for ; Wed, 19 Dec 2018 08:05:26 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MJJbSTl5CGQ0SVbWCJU7eQo5f5XMNxvy5RRlhtaAwi8=; b=cS/e6lMAuUlctj qRDm6fcTV3nnBfH8m1YoCzG5qXL3ODhb3u9PMn2SEolxFO2Q5HyQiE7iAtODjbWZk0SdlePEWBKgi 5YASGOpAenK3JiImH6gN5gwXgRrOj3OmT8JxIfKTHtNUJKYIe3jrdeEMQuuNVYEPU4sVf58oPZKMn UhJ4swbLlHxpLBvkekuk1ZnqYu0hK+5tfKv+G2VFtAxtgwerXzfZ49YRn8tq/3xy6Eea39Z+A3CFl uf0JVMZ52dQ1hB5O67JmoEI7UZehJmEeefhcea64HDLgfJH3RPFB1TQjHy09dZV9Zctwb2VRon2Zw ZJ232VEpVuFf2CXsjNOQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gZMYN-0001cZ-QX; Tue, 18 Dec 2018 21:05:23 +0000 Received: from smtprelay.synopsys.com ([198.182.60.111]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gZMYH-0001V4-Le for linux-snps-arc@lists.infradead.org; Tue, 18 Dec 2018 21:05:21 +0000 Received: from mailhost.synopsys.com (mailhost2.synopsys.com [10.13.184.66]) by smtprelay.synopsys.com (Postfix) with ESMTP id E393C10C1DB2; Tue, 18 Dec 2018 13:05:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1545167112; bh=QmdRN4wXGBKMToVkn8EFs0dmJCIBZBFXewO2LcHESpM=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=AfA56XNxuSjvkc1IVajUoSvRgGZvxsIGKO+5+5CJmG+79FIno/9hy6EObaQkyM1K9 VP281B/gJIoqAW2OY8KDfs/hb8oveprhRSyNHDqIYO6fTnBniWyb9KqGU4Ji0Fkl44 iSW4WdYnNZnkcxE0Gf9ohspbYLWQFwWkYTngu3dfnPpkSFGl6ypm4XCxjZ6n5Sc2P2 NOd8PTKi7ZN36CmgQ5rBqIQgp1Lg+wjCza7z/x8zq2V69jb644fa4EI8A9k6KXpEiT tiFZZTLfEsnDcilxvOUV3yM0eAKEq586sPV7nj5RxYaekVddcNVVOIT1e83hiVD6/6 bfYaG7fcsz2OQ== Received: from US01WEHTC2.internal.synopsys.com (us01wehtc2.internal.synopsys.com [10.12.239.237]) by mailhost.synopsys.com (Postfix) with ESMTP id D8EF83A81; Tue, 18 Dec 2018 13:05:12 -0800 (PST) Received: from IN01WEHTCA.internal.synopsys.com (10.144.199.104) by US01WEHTC2.internal.synopsys.com (10.12.239.237) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 18 Dec 2018 13:05:12 -0800 Received: from IN01WEHTCB.internal.synopsys.com (10.144.199.105) by IN01WEHTCA.internal.synopsys.com (10.144.199.103) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 19 Dec 2018 02:35:11 +0530 Received: from vineetg-Latitude-E7450.internal.synopsys.com (10.10.161.70) by IN01WEHTCB.internal.synopsys.com (10.144.199.243) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 19 Dec 2018 02:35:11 +0530 From: Vineet Gupta To: Subject: [PATCH 10/21] ARC: Linux Startup and Dynamic Loading Date: Tue, 18 Dec 2018 13:04:32 -0800 Message-ID: <1545167083-16764-11-git-send-email-vgupta@synopsys.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545167083-16764-1-git-send-email-vgupta@synopsys.com> References: <1545167083-16764-1-git-send-email-vgupta@synopsys.com> MIME-Version: 1.0 X-Originating-IP: [10.10.161.70] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181218_130517_833180_56AD0FD0 X-CRM114-Status: GOOD ( 18.99 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [198.182.60.111 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vineet Gupta , linux-snps-arc@lists.infradead.org Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Signed-off-by: Vineet Gupta --- ChangeLog | 3 ++ sysdeps/unix/sysv/linux/arc/dl-static.c | 84 +++++++++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/arc/ldconfig.h | 25 ++++++++++ sysdeps/unix/sysv/linux/arc/ldsodefs.h | 32 +++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/arc/dl-static.c create mode 100644 sysdeps/unix/sysv/linux/arc/ldconfig.h create mode 100644 sysdeps/unix/sysv/linux/arc/ldsodefs.h diff --git a/ChangeLog b/ChangeLog index ca010c356597..f6ad5968d7de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -71,6 +71,9 @@ * sysdeps/unix/sysv/linux/arc/sys/user.h: New file. * sysdeps/unix/sysv/linux/arc/ucontext-macros.h: New file. * sysdeps/unix/sysv/linux/arc/ucontext_i.sym: New file. + * sysdeps/unix/sysv/linux/arc/dl-static.c: New file. + * sysdeps/unix/sysv/linux/arc/ldconfig.h: New file. + * sysdeps/unix/sysv/linux/arc/ldsodefs.h: New file. 2018-12-17 Joseph Myers diff --git a/sysdeps/unix/sysv/linux/arc/dl-static.c b/sysdeps/unix/sysv/linux/arc/dl-static.c new file mode 100644 index 000000000000..2683ee5e7e2a --- /dev/null +++ b/sysdeps/unix/sysv/linux/arc/dl-static.c @@ -0,0 +1,84 @@ +/* Variable initialization. ARC version. + Copyright (C) 2001-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include + +#ifdef SHARED + +void +_dl_var_init (void *array[]) +{ + /* It has to match "variables" below. */ + enum + { + DL_PAGESIZE = 0 + }; + + GLRO(dl_pagesize) = *((size_t *) array[DL_PAGESIZE]); +} + +#else + +static void *variables[] = +{ + &GLRO(dl_pagesize) +}; + +static void +_dl_unprotect_relro (struct link_map *l) +{ + ElfW(Addr) start = ((l->l_addr + l->l_relro_addr) + & ~(GLRO(dl_pagesize) - 1)); + ElfW(Addr) end = ((l->l_addr + l->l_relro_addr + l->l_relro_size) + & ~(GLRO(dl_pagesize) - 1)); + + if (start != end) + __mprotect ((void *) start, end - start, PROT_READ | PROT_WRITE); +} + +void +_dl_static_init (struct link_map *l) +{ + struct link_map *rtld_map = l; + struct r_scope_elem **scope; + const ElfW(Sym) *ref = NULL; + lookup_t loadbase; + void (*f) (void *[]); + size_t i; + + loadbase = _dl_lookup_symbol_x ("_dl_var_init", l, &ref, l->l_local_scope, + NULL, 0, 1, NULL); + + for (scope = l->l_local_scope; *scope != NULL; scope++) + for (i = 0; i < (*scope)->r_nlist; i++) + if ((*scope)->r_list[i] == loadbase) + { + rtld_map = (*scope)->r_list[i]; + break; + } + + if (ref != NULL) + { + f = (void (*) (void *[])) DL_SYMBOL_ADDRESS (loadbase, ref); + _dl_unprotect_relro (rtld_map); + f (variables); + _dl_protect_relro (rtld_map); + } +} + +#endif diff --git a/sysdeps/unix/sysv/linux/arc/ldconfig.h b/sysdeps/unix/sysv/linux/arc/ldconfig.h new file mode 100644 index 000000000000..c38ce20edaea --- /dev/null +++ b/sysdeps/unix/sysv/linux/arc/ldconfig.h @@ -0,0 +1,25 @@ +/* dynamic linker names for ARC + Copyright (C) 2001-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +#define SYSDEP_KNOWN_INTERPRETER_NAMES \ + { "/lib/ld-linux.so.2", FLAG_ELF_LIBC6 }, +#define SYSDEP_KNOWN_LIBRARY_NAMES \ + { "libc.so.6", FLAG_ELF_LIBC6 }, \ + { "libm.so.6", FLAG_ELF_LIBC6 }, diff --git a/sysdeps/unix/sysv/linux/arc/ldsodefs.h b/sysdeps/unix/sysv/linux/arc/ldsodefs.h new file mode 100644 index 000000000000..005c49a7b7cd --- /dev/null +++ b/sysdeps/unix/sysv/linux/arc/ldsodefs.h @@ -0,0 +1,32 @@ +/* Run-time dynamic linker data structures for loaded ELF shared objects. ARC + Copyright (C) 2001-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _LDSODEFS_H + +/* Get the real definitions. */ +#include_next + +/* Now define our stuff. */ + +/* We need special support to initialize DSO loaded for statically linked + binaries. */ +extern void _dl_static_init (struct link_map *map); +#undef DL_STATIC_INIT +#define DL_STATIC_INIT(map) _dl_static_init (map) + +#endif /* ldsodefs.h */