public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: <caiyinyu@loongson.cn>
To: Fangrui Song <maskray@google.com>
Cc: "libc-alpha@sourceware.org" <libc-alpha@sourceware.org>,
	 "xuchenghua@loongson.cn" <xuchenghua@loongson.cn>,
	 "joseph_myers@mentor.com" <joseph_myers@mentor.com>
Subject: 回复: [PATCH v4 04/13] LoongArch: ABI Implementation
Date: Tue, 24 May 2022 17:49:54 +0800	[thread overview]
Message-ID: <628CAA45.0420B4.01722@loongson.cn> (raw)
In-Reply-To: <20220509075631.jkgi33z5fi5iwhzt@google.com>



从 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 ();
 }





>


  reply	other threads:[~2022-05-24  9:50 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-09  2:29 [PATCH v4 00/13] GLIBC LoongArch PATCHES caiyinyu
2022-05-09  2:29 ` [PATCH v4 01/13] LoongArch: Update NEWS and README for the LoongArch port caiyinyu
2022-05-09  2:29 ` [PATCH v4 02/13] LoongArch: Add LoongArch entries to config.h.in caiyinyu
2022-05-09  2:30 ` [PATCH v4 03/13] LoongArch: Add relocations and ELF flags to elf.h and scripts/glibcelf.py caiyinyu
2022-05-09  2:30 ` [PATCH v4 04/13] LoongArch: ABI Implementation caiyinyu
2022-05-09  7:56   ` Fangrui Song
2022-05-24  9:49     ` caiyinyu [this message]
2022-05-24 19:55       ` 回复: " Fangrui Song
2022-05-09  8:20   ` Fangrui Song
2022-05-09 11:33     ` Adhemerval Zanella
2022-05-09 12:39   ` Adhemerval Zanella
2022-05-09 12:46     ` Florian Weimer
2022-05-29 13:10   ` Adhemerval Zanella
2022-05-09  2:30 ` [PATCH v4 05/13] LoongArch: Thread-Local Storage Support caiyinyu
2022-05-09  2:30 ` [PATCH v4 06/13] LoongArch: Generic <math.h> and soft-fp Routines caiyinyu
2022-05-09  2:30 ` [PATCH v4 07/13] LoongArch: Atomic and Locking Routines caiyinyu
2022-05-09  2:30 ` [PATCH v4 08/13] LoongArch: Linux Syscall Interface caiyinyu
2022-05-09  2:30 ` [PATCH v4 09/13] LoongArch: Linux ABI caiyinyu
2022-05-09  2:30 ` [PATCH v4 10/13] LoongArch: Add ABI Lists caiyinyu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=628CAA45.0420B4.01722@loongson.cn \
    --to=caiyinyu@loongson.cn \
    --cc=joseph_myers@mentor.com \
    --cc=libc-alpha@sourceware.org \
    --cc=maskray@google.com \
    --cc=xuchenghua@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).