From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 6105D3856DDB for ; Fri, 15 Apr 2022 01:28:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6105D3856DDB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from [10.20.4.187] (unknown [10.20.4.187]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxusxWylhijskjAA--.45129S3; Fri, 15 Apr 2022 09:28:55 +0800 (CST) From: caiyinyu Subject: Re: [PATCH v2 10/14] LoongArch: Linux Startup and Dynamic Loading Code To: Adhemerval Zanella , libc-alpha@sourceware.org Cc: xuchenghua@loongson.cn, joseph_myers@mentor.com References: <20211231064455.1030051-1-caiyinyu@loongson.cn> <20211231064455.1030051-11-caiyinyu@loongson.cn> <3b630aac-4a2a-76a4-483f-3bbcef8297cf@linaro.org> Message-ID: <37174cb8-e4ce-1d68-1395-bfa1cd3b262b@loongson.cn> Date: Fri, 15 Apr 2022 09:28:54 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <3b630aac-4a2a-76a4-483f-3bbcef8297cf@linaro.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID: AQAAf9AxusxWylhijskjAA--.45129S3 X-Coremail-Antispam: 1UD129KBjvJXoWxZF45ZF1DWF1UWrWxtrWDurg_yoW7JFW7pF WUCF45GF48JF17Ga4Sgw13X3Zxtrn3tF90kFy3Kay7Arn2kr1fWanFkFy3CFyxA34fCr4j vFyUGasrCF4xJaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvv14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AKxV WxJr0_GcWle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2Wl Yx0E2Ix0cI8IcVAFwI0_Jw0_WrylYx0Ex4A2jsIE14v26r4j6F4UMcvjeVCFs4IE7xkEbV WUJVW8JwACjcxG0xvEwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc7I2V7IY0VAS07Al zVAYIcxG8wCY02Avz4vE-syl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr 1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE 14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7 IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUCVW8JwCI42IY6I8E 87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73Uj IFyTuYvjfU0pBTUUUUU X-CM-SenderInfo: 5fdl5xhq1xqz5rrqw2lrqou0/ X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, KAM_STOCKGEN, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Apr 2022 01:29:01 -0000 在 2022/1/4 下午10:27, Adhemerval Zanella 写道: > On 31/12/2021 03:44, caiyinyu wrote: >> This contains the Linux-specific code for loading programs on LoongArch. >> --- >> sysdeps/unix/sysv/linux/loongarch/dl-static.c | 80 +++++++++++++++++++ >> sysdeps/unix/sysv/linux/loongarch/ldsodefs.h | 33 ++++++++ >> 2 files changed, 113 insertions(+) >> create mode 100644 sysdeps/unix/sysv/linux/loongarch/dl-static.c >> create mode 100644 sysdeps/unix/sysv/linux/loongarch/ldsodefs.h >> >> diff --git a/sysdeps/unix/sysv/linux/loongarch/dl-static.c b/sysdeps/unix/sysv/linux/loongarch/dl-static.c >> new file mode 100644 >> index 0000000000..b9a7b2a61f >> --- /dev/null >> +++ b/sysdeps/unix/sysv/linux/loongarch/dl-static.c >> @@ -0,0 +1,80 @@ >> +/* dl_static_init for loongarch. >> + Copyright (C) 2021 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 > This file should not be required, Florian has refactored it to avoid this > boilerplate code (check bdc90abc48f0528588600df37eebdc04ce01b2f0 and > related commits). Removed and modified related code. > >> diff --git a/sysdeps/unix/sysv/linux/loongarch/ldsodefs.h b/sysdeps/unix/sysv/linux/loongarch/ldsodefs.h >> new file mode 100644 >> index 0000000000..680baf2edc >> --- /dev/null >> +++ b/sysdeps/unix/sysv/linux/loongarch/ldsodefs.h >> @@ -0,0 +1,33 @@ >> +/* Run-time dynamic linker data structures for loaded ELF shared objects. >> + Copyright (C) 2021 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 */ > Same as before. Removed.