From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 763BF3857BAD for ; Tue, 24 May 2022 19:56:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 763BF3857BAD Received: by mail-pf1-x435.google.com with SMTP id j6so17322803pfe.13 for ; Tue, 24 May 2022 12:56:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=OVS95Whw9zt0k6MVjy1524nuBzzXmoMO5tPb59aI9Tc=; b=x07XtsPaKwr1EuKyGTMr+H+JO004FI9r+phgGS49KTMyAsSdcAuIWBsexEbb/vEIb9 rJiwDq4e6FbyAWXebXQj5UGYXTf0ydXx5bnMOEx7c9wmp3qrCXjT/0l4fZu85967Xa9I Z8/oHdwx7Ty7KEwvTD2J0TguQKsDdsDPBFv1ZWHmW5GxCrWWGfcz5DRdahHzbnAdGF6E yus++4Nat0PY/bv/JEXFM2HFqHsF2vd5kMQyNN0WwQUiHibT7lmpUDygymopu5gqpEUF WuIp6Aex5ex1+Ke6adZQjPz7hw+wf6wRa4POjNJBUJBftVqASPjaNzKMiVyumw5TfyTH d7cQ== X-Gm-Message-State: AOAM5300piLWWrctOuR4esUIk/XylQWraGeScjzaNp+WgBJ5/cJQHpPp TZ1NrREh/Zgml2/2FOCs0A63HTh2AL4CwA== X-Google-Smtp-Source: ABdhPJyVRESqDc30teGNCbtD27AlgcrMf/d06vj7cklA1CSpJBZS6Bb3ax0jaHShGr8uvGH+05uypg== X-Received: by 2002:a63:4c61:0:b0:3fa:267:5d60 with SMTP id m33-20020a634c61000000b003fa02675d60mr14244622pgl.202.1653422160325; Tue, 24 May 2022 12:56:00 -0700 (PDT) Received: from google.com ([2620:15c:2ce:200:a875:ceeb:f6fb:e7e2]) by smtp.gmail.com with ESMTPSA id t8-20020a17090340c800b00161ac982b9esm7557372pld.185.2022.05.24.12.55.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 May 2022 12:55:59 -0700 (PDT) Date: Tue, 24 May 2022 12:55:56 -0700 From: Fangrui Song To: caiyinyu@loongson.cn Cc: "libc-alpha@sourceware.org" , "xuchenghua@loongson.cn" , "joseph_myers@mentor.com" Subject: Re: =?utf-8?B?5Zue5aSN?= =?utf-8?Q?=3A?= [PATCH v4 04/13] LoongArch: ABI Implementation Message-ID: <20220524195556.xqthss5hkdcwan3t@google.com> References: <20220509023010.1250020-1-caiyinyu@loongson.cn> <20220509023010.1250020-5-caiyinyu@loongson.cn> <20220509075631.jkgi33z5fi5iwhzt@google.com> <628CAA45.0420B4.01722@loongson.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <628CAA45.0420B4.01722@loongson.cn> X-Spam-Status: No, score=-24.6 required=5.0 tests=BAYES_00, BODY_8BITS, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, KAM_INFOUSMEBIZ, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Tue, 24 May 2022 19:56:04 -0000 On 2022-05-24, caiyinyu@loongson.cn wrote: > > >从 Windows 版邮件发送 > >发件人: Fangrui Song >发送时间: 2022年5月9日 16:24 >收件人: caiyinyu >抄送: libc-alpha@sourceware.org; xuchenghua@loongson.cn; joseph_myers@mentor.com >主题: Re: [PATCH v4 04/13] LoongArch: ABI Implementation > >>+/* Runtime address of .got */ >>+#define _GLOBAL_OFFSET_TABLE_ \ >>+ ({ \ >>+ ElfW (Addr) * r; \ >>+ asm("la.pcrel %0, _GLOBAL_OFFSET_TABLE_" : "=r"(r)); \ >>+ r; \ >>+ }) >>+ >>+/* Return the link-time address of _DYNAMIC. */ >>+static inline ElfW (Addr) elf_machine_dynamic (void) >>+{ >>+ return _GLOBAL_OFFSET_TABLE_[0]; >>+} > >_GLOBAL_OFFSET_TABLE_[0] == link_time_dynamic is not recommended. >See >https://maskray.me/blog/2021-09-05-build-glibc-with-lld#global_offset_table_0 >aarch64/riscv/x86_64/etc have been updated to use the preferred >approach. > >Fixed. > > >diff --git a/sysdeps/loongarch/dl-machine.h b/sysdeps/loongarch/dl-machine.h >index f902410213..361f7555f9 100644 >--- a/sysdeps/loongarch/dl-machine.h >+++ b/sysdeps/loongarch/dl-machine.h >@@ -70,28 +70,18 @@ elf_machine_matches_host (const ElfW (Ehdr) * ehdr) > return 1; > } > >-/* Runtime address of .got */ >-#define _GLOBAL_OFFSET_TABLE_ \ >- ({ \ >- ElfW (Addr) * r; \ >- asm("la.pcrel %0, _GLOBAL_OFFSET_TABLE_" : "=r"(r)); \ >- r; \ >- }) >- >-/* Return the link-time address of _DYNAMIC. */ >-static inline ElfW (Addr) elf_machine_dynamic (void) >+/* Return the run-time load address of the shared object. */ >+static inline ElfW (Addr) elf_machine_load_address (void) > { >- return _GLOBAL_OFFSET_TABLE_[0]; >+ extern const ElfW(Ehdr) __ehdr_start attribute_hidden; >+ return (ElfW(Addr)) &__ehdr_start; > } > >-/* Return the run-time load address of the shared object. */ >-static inline ElfW (Addr) elf_machine_load_address (void) >+/* Return the link-time address of _DYNAMIC. */ >+static inline ElfW (Addr) elf_machine_dynamic (void) > { >- ElfW (Addr) got_linktime_addr; >- asm("la.got %0, _GLOBAL_OFFSET_TABLE_" >- /* Link-time address in GOT entry before runtime relocation */ >- : "=r"(got_linktime_addr)); >- return (ElfW (Addr)) _GLOBAL_OFFSET_TABLE_ - got_linktime_addr; >+ extern ElfW(Dyn) _DYNAMIC[] attribute_hidden; >+ return (ElfW(Addr)) _DYNAMIC - elf_machine_load_address (); > } Thank you. The updated elf_machine_load_address and elf_machine_dynamic look good.