08c3a6
commit b868b45f6763a4adc4aa93248be9f84480768fcf
08c3a6
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
08c3a6
Date:   Wed Oct 13 09:49:34 2021 -0300
08c3a6
08c3a6
    elf: Fix dynamic-link.h usage on rtld.c
08c3a6
    
08c3a6
    The 4af6982e4c fix does not fully handle RTLD_BOOTSTRAP usage on
08c3a6
    rtld.c due two issues:
08c3a6
    
08c3a6
      1. RTLD_BOOTSTRAP is also used on dl-machine.h on various
08c3a6
         architectures and it changes the semantics of various machine
08c3a6
         relocation functions.
08c3a6
    
08c3a6
      2. The elf_get_dynamic_info() change was done sideways, previously
08c3a6
         to 490e6c62aa get-dynamic-info.h was included by the first
08c3a6
         dynamic-link.h include *without* RTLD_BOOTSTRAP being defined.
08c3a6
         It means that the code within elf_get_dynamic_info() that uses
08c3a6
         RTLD_BOOTSTRAP is in fact unused.
08c3a6
    
08c3a6
    To fix 1. this patch now includes dynamic-link.h only once with
08c3a6
    RTLD_BOOTSTRAP defined.  The ELF_DYNAMIC_RELOCATE call will now have
08c3a6
    the relocation fnctions with the expected semantics for the loader.
08c3a6
    
08c3a6
    And to fix 2. part of 4af6982e4c is reverted (the check argument
08c3a6
    elf_get_dynamic_info() is not required) and the RTLD_BOOTSTRAP
08c3a6
    pieces are removed.
08c3a6
    
08c3a6
    To reorganize the includes the static TLS definition is moved to
08c3a6
    its own header to avoid a circular dependency (it is defined on
08c3a6
    dynamic-link.h and dl-machine.h requires it at same time other
08c3a6
    dynamic-link.h definition requires dl-machine.h defitions).
08c3a6
    
08c3a6
    Also ELF_MACHINE_NO_REL, ELF_MACHINE_NO_RELA, and ELF_MACHINE_PLT_REL
08c3a6
    are moved to its own header.  Only ancient ABIs need special values
08c3a6
    (arm, i386, and mips), so a generic one is used as default.
08c3a6
    
08c3a6
    The powerpc Elf64_FuncDesc is also moved to its own header, since
08c3a6
    csu code required its definition (which would require either include
08c3a6
    elf/ folder or add a full path with elf/).
08c3a6
    
08c3a6
    Checked on x86_64, i686, aarch64, armhf, powerpc64, powerpc32,
08c3a6
    and powerpc64le.
08c3a6
    
08c3a6
    Reviewed-by: Szabolcs Nagy <szabolcs.nagy@arm.com>
08c3a6
    (cherry picked from commit d6d89608ac8cf2b37c75debad1fff653f6939f90)
08c3a6
    
08c3a6
    Resolved conflicts:
08c3a6
            elf/rtld.c
08c3a6
08c3a6
Conflicts:
08c3a6
	elf/rtld.c - Manual merge around dl-execve.h include.
08c3a6
08c3a6
diff --git a/elf/dl-load.c b/elf/dl-load.c
08c3a6
index eea06629a978aaf3..fb3da5aa565908a6 100644
08c3a6
--- a/elf/dl-load.c
08c3a6
+++ b/elf/dl-load.c
08c3a6
@@ -1296,7 +1296,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
08c3a6
   if (l->l_ld != 0)
08c3a6
     l->l_ld = (ElfW(Dyn) *) ((ElfW(Addr)) l->l_ld + l->l_addr);
08c3a6
 
08c3a6
-  elf_get_dynamic_info (l, false);
08c3a6
+  elf_get_dynamic_info (l);
08c3a6
 
08c3a6
   /* Make sure we are not dlopen'ing an object that has the
08c3a6
      DF_1_NOOPEN flag set, or a PIE object.  */
08c3a6
diff --git a/elf/dl-reloc-static-pie.c b/elf/dl-reloc-static-pie.c
08c3a6
index f323b4dd0d5ba279..ababafcf98f9945d 100644
08c3a6
--- a/elf/dl-reloc-static-pie.c
08c3a6
+++ b/elf/dl-reloc-static-pie.c
08c3a6
@@ -52,7 +52,7 @@ _dl_relocate_static_pie (void)
08c3a6
 	break;
08c3a6
       }
08c3a6
 
08c3a6
-  elf_get_dynamic_info (main_map, false);
08c3a6
+  elf_get_dynamic_info (main_map);
08c3a6
 
08c3a6
 # ifdef ELF_MACHINE_BEFORE_RTLD_RELOC
08c3a6
   ELF_MACHINE_BEFORE_RTLD_RELOC (main_map, main_map->l_info);
08c3a6
diff --git a/elf/dl-static-tls.h b/elf/dl-static-tls.h
08c3a6
new file mode 100644
08c3a6
index 0000000000000000..730924fc0155acb7
08c3a6
--- /dev/null
08c3a6
+++ b/elf/dl-static-tls.h
08c3a6
@@ -0,0 +1,51 @@
08c3a6
+/* Inline functions for dynamic linking.
08c3a6
+   Copyright (C) 1995-2021 Free Software Foundation, Inc.
08c3a6
+   This file is part of the GNU C Library.
08c3a6
+
08c3a6
+   The GNU C Library is free software; you can redistribute it and/or
08c3a6
+   modify it under the terms of the GNU Lesser General Public
08c3a6
+   License as published by the Free Software Foundation; either
08c3a6
+   version 2.1 of the License, or (at your option) any later version.
08c3a6
+
08c3a6
+   The GNU C Library is distributed in the hope that it will be useful,
08c3a6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
08c3a6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
08c3a6
+   Lesser General Public License for more details.
08c3a6
+
08c3a6
+   You should have received a copy of the GNU Lesser General Public
08c3a6
+   License along with the GNU C Library; if not, see
08c3a6
+   <https://www.gnu.org/licenses/>.  */
08c3a6
+
08c3a6
+#ifndef _DL_STATIC_TLS_H
08c3a6
+#define _DL_STATIC_TLS_H
08c3a6
+
08c3a6
+/* This macro is used as a callback from elf_machine_rel{a,} when a
08c3a6
+   static TLS reloc is about to be performed.  Since (in dl-load.c) we
08c3a6
+   permit dynamic loading of objects that might use such relocs, we
08c3a6
+   have to check whether each use is actually doable.  If the object
08c3a6
+   whose TLS segment the reference resolves to was allocated space in
08c3a6
+   the static TLS block at startup, then it's ok.  Otherwise, we make
08c3a6
+   an attempt to allocate it in surplus space on the fly.  If that
08c3a6
+   can't be done, we fall back to the error that DF_STATIC_TLS is
08c3a6
+   intended to produce.  */
08c3a6
+#define HAVE_STATIC_TLS(map, sym_map)					\
08c3a6
+    (__builtin_expect ((sym_map)->l_tls_offset != NO_TLS_OFFSET		\
08c3a6
+		       && ((sym_map)->l_tls_offset			\
08c3a6
+			   != FORCED_DYNAMIC_TLS_OFFSET), 1))
08c3a6
+
08c3a6
+#define CHECK_STATIC_TLS(map, sym_map)					\
08c3a6
+    do {								\
08c3a6
+      if (!HAVE_STATIC_TLS (map, sym_map))				\
08c3a6
+	_dl_allocate_static_tls (sym_map);				\
08c3a6
+    } while (0)
08c3a6
+
08c3a6
+#define TRY_STATIC_TLS(map, sym_map)					\
08c3a6
+    (__builtin_expect ((sym_map)->l_tls_offset				\
08c3a6
+		       != FORCED_DYNAMIC_TLS_OFFSET, 1)			\
08c3a6
+     && (__builtin_expect ((sym_map)->l_tls_offset != NO_TLS_OFFSET, 1)	\
08c3a6
+	 || _dl_try_allocate_static_tls (sym_map, true) == 0))
08c3a6
+
08c3a6
+int _dl_try_allocate_static_tls (struct link_map *map, bool optional)
08c3a6
+  attribute_hidden;
08c3a6
+
08c3a6
+#endif
08c3a6
diff --git a/elf/dynamic-link.h b/elf/dynamic-link.h
08c3a6
index 21cdfc88bbfb89ea..ac4cc70dea3da763 100644
08c3a6
--- a/elf/dynamic-link.h
08c3a6
+++ b/elf/dynamic-link.h
08c3a6
@@ -16,35 +16,7 @@
08c3a6
    License along with the GNU C Library; if not, see
08c3a6
    <https://www.gnu.org/licenses/>.  */
08c3a6
 
08c3a6
-/* This macro is used as a callback from elf_machine_rel{a,} when a
08c3a6
-   static TLS reloc is about to be performed.  Since (in dl-load.c) we
08c3a6
-   permit dynamic loading of objects that might use such relocs, we
08c3a6
-   have to check whether each use is actually doable.  If the object
08c3a6
-   whose TLS segment the reference resolves to was allocated space in
08c3a6
-   the static TLS block at startup, then it's ok.  Otherwise, we make
08c3a6
-   an attempt to allocate it in surplus space on the fly.  If that
08c3a6
-   can't be done, we fall back to the error that DF_STATIC_TLS is
08c3a6
-   intended to produce.  */
08c3a6
-#define HAVE_STATIC_TLS(map, sym_map)					\
08c3a6
-    (__builtin_expect ((sym_map)->l_tls_offset != NO_TLS_OFFSET		\
08c3a6
-		       && ((sym_map)->l_tls_offset			\
08c3a6
-			   != FORCED_DYNAMIC_TLS_OFFSET), 1))
08c3a6
-
08c3a6
-#define CHECK_STATIC_TLS(map, sym_map)					\
08c3a6
-    do {								\
08c3a6
-      if (!HAVE_STATIC_TLS (map, sym_map))				\
08c3a6
-	_dl_allocate_static_tls (sym_map);				\
08c3a6
-    } while (0)
08c3a6
-
08c3a6
-#define TRY_STATIC_TLS(map, sym_map)					\
08c3a6
-    (__builtin_expect ((sym_map)->l_tls_offset				\
08c3a6
-		       != FORCED_DYNAMIC_TLS_OFFSET, 1)			\
08c3a6
-     && (__builtin_expect ((sym_map)->l_tls_offset != NO_TLS_OFFSET, 1)	\
08c3a6
-	 || _dl_try_allocate_static_tls (sym_map, true) == 0))
08c3a6
-
08c3a6
-int _dl_try_allocate_static_tls (struct link_map *map, bool optional)
08c3a6
-  attribute_hidden;
08c3a6
-
08c3a6
+#include <dl-machine.h>
08c3a6
 #include <elf.h>
08c3a6
 
08c3a6
 #ifdef RESOLVE_MAP
08c3a6
@@ -91,9 +63,6 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[],
08c3a6
 # endif
08c3a6
 #endif
08c3a6
 
08c3a6
-#include <dl-machine.h>
08c3a6
-
08c3a6
-
08c3a6
 #ifdef RESOLVE_MAP
08c3a6
 
08c3a6
 # if defined RTLD_BOOTSTRAP || defined STATIC_PIE_BOOTSTRAP
08c3a6
diff --git a/elf/get-dynamic-info.h b/elf/get-dynamic-info.h
08c3a6
index d169099fbc9897cf..1ac0663d1ff5de24 100644
08c3a6
--- a/elf/get-dynamic-info.h
08c3a6
+++ b/elf/get-dynamic-info.h
08c3a6
@@ -22,10 +22,11 @@
08c3a6
 #define _GET_DYNAMIC_INFO_H
08c3a6
 
08c3a6
 #include <assert.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 #include <libc-diag.h>
08c3a6
 
08c3a6
 static inline void __attribute__ ((unused, always_inline))
08c3a6
-elf_get_dynamic_info (struct link_map *l, bool check)
08c3a6
+elf_get_dynamic_info (struct link_map *l)
08c3a6
 {
08c3a6
 #if __ELF_NATIVE_CLASS == 32
08c3a6
   typedef Elf32_Word d_tag_utype;
08c3a6
@@ -33,7 +34,7 @@ elf_get_dynamic_info (struct link_map *l, bool check)
08c3a6
   typedef Elf64_Xword d_tag_utype;
08c3a6
 #endif
08c3a6
 
08c3a6
-#if !defined RTLD_BOOTSTRAP && !defined STATIC_PIE_BOOTSTRAP
08c3a6
+#ifndef STATIC_PIE_BOOTSTRAP
08c3a6
   if (l->l_ld == NULL)
08c3a6
     return;
08c3a6
 #endif
08c3a6
@@ -111,21 +112,10 @@ elf_get_dynamic_info (struct link_map *l, bool check)
08c3a6
   if (info[DT_REL] != NULL)
08c3a6
     assert (info[DT_RELENT]->d_un.d_val == sizeof (ElfW(Rel)));
08c3a6
 #endif
08c3a6
-#ifdef RTLD_BOOTSTRAP
08c3a6
-  if (check)
08c3a6
-    {
08c3a6
-      /* Only the bind now flags are allowed.  */
08c3a6
-      assert (info[VERSYMIDX (DT_FLAGS_1)] == NULL
08c3a6
-	      || (info[VERSYMIDX (DT_FLAGS_1)]->d_un.d_val & ~DF_1_NOW) == 0);
08c3a6
-      /* Flags must not be set for ld.so.  */
08c3a6
-      assert (info[DT_FLAGS] == NULL
08c3a6
-	      || (info[DT_FLAGS]->d_un.d_val & ~DF_BIND_NOW) == 0);
08c3a6
-# ifdef STATIC_PIE_BOOTSTRAP
08c3a6
-      assert (info[DT_RUNPATH] == NULL);
08c3a6
-      assert (info[DT_RPATH] == NULL);
08c3a6
-# endif
08c3a6
-    }
08c3a6
-#else
08c3a6
+#ifdef STATIC_PIE_BOOTSTRAP
08c3a6
+  assert (info[DT_RUNPATH] == NULL);
08c3a6
+  assert (info[DT_RPATH] == NULL);
08c3a6
+#endif
08c3a6
   if (info[DT_FLAGS] != NULL)
08c3a6
     {
08c3a6
       /* Flags are used.  Translate to the old form where available.
08c3a6
@@ -163,7 +153,6 @@ elf_get_dynamic_info (struct link_map *l, bool check)
08c3a6
   if (info[DT_RUNPATH] != NULL)
08c3a6
     /* If both RUNPATH and RPATH are given, the latter is ignored.  */
08c3a6
     info[DT_RPATH] = NULL;
08c3a6
-#endif
08c3a6
 }
08c3a6
 
08c3a6
 #endif
08c3a6
diff --git a/elf/rtld.c b/elf/rtld.c
08c3a6
index 352d596dedb42e79..37d28d5a66d7b5d6 100644
08c3a6
--- a/elf/rtld.c
08c3a6
+++ b/elf/rtld.c
08c3a6
@@ -32,7 +32,6 @@
08c3a6
 #include <fpu_control.h>
08c3a6
 #include <hp-timing.h>
08c3a6
 #include <libc-lock.h>
08c3a6
-#include "dynamic-link.h"
08c3a6
 #include <dl-librecon.h>
08c3a6
 #include <unsecvars.h>
08c3a6
 #include <dl-cache.h>
08c3a6
@@ -51,9 +50,18 @@
08c3a6
 #include <gnu/lib-names.h>
08c3a6
 #include <dl-tunables.h>
08c3a6
 #include <dl-execve.h>
08c3a6
+#include <get-dynamic-info.h>
08c3a6
 
08c3a6
 #include <assert.h>
08c3a6
 
08c3a6
+/* This #define produces dynamic linking inline functions for
08c3a6
+   bootstrap relocation instead of general-purpose relocation.
08c3a6
+   Since ld.so must not have any undefined symbols the result
08c3a6
+   is trivial: always the map of ld.so itself.  */
08c3a6
+#define RTLD_BOOTSTRAP
08c3a6
+#define RESOLVE_MAP(map, scope, sym, version, flags) map
08c3a6
+#include "dynamic-link.h"
08c3a6
+
08c3a6
 /* Only enables rtld profiling for architectures which provides non generic
08c3a6
    hp-timing support.  The generic support requires either syscall
08c3a6
    (clock_gettime), which will incur in extra overhead on loading time.
08c3a6
@@ -508,15 +516,6 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
08c3a6
 # define bootstrap_map info.l
08c3a6
 #endif
08c3a6
 
08c3a6
-  /* This #define produces dynamic linking inline functions for
08c3a6
-     bootstrap relocation instead of general-purpose relocation.
08c3a6
-     Since ld.so must not have any undefined symbols the result
08c3a6
-     is trivial: always the map of ld.so itself.  */
08c3a6
-#define RTLD_BOOTSTRAP
08c3a6
-#define RESOLVE_MAP(map, scope, sym, version, flags) map
08c3a6
-#include "get-dynamic-info.h"
08c3a6
-#include "dynamic-link.h"
08c3a6
-
08c3a6
 static ElfW(Addr) __attribute_used__
08c3a6
 _dl_start (void *arg)
08c3a6
 {
08c3a6
@@ -550,7 +549,7 @@ _dl_start (void *arg)
08c3a6
   /* Read our own dynamic section and fill in the info array.  */
08c3a6
   bootstrap_map.l_ld = (void *) bootstrap_map.l_addr + elf_machine_dynamic ();
08c3a6
   bootstrap_map.l_ld_readonly = DL_RO_DYN_SECTION;
08c3a6
-  elf_get_dynamic_info (&bootstrap_map, true);
08c3a6
+  elf_get_dynamic_info (&bootstrap_map);
08c3a6
 
08c3a6
 #if NO_TLS_OFFSET != 0
08c3a6
   bootstrap_map.l_tls_offset = NO_TLS_OFFSET;
08c3a6
@@ -1654,7 +1653,7 @@ dl_main (const ElfW(Phdr) *phdr,
08c3a6
   if (! rtld_is_main)
08c3a6
     {
08c3a6
       /* Extract the contents of the dynamic section for easy access.  */
08c3a6
-      elf_get_dynamic_info (main_map, false);
08c3a6
+      elf_get_dynamic_info (main_map);
08c3a6
 
08c3a6
       /* If the main map is libc.so, update the base namespace to
08c3a6
 	 refer to this map.  If libc.so is loaded later, this happens
08c3a6
diff --git a/elf/setup-vdso.h b/elf/setup-vdso.h
08c3a6
index 6fdffafcca5e9916..f44748bc9858e5fd 100644
08c3a6
--- a/elf/setup-vdso.h
08c3a6
+++ b/elf/setup-vdso.h
08c3a6
@@ -64,7 +64,7 @@ setup_vdso (struct link_map *main_map __attribute__ ((unused)),
08c3a6
       l->l_map_end += l->l_addr;
08c3a6
       l->l_text_end += l->l_addr;
08c3a6
       l->l_ld = (void *) ((ElfW(Addr)) l->l_ld + l->l_addr);
08c3a6
-      elf_get_dynamic_info (l, false);
08c3a6
+      elf_get_dynamic_info (l);
08c3a6
       _dl_setup_hash (l);
08c3a6
       l->l_relocated = 1;
08c3a6
 
08c3a6
diff --git a/sysdeps/aarch64/dl-machine.h b/sysdeps/aarch64/dl-machine.h
08c3a6
index 34c0790b893a529b..07af183e711b50f2 100644
08c3a6
--- a/sysdeps/aarch64/dl-machine.h
08c3a6
+++ b/sysdeps/aarch64/dl-machine.h
08c3a6
@@ -24,7 +24,9 @@
08c3a6
 #include <sysdep.h>
08c3a6
 #include <tls.h>
08c3a6
 #include <dl-tlsdesc.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
 #include <dl-irel.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 #include <cpu-features.c>
08c3a6
 
08c3a6
 /* Translate a processor specific dynamic tag to the index in l_info array.  */
08c3a6
@@ -196,10 +198,6 @@ _dl_start_user:								\n\
08c3a6
 
08c3a6
 #define ELF_MACHINE_JMP_SLOT	AARCH64_R(JUMP_SLOT)
08c3a6
 
08c3a6
-/* AArch64 uses RELA not REL */
08c3a6
-#define ELF_MACHINE_NO_REL 1
08c3a6
-#define ELF_MACHINE_NO_RELA 0
08c3a6
-
08c3a6
 #define DL_PLATFORM_INIT dl_platform_init ()
08c3a6
 
08c3a6
 static inline void __attribute__ ((unused))
08c3a6
@@ -376,7 +374,7 @@ elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[],
08c3a6
     }
08c3a6
 }
08c3a6
 
08c3a6
-inline void
08c3a6
+static inline void
08c3a6
 __attribute__ ((always_inline))
08c3a6
 elf_machine_rela_relative (ElfW(Addr) l_addr,
08c3a6
 			   const ElfW(Rela) *reloc,
08c3a6
diff --git a/sysdeps/alpha/dl-machine.h b/sysdeps/alpha/dl-machine.h
08c3a6
index 66e1db524bb378f6..e948e54fb7223a18 100644
08c3a6
--- a/sysdeps/alpha/dl-machine.h
08c3a6
+++ b/sysdeps/alpha/dl-machine.h
08c3a6
@@ -26,6 +26,8 @@
08c3a6
 #define ELF_MACHINE_NAME "alpha"
08c3a6
 
08c3a6
 #include <string.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 
08c3a6
 /* Mask identifying addresses reserved for the user program,
08c3a6
@@ -241,10 +243,6 @@ $fixup_stack:							\n\
08c3a6
 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
08c3a6
 #define ELF_MACHINE_JMP_SLOT	 R_ALPHA_JMP_SLOT
08c3a6
 
08c3a6
-/* The alpha never uses Elf64_Rel relocations.  */
08c3a6
-#define ELF_MACHINE_NO_REL 1
08c3a6
-#define ELF_MACHINE_NO_RELA 0
08c3a6
-
08c3a6
 /* We define an initialization functions.  This is called very early in
08c3a6
  *    _dl_sysdep_start.  */
08c3a6
 #define DL_PLATFORM_INIT dl_platform_init ()
08c3a6
diff --git a/sysdeps/arc/dl-machine.h b/sysdeps/arc/dl-machine.h
08c3a6
index 4b64ffec256b7f3b..f843ed9bd6ff5fc2 100644
08c3a6
--- a/sysdeps/arc/dl-machine.h
08c3a6
+++ b/sysdeps/arc/dl-machine.h
08c3a6
@@ -30,6 +30,8 @@
08c3a6
 #include <string.h>
08c3a6
 #include <link.h>
08c3a6
 #include <dl-tls.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 /* Dynamic Linking ABI for ARCv2 ISA.
08c3a6
 
08c3a6
@@ -203,10 +205,6 @@ __start:								\n\
08c3a6
 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
08c3a6
 #define ELF_MACHINE_JMP_SLOT  R_ARC_JUMP_SLOT
08c3a6
 
08c3a6
-/* ARC uses Rela relocations.  */
08c3a6
-#define ELF_MACHINE_NO_REL 1
08c3a6
-#define ELF_MACHINE_NO_RELA 0
08c3a6
-
08c3a6
 /* Fixup a PLT entry to bounce directly to the function at VALUE.  */
08c3a6
 
08c3a6
 static inline ElfW(Addr)
08c3a6
@@ -318,7 +316,7 @@ elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[],
08c3a6
     }
08c3a6
 }
08c3a6
 
08c3a6
-inline void
08c3a6
+static inline void
08c3a6
 __attribute__ ((always_inline))
08c3a6
 elf_machine_rela_relative (ElfW(Addr) l_addr, const ElfW(Rela) *reloc,
08c3a6
                            void *const reloc_addr_arg)
08c3a6
@@ -327,7 +325,7 @@ elf_machine_rela_relative (ElfW(Addr) l_addr, const ElfW(Rela) *reloc,
08c3a6
   *reloc_addr += l_addr;
08c3a6
 }
08c3a6
 
08c3a6
-inline void
08c3a6
+static inline void
08c3a6
 __attribute__ ((always_inline))
08c3a6
 elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[],
08c3a6
 		      ElfW(Addr) l_addr, const ElfW(Rela) *reloc,
08c3a6
diff --git a/sysdeps/arm/dl-machine-rel.h b/sysdeps/arm/dl-machine-rel.h
08c3a6
new file mode 100644
08c3a6
index 0000000000000000..bec114706cd027a4
08c3a6
--- /dev/null
08c3a6
+++ b/sysdeps/arm/dl-machine-rel.h
08c3a6
@@ -0,0 +1,31 @@
08c3a6
+/* ELF dynamic relocation type supported by the architecture.  ARM version.
08c3a6
+   Copyright (C) 2001-2021 Free Software Foundation, Inc.
08c3a6
+   This file is part of the GNU C Library.
08c3a6
+
08c3a6
+   The GNU C Library is free software; you can redistribute it and/or
08c3a6
+   modify it under the terms of the GNU Lesser General Public
08c3a6
+   License as published by the Free Software Foundation; either
08c3a6
+   version 2.1 of the License, or (at your option) any later version.
08c3a6
+
08c3a6
+   The GNU C Library is distributed in the hope that it will be useful,
08c3a6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
08c3a6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
08c3a6
+   Lesser General Public License for more details.
08c3a6
+
08c3a6
+   You should have received a copy of the GNU Lesser General Public
08c3a6
+   License along with the GNU C Library; if not, see
08c3a6
+   <https://www.gnu.org/licenses/>.  */
08c3a6
+
08c3a6
+#ifndef _DL_MACHINE_REL_H
08c3a6
+#define _DL_MACHINE_REL_H
08c3a6
+
08c3a6
+/* ARM never uses Elf32_Rela relocations for the dynamic linker.
08c3a6
+   Prelinked libraries may use Elf32_Rela though.  */
08c3a6
+#define ELF_MACHINE_NO_RELA defined RTLD_BOOTSTRAP
08c3a6
+#define ELF_MACHINE_NO_REL 0
08c3a6
+
08c3a6
+/* ARM never uses Elf32_Rela relocations for the dynamic linker.
08c3a6
+   Prelinked libraries may use Elf32_Rela though.  */
08c3a6
+#define ELF_MACHINE_PLT_REL 1
08c3a6
+
08c3a6
+#endif
08c3a6
diff --git a/sysdeps/arm/dl-machine.h b/sysdeps/arm/dl-machine.h
08c3a6
index 86f866ca7c17bd9b..3239841eb5b36623 100644
08c3a6
--- a/sysdeps/arm/dl-machine.h
08c3a6
+++ b/sysdeps/arm/dl-machine.h
08c3a6
@@ -26,6 +26,8 @@
08c3a6
 #include <tls.h>
08c3a6
 #include <dl-tlsdesc.h>
08c3a6
 #include <dl-irel.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 #ifndef CLEAR_CACHE
08c3a6
 # error CLEAR_CACHE definition required to handle TEXTREL
08c3a6
@@ -258,10 +260,6 @@ _dl_start_user:\n\
08c3a6
 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
08c3a6
 #define ELF_MACHINE_JMP_SLOT	R_ARM_JUMP_SLOT
08c3a6
 
08c3a6
-/* ARM never uses Elf32_Rela relocations for the dynamic linker.
08c3a6
-   Prelinked libraries may use Elf32_Rela though.  */
08c3a6
-#define ELF_MACHINE_PLT_REL 1
08c3a6
-
08c3a6
 /* We define an initialization functions.  This is called very early in
08c3a6
    _dl_sysdep_start.  */
08c3a6
 #define DL_PLATFORM_INIT dl_platform_init ()
08c3a6
@@ -294,11 +292,6 @@ elf_machine_plt_value (struct link_map *map, const Elf32_Rel *reloc,
08c3a6
 #endif /* !dl_machine_h */
08c3a6
 
08c3a6
 
08c3a6
-/* ARM never uses Elf32_Rela relocations for the dynamic linker.
08c3a6
-   Prelinked libraries may use Elf32_Rela though.  */
08c3a6
-#define ELF_MACHINE_NO_RELA defined RTLD_BOOTSTRAP
08c3a6
-#define ELF_MACHINE_NO_REL 0
08c3a6
-
08c3a6
 /* Names of the architecture-specific auditing callback functions.  */
08c3a6
 #define ARCH_LA_PLTENTER arm_gnu_pltenter
08c3a6
 #define ARCH_LA_PLTEXIT arm_gnu_pltexit
08c3a6
diff --git a/sysdeps/csky/dl-machine.h b/sysdeps/csky/dl-machine.h
08c3a6
index ec22f875772b1291..4dfd9578773f1c8e 100644
08c3a6
--- a/sysdeps/csky/dl-machine.h
08c3a6
+++ b/sysdeps/csky/dl-machine.h
08c3a6
@@ -24,6 +24,8 @@
08c3a6
 #include <sys/param.h>
08c3a6
 #include <sysdep.h>
08c3a6
 #include <dl-tls.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 /* Return nonzero if ELF header is compatible with the running host.  */
08c3a6
 static inline int
08c3a6
@@ -172,10 +174,6 @@ _dl_start_user:\n\
08c3a6
 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
08c3a6
 #define ELF_MACHINE_JMP_SLOT R_CKCORE_JUMP_SLOT
08c3a6
 
08c3a6
-/* C-SKY never uses Elf32_Rel relocations.  */
08c3a6
-#define ELF_MACHINE_NO_REL 1
08c3a6
-#define ELF_MACHINE_NO_RELA 0
08c3a6
-
08c3a6
 /* We define an initialization functions.  This is called very early in
08c3a6
    _dl_sysdep_start.  */
08c3a6
 #define DL_PLATFORM_INIT dl_platform_init ()
08c3a6
diff --git a/sysdeps/generic/dl-machine-rel.h b/sysdeps/generic/dl-machine-rel.h
08c3a6
new file mode 100644
08c3a6
index 0000000000000000..9167a1dffc715704
08c3a6
--- /dev/null
08c3a6
+++ b/sysdeps/generic/dl-machine-rel.h
08c3a6
@@ -0,0 +1,27 @@
08c3a6
+/* ELF dynamic relocation type supported by the architecture.
08c3a6
+   Copyright (C) 2001-2021 Free Software Foundation, Inc.
08c3a6
+   This file is part of the GNU C Library.
08c3a6
+
08c3a6
+   The GNU C Library is free software; you can redistribute it and/or
08c3a6
+   modify it under the terms of the GNU Lesser General Public
08c3a6
+   License as published by the Free Software Foundation; either
08c3a6
+   version 2.1 of the License, or (at your option) any later version.
08c3a6
+
08c3a6
+   The GNU C Library is distributed in the hope that it will be useful,
08c3a6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
08c3a6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
08c3a6
+   Lesser General Public License for more details.
08c3a6
+
08c3a6
+   You should have received a copy of the GNU Lesser General Public
08c3a6
+   License along with the GNU C Library; if not, see
08c3a6
+   <https://www.gnu.org/licenses/>.  */
08c3a6
+
08c3a6
+#ifndef _DL_MACHINE_REL_H
08c3a6
+#define _DL_MACHINE_REL_H
08c3a6
+
08c3a6
+/* Defined if the architecture supports Elf{32,64}_Rel relocations.  */
08c3a6
+#define ELF_MACHINE_NO_REL 1
08c3a6
+/* Defined if the architecture supports Elf{32,64}_Rela relocations.  */
08c3a6
+#define ELF_MACHINE_NO_RELA 0
08c3a6
+
08c3a6
+#endif
08c3a6
diff --git a/sysdeps/generic/dl-machine.h b/sysdeps/generic/dl-machine.h
08c3a6
index 4a4ab4fc70ff1cf1..7da695d9030b000e 100644
08c3a6
--- a/sysdeps/generic/dl-machine.h
08c3a6
+++ b/sysdeps/generic/dl-machine.h
08c3a6
@@ -20,6 +20,8 @@
08c3a6
 
08c3a6
 #include <string.h>
08c3a6
 #include <link.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 
08c3a6
 /* Return nonzero iff ELF header is compatible with the running host.  */
08c3a6
diff --git a/sysdeps/hppa/dl-machine.h b/sysdeps/hppa/dl-machine.h
08c3a6
index 088931f67065250c..ac66f044189edd18 100644
08c3a6
--- a/sysdeps/hppa/dl-machine.h
08c3a6
+++ b/sysdeps/hppa/dl-machine.h
08c3a6
@@ -31,6 +31,8 @@
08c3a6
 #include <dl-fptr.h>
08c3a6
 #include <abort-instr.h>
08c3a6
 #include <tls.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 /* These two definitions must match the definition of the stub in
08c3a6
    bfd/elf32-hppa.c (see plt_stub[]).
08c3a6
@@ -525,10 +527,6 @@ asm (									\
08c3a6
 #define ELF_MACHINE_JMP_SLOT R_PARISC_IPLT
08c3a6
 #define ELF_MACHINE_SIZEOF_JMP_SLOT PLT_ENTRY_SIZE
08c3a6
 
08c3a6
-/* We only use RELA. */
08c3a6
-#define ELF_MACHINE_NO_REL 1
08c3a6
-#define ELF_MACHINE_NO_RELA 0
08c3a6
-
08c3a6
 /* Return the address of the entry point. */
08c3a6
 #define ELF_MACHINE_START_ADDRESS(map, start)			\
08c3a6
 ({								\
08c3a6
diff --git a/sysdeps/i386/dl-machine-rel.h b/sysdeps/i386/dl-machine-rel.h
08c3a6
new file mode 100644
08c3a6
index 0000000000000000..7ac46f78a69fbf98
08c3a6
--- /dev/null
08c3a6
+++ b/sysdeps/i386/dl-machine-rel.h
08c3a6
@@ -0,0 +1,31 @@
08c3a6
+/* ELF dynamic relocation type supported by the architecture.  ARM version.
08c3a6
+   Copyright (C) 2001-2021 Free Software Foundation, Inc.
08c3a6
+   This file is part of the GNU C Library.
08c3a6
+
08c3a6
+   The GNU C Library is free software; you can redistribute it and/or
08c3a6
+   modify it under the terms of the GNU Lesser General Public
08c3a6
+   License as published by the Free Software Foundation; either
08c3a6
+   version 2.1 of the License, or (at your option) any later version.
08c3a6
+
08c3a6
+   The GNU C Library is distributed in the hope that it will be useful,
08c3a6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
08c3a6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
08c3a6
+   Lesser General Public License for more details.
08c3a6
+
08c3a6
+   You should have received a copy of the GNU Lesser General Public
08c3a6
+   License along with the GNU C Library; if not, see
08c3a6
+   <https://www.gnu.org/licenses/>.  */
08c3a6
+
08c3a6
+#ifndef _DL_MACHINE_REL_H
08c3a6
+#define _DL_MACHINE_REL_H
08c3a6
+
08c3a6
+/* The i386 never uses Elf32_Rela relocations for the dynamic linker.
08c3a6
+   Prelinked libraries may use Elf32_Rela though.  */
08c3a6
+#define ELF_MACHINE_NO_RELA defined RTLD_BOOTSTRAP
08c3a6
+#define ELF_MACHINE_NO_REL 0
08c3a6
+
08c3a6
+/* The i386 never uses Elf32_Rela relocations for the dynamic linker.
08c3a6
+   Prelinked libraries may use Elf32_Rela though.  */
08c3a6
+#define ELF_MACHINE_PLT_REL 1
08c3a6
+
08c3a6
+#endif
08c3a6
diff --git a/sysdeps/i386/dl-machine.h b/sysdeps/i386/dl-machine.h
08c3a6
index fa902612ca8557f9..c55c9a3d64bed1f2 100644
08c3a6
--- a/sysdeps/i386/dl-machine.h
08c3a6
+++ b/sysdeps/i386/dl-machine.h
08c3a6
@@ -26,6 +26,8 @@
08c3a6
 #include <sysdep.h>
08c3a6
 #include <tls.h>
08c3a6
 #include <dl-tlsdesc.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 /* Return nonzero iff ELF header is compatible with the running host.  */
08c3a6
 static inline int __attribute__ ((unused))
08c3a6
@@ -237,10 +239,6 @@ _dl_start_user:\n\
08c3a6
 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
08c3a6
 #define ELF_MACHINE_JMP_SLOT	R_386_JMP_SLOT
08c3a6
 
08c3a6
-/* The i386 never uses Elf32_Rela relocations for the dynamic linker.
08c3a6
-   Prelinked libraries may use Elf32_Rela though.  */
08c3a6
-#define ELF_MACHINE_PLT_REL 1
08c3a6
-
08c3a6
 /* We define an initialization functions.  This is called very early in
08c3a6
    _dl_sysdep_start.  */
08c3a6
 #define DL_PLATFORM_INIT dl_platform_init ()
08c3a6
@@ -283,11 +281,6 @@ elf_machine_plt_value (struct link_map *map, const Elf32_Rel *reloc,
08c3a6
 
08c3a6
 #endif /* !dl_machine_h */
08c3a6
 
08c3a6
-/* The i386 never uses Elf32_Rela relocations for the dynamic linker.
08c3a6
-   Prelinked libraries may use Elf32_Rela though.  */
08c3a6
-#define ELF_MACHINE_NO_RELA defined RTLD_BOOTSTRAP
08c3a6
-#define ELF_MACHINE_NO_REL 0
08c3a6
-
08c3a6
 #ifdef RESOLVE_MAP
08c3a6
 
08c3a6
 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
08c3a6
diff --git a/sysdeps/ia64/dl-machine.h b/sysdeps/ia64/dl-machine.h
08c3a6
index 2217d0b556c17683..c9608a51b0291164 100644
08c3a6
--- a/sysdeps/ia64/dl-machine.h
08c3a6
+++ b/sysdeps/ia64/dl-machine.h
08c3a6
@@ -27,6 +27,8 @@
08c3a6
 #include <errno.h>
08c3a6
 #include <dl-fptr.h>
08c3a6
 #include <tls.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 /* Translate a processor specific dynamic tag to the index
08c3a6
    in l_info array.  */
08c3a6
@@ -319,10 +321,6 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[],
08c3a6
 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
08c3a6
 #define ELF_MACHINE_JMP_SLOT	 R_IA64_IPLTLSB
08c3a6
 
08c3a6
-/* According to the IA-64 specific documentation, Rela is always used.  */
08c3a6
-#define ELF_MACHINE_NO_REL 1
08c3a6
-#define ELF_MACHINE_NO_RELA 0
08c3a6
-
08c3a6
 /* Return the address of the entry point. */
08c3a6
 #define ELF_MACHINE_START_ADDRESS(map, start)			\
08c3a6
 ({								\
08c3a6
diff --git a/sysdeps/m68k/dl-machine.h b/sysdeps/m68k/dl-machine.h
08c3a6
index 5e34c4784e348b19..30323d62d443645a 100644
08c3a6
--- a/sysdeps/m68k/dl-machine.h
08c3a6
+++ b/sysdeps/m68k/dl-machine.h
08c3a6
@@ -24,6 +24,8 @@
08c3a6
 #include <sys/param.h>
08c3a6
 #include <sysdep.h>
08c3a6
 #include <dl-tls.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 /* Return nonzero iff ELF header is compatible with the running host.  */
08c3a6
 static inline int
08c3a6
@@ -183,10 +185,6 @@ _dl_start_user:\n\
08c3a6
 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
08c3a6
 #define ELF_MACHINE_JMP_SLOT	R_68K_JMP_SLOT
08c3a6
 
08c3a6
-/* The m68k never uses Elf32_Rel relocations.  */
08c3a6
-#define ELF_MACHINE_NO_REL 1
08c3a6
-#define ELF_MACHINE_NO_RELA 0
08c3a6
-
08c3a6
 static inline Elf32_Addr
08c3a6
 elf_machine_fixup_plt (struct link_map *map, lookup_t t,
08c3a6
 		       const ElfW(Sym) *refsym, const ElfW(Sym) *sym,
08c3a6
diff --git a/sysdeps/microblaze/dl-machine.h b/sysdeps/microblaze/dl-machine.h
08c3a6
index 3fd4988e6093be1c..b8cc5a7fe65af90a 100644
08c3a6
--- a/sysdeps/microblaze/dl-machine.h
08c3a6
+++ b/sysdeps/microblaze/dl-machine.h
08c3a6
@@ -23,6 +23,8 @@
08c3a6
 
08c3a6
 #include <sys/param.h>
08c3a6
 #include <tls.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 /* Return nonzero iff ELF header is compatible with the running host.  */
08c3a6
 static inline int
08c3a6
@@ -169,10 +171,6 @@ _dl_start_user:\n\
08c3a6
 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
08c3a6
 #define ELF_MACHINE_JMP_SLOT	R_MICROBLAZE_JUMP_SLOT
08c3a6
 
08c3a6
-/* The microblaze never uses Elf32_Rel relocations.  */
08c3a6
-#define ELF_MACHINE_NO_REL 1
08c3a6
-#define ELF_MACHINE_NO_RELA 0
08c3a6
-
08c3a6
 static inline Elf32_Addr
08c3a6
 elf_machine_fixup_plt (struct link_map *map, lookup_t t,
08c3a6
 		       const ElfW(Sym) *refsym, const ElfW(Sym) *sym,
08c3a6
diff --git a/sysdeps/mips/dl-machine-rel.h b/sysdeps/mips/dl-machine-rel.h
08c3a6
new file mode 100644
08c3a6
index 0000000000000000..ed396180412bc723
08c3a6
--- /dev/null
08c3a6
+++ b/sysdeps/mips/dl-machine-rel.h
08c3a6
@@ -0,0 +1,26 @@
08c3a6
+/* ELF dynamic relocation type supported by the architecture.  ARM version.
08c3a6
+   Copyright (C) 2001-2021 Free Software Foundation, Inc.
08c3a6
+   This file is part of the GNU C Library.
08c3a6
+
08c3a6
+   The GNU C Library is free software; you can redistribute it and/or
08c3a6
+   modify it under the terms of the GNU Lesser General Public
08c3a6
+   License as published by the Free Software Foundation; either
08c3a6
+   version 2.1 of the License, or (at your option) any later version.
08c3a6
+
08c3a6
+   The GNU C Library is distributed in the hope that it will be useful,
08c3a6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
08c3a6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
08c3a6
+   Lesser General Public License for more details.
08c3a6
+
08c3a6
+   You should have received a copy of the GNU Lesser General Public
08c3a6
+   License along with the GNU C Library; if not, see
08c3a6
+   <https://www.gnu.org/licenses/>.  */
08c3a6
+
08c3a6
+#ifndef _DL_MACHINE_REL_H
08c3a6
+#define _DL_MACHINE_REL_H
08c3a6
+
08c3a6
+#define ELF_MACHINE_PLT_REL 1
08c3a6
+#define ELF_MACHINE_NO_REL 0
08c3a6
+#define ELF_MACHINE_NO_RELA 0
08c3a6
+
08c3a6
+#endif
08c3a6
diff --git a/sysdeps/mips/dl-machine.h b/sysdeps/mips/dl-machine.h
08c3a6
index 7a821ceb8e518cef..45a394907a98be32 100644
08c3a6
--- a/sysdeps/mips/dl-machine.h
08c3a6
+++ b/sysdeps/mips/dl-machine.h
08c3a6
@@ -33,6 +33,8 @@
08c3a6
 #include <sysdep.h>
08c3a6
 #include <sys/asm.h>
08c3a6
 #include <dl-tls.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 /* The offset of gp from GOT might be system-dependent.  It's set by
08c3a6
    ld.  The same value is also */
08c3a6
@@ -60,10 +62,6 @@
08c3a6
   ((((type) == ELF_MACHINE_JMP_SLOT) * ELF_RTYPE_CLASS_PLT)	\
08c3a6
    | (((type) == R_MIPS_COPY) * ELF_RTYPE_CLASS_COPY))
08c3a6
 
08c3a6
-#define ELF_MACHINE_PLT_REL 1
08c3a6
-#define ELF_MACHINE_NO_REL 0
08c3a6
-#define ELF_MACHINE_NO_RELA 0
08c3a6
-
08c3a6
 /* Translate a processor specific dynamic tag to the index
08c3a6
    in l_info array.  */
08c3a6
 #define DT_MIPS(x) (DT_MIPS_##x - DT_LOPROC + DT_NUM)
08c3a6
diff --git a/sysdeps/nios2/dl-machine.h b/sysdeps/nios2/dl-machine.h
08c3a6
index 4de602b13d5500f6..430ca5d7ae1e0372 100644
08c3a6
--- a/sysdeps/nios2/dl-machine.h
08c3a6
+++ b/sysdeps/nios2/dl-machine.h
08c3a6
@@ -24,6 +24,8 @@
08c3a6
 #include <string.h>
08c3a6
 #include <link.h>
08c3a6
 #include <dl-tls.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 /* Return nonzero iff ELF header is compatible with the running host.  */
08c3a6
 static inline int
08c3a6
@@ -200,10 +202,6 @@ _start:\n\
08c3a6
 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
08c3a6
 #define ELF_MACHINE_JMP_SLOT  R_NIOS2_JUMP_SLOT
08c3a6
 
08c3a6
-/* The Nios II never uses Elf32_Rel relocations.  */
08c3a6
-#define ELF_MACHINE_NO_REL 1
08c3a6
-#define ELF_MACHINE_NO_RELA 0
08c3a6
-
08c3a6
 /* Fixup a PLT entry to bounce directly to the function at VALUE.  */
08c3a6
 
08c3a6
 static inline Elf32_Addr
08c3a6
diff --git a/sysdeps/powerpc/powerpc32/dl-machine.h b/sysdeps/powerpc/powerpc32/dl-machine.h
08c3a6
index cda012dc1b822254..8d062951ce0abd69 100644
08c3a6
--- a/sysdeps/powerpc/powerpc32/dl-machine.h
08c3a6
+++ b/sysdeps/powerpc/powerpc32/dl-machine.h
08c3a6
@@ -25,6 +25,8 @@
08c3a6
 #include <dl-tls.h>
08c3a6
 #include <dl-irel.h>
08c3a6
 #include <hwcapinfo.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 /* Translate a processor specific dynamic tag to the index
08c3a6
    in l_info array.  */
08c3a6
@@ -145,10 +147,6 @@ __elf_preferred_address(struct link_map *loader, size_t maplength,
08c3a6
 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
08c3a6
 #define ELF_MACHINE_JMP_SLOT	R_PPC_JMP_SLOT
08c3a6
 
08c3a6
-/* The PowerPC never uses REL relocations.  */
08c3a6
-#define ELF_MACHINE_NO_REL 1
08c3a6
-#define ELF_MACHINE_NO_RELA 0
08c3a6
-
08c3a6
 /* We define an initialization function to initialize HWCAP/HWCAP2 and
08c3a6
    platform data so it can be copied into the TCB later.  This is called
08c3a6
    very early in _dl_sysdep_start for dynamically linked binaries.  */
08c3a6
diff --git a/sysdeps/powerpc/powerpc64/dl-funcdesc.h b/sysdeps/powerpc/powerpc64/dl-funcdesc.h
08c3a6
new file mode 100644
08c3a6
index 0000000000000000..b2d1f76ce02d629e
08c3a6
--- /dev/null
08c3a6
+++ b/sysdeps/powerpc/powerpc64/dl-funcdesc.h
08c3a6
@@ -0,0 +1,34 @@
08c3a6
+/* PowerPC ELFv1 function descriptor definition.
08c3a6
+   Copyright (C) 2009-2021 Free Software Foundation, Inc.
08c3a6
+   This file is part of the GNU C Library.
08c3a6
+
08c3a6
+   The GNU C Library is free software; you can redistribute it and/or
08c3a6
+   modify it under the terms of the GNU Lesser General Public
08c3a6
+   License as published by the Free Software Foundation; either
08c3a6
+   version 2.1 of the License, or (at your option) any later version.
08c3a6
+
08c3a6
+   The GNU C Library is distributed in the hope that it will be useful,
08c3a6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
08c3a6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
08c3a6
+   Lesser General Public License for more details.
08c3a6
+
08c3a6
+   You should have received a copy of the GNU Lesser General Public
08c3a6
+   License along with the GNU C Library; if not, see
08c3a6
+   <https://www.gnu.org/licenses/>.  */
08c3a6
+
08c3a6
+#ifndef _DL_FUNCDESC_H
08c3a6
+#define _DL_FUNCDESC_H
08c3a6
+
08c3a6
+#if _CALL_ELF != 2
08c3a6
+/* A PowerPC64 function descriptor.  The .plt (procedure linkage
08c3a6
+   table) and .opd (official procedure descriptor) sections are
08c3a6
+   arrays of these.  */
08c3a6
+typedef struct
08c3a6
+{
08c3a6
+  Elf64_Addr fd_func;
08c3a6
+  Elf64_Addr fd_toc;
08c3a6
+  Elf64_Addr fd_aux;
08c3a6
+} Elf64_FuncDesc;
08c3a6
+#endif
08c3a6
+
08c3a6
+#endif
08c3a6
diff --git a/sysdeps/powerpc/powerpc64/dl-irel.h b/sysdeps/powerpc/powerpc64/dl-irel.h
08c3a6
index 0e11b7ff647c19d5..aa9a2dca71c3b05f 100644
08c3a6
--- a/sysdeps/powerpc/powerpc64/dl-irel.h
08c3a6
+++ b/sysdeps/powerpc/powerpc64/dl-irel.h
08c3a6
@@ -23,7 +23,7 @@
08c3a6
 #include <stdio.h>
08c3a6
 #include <unistd.h>
08c3a6
 #include <ldsodefs.h>
08c3a6
-#include <dl-machine.h>
08c3a6
+#include <dl-funcdesc.h>
08c3a6
 
08c3a6
 #define ELF_MACHINE_IRELA	1
08c3a6
 
08c3a6
diff --git a/sysdeps/powerpc/powerpc64/dl-machine.h b/sysdeps/powerpc/powerpc64/dl-machine.h
08c3a6
index 3f92fbb369eb5023..3a4a21a4124dc72a 100644
08c3a6
--- a/sysdeps/powerpc/powerpc64/dl-machine.h
08c3a6
+++ b/sysdeps/powerpc/powerpc64/dl-machine.h
08c3a6
@@ -28,23 +28,14 @@
08c3a6
 #include <sysdep.h>
08c3a6
 #include <hwcapinfo.h>
08c3a6
 #include <cpu-features.c>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-funcdesc.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 /* Translate a processor specific dynamic tag to the index
08c3a6
    in l_info array.  */
08c3a6
 #define DT_PPC64(x) (DT_PPC64_##x - DT_LOPROC + DT_NUM)
08c3a6
 
08c3a6
-#if _CALL_ELF != 2
08c3a6
-/* A PowerPC64 function descriptor.  The .plt (procedure linkage
08c3a6
-   table) and .opd (official procedure descriptor) sections are
08c3a6
-   arrays of these.  */
08c3a6
-typedef struct
08c3a6
-{
08c3a6
-  Elf64_Addr fd_func;
08c3a6
-  Elf64_Addr fd_toc;
08c3a6
-  Elf64_Addr fd_aux;
08c3a6
-} Elf64_FuncDesc;
08c3a6
-#endif
08c3a6
-
08c3a6
 #define ELF_MULT_MACHINES_SUPPORTED
08c3a6
 
08c3a6
 /* Return nonzero iff ELF header is compatible with the running host.  */
08c3a6
@@ -292,10 +283,6 @@ BODY_PREFIX "_dl_start_user:\n"						\
08c3a6
 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
08c3a6
 #define ELF_MACHINE_JMP_SLOT	R_PPC64_JMP_SLOT
08c3a6
 
08c3a6
-/* The PowerPC never uses REL relocations.  */
08c3a6
-#define ELF_MACHINE_NO_REL 1
08c3a6
-#define ELF_MACHINE_NO_RELA 0
08c3a6
-
08c3a6
 /* We define an initialization function to initialize HWCAP/HWCAP2 and
08c3a6
    platform data so it can be copied into the TCB later.  This is called
08c3a6
    very early in _dl_sysdep_start for dynamically linked binaries.  */
08c3a6
diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h
08c3a6
index 343c0feb6b437001..a9a3f63cb4d91f26 100644
08c3a6
--- a/sysdeps/riscv/dl-machine.h
08c3a6
+++ b/sysdeps/riscv/dl-machine.h
08c3a6
@@ -26,6 +26,8 @@
08c3a6
 #include <sys/asm.h>
08c3a6
 #include <dl-tls.h>
08c3a6
 #include <dl-irel.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 #ifndef _RTLD_PROLOGUE
08c3a6
 # define _RTLD_PROLOGUE(entry)						\
08c3a6
@@ -51,9 +53,6 @@
08c3a6
      || (__WORDSIZE == 64 && (type) == R_RISCV_TLS_TPREL64)))	\
08c3a6
    | (ELF_RTYPE_CLASS_COPY * ((type) == R_RISCV_COPY)))
08c3a6
 
08c3a6
-#define ELF_MACHINE_NO_REL 1
08c3a6
-#define ELF_MACHINE_NO_RELA 0
08c3a6
-
08c3a6
 /* Return nonzero iff ELF header is compatible with the running host.  */
08c3a6
 static inline int __attribute_used__
08c3a6
 elf_machine_matches_host (const ElfW(Ehdr) *ehdr)
08c3a6
diff --git a/sysdeps/s390/s390-32/dl-machine.h b/sysdeps/s390/s390-32/dl-machine.h
08c3a6
index 96a5e80c846c816a..ba681d1eac7bda53 100644
08c3a6
--- a/sysdeps/s390/s390-32/dl-machine.h
08c3a6
+++ b/sysdeps/s390/s390-32/dl-machine.h
08c3a6
@@ -27,6 +27,8 @@
08c3a6
 #include <link.h>
08c3a6
 #include <sysdeps/s390/dl-procinfo.h>
08c3a6
 #include <dl-irel.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 /* This is an older, now obsolete value.  */
08c3a6
 #define EM_S390_OLD	0xA390
08c3a6
@@ -277,10 +279,6 @@ _dl_start_user:\n\
08c3a6
 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
08c3a6
 #define ELF_MACHINE_JMP_SLOT    R_390_JMP_SLOT
08c3a6
 
08c3a6
-/* The S390 never uses Elf32_Rel relocations.  */
08c3a6
-#define ELF_MACHINE_NO_REL 1
08c3a6
-#define ELF_MACHINE_NO_RELA 0
08c3a6
-
08c3a6
 /* We define an initialization functions.  This is called very early in
08c3a6
    _dl_sysdep_start.  */
08c3a6
 #define DL_PLATFORM_INIT dl_platform_init ()
08c3a6
diff --git a/sysdeps/s390/s390-64/dl-machine.h b/sysdeps/s390/s390-64/dl-machine.h
08c3a6
index c94d09b9c8512738..af2cffd9f904274e 100644
08c3a6
--- a/sysdeps/s390/s390-64/dl-machine.h
08c3a6
+++ b/sysdeps/s390/s390-64/dl-machine.h
08c3a6
@@ -28,6 +28,8 @@
08c3a6
 #include <link.h>
08c3a6
 #include <sysdeps/s390/dl-procinfo.h>
08c3a6
 #include <dl-irel.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 #define ELF_MACHINE_IRELATIVE       R_390_IRELATIVE
08c3a6
 
08c3a6
@@ -225,10 +227,6 @@ _dl_start_user:\n\
08c3a6
 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
08c3a6
 #define ELF_MACHINE_JMP_SLOT	R_390_JMP_SLOT
08c3a6
 
08c3a6
-/* The 64 bit S/390 never uses Elf64_Rel relocations.  */
08c3a6
-#define ELF_MACHINE_NO_REL 1
08c3a6
-#define ELF_MACHINE_NO_RELA 0
08c3a6
-
08c3a6
 /* We define an initialization functions.  This is called very early in
08c3a6
    _dl_sysdep_start.  */
08c3a6
 #define DL_PLATFORM_INIT dl_platform_init ()
08c3a6
diff --git a/sysdeps/sh/dl-machine.h b/sysdeps/sh/dl-machine.h
08c3a6
index 0c22dfd8487a516e..d14023e7492f64e9 100644
08c3a6
--- a/sysdeps/sh/dl-machine.h
08c3a6
+++ b/sysdeps/sh/dl-machine.h
08c3a6
@@ -24,6 +24,8 @@
08c3a6
 #include <sys/param.h>
08c3a6
 #include <sysdep.h>
08c3a6
 #include <assert.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 /* Return nonzero iff ELF header is compatible with the running host.  */
08c3a6
 static inline int __attribute__ ((unused))
08c3a6
@@ -251,10 +253,6 @@ elf_machine_plt_value (struct link_map *map, const Elf32_Rela *reloc,
08c3a6
 
08c3a6
 #endif /* !dl_machine_h */
08c3a6
 
08c3a6
-/* SH never uses Elf32_Rel relocations.	 */
08c3a6
-#define ELF_MACHINE_NO_REL 1
08c3a6
-#define ELF_MACHINE_NO_RELA 0
08c3a6
-
08c3a6
 #ifdef RESOLVE_MAP
08c3a6
 
08c3a6
 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
08c3a6
diff --git a/sysdeps/sparc/sparc32/dl-machine.h b/sysdeps/sparc/sparc32/dl-machine.h
08c3a6
index 6361cfae9eb8fa58..78f53bc49920fa46 100644
08c3a6
--- a/sysdeps/sparc/sparc32/dl-machine.h
08c3a6
+++ b/sysdeps/sparc/sparc32/dl-machine.h
08c3a6
@@ -28,6 +28,8 @@
08c3a6
 #include <tls.h>
08c3a6
 #include <dl-plt.h>
08c3a6
 #include <elf/dl-hwcaps.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 /* Return nonzero iff ELF header is compatible with the running host.  */
08c3a6
 static inline int
08c3a6
@@ -196,10 +198,6 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[],
08c3a6
 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
08c3a6
 #define ELF_MACHINE_JMP_SLOT	R_SPARC_JMP_SLOT
08c3a6
 
08c3a6
-/* The SPARC never uses Elf32_Rel relocations.  */
08c3a6
-#define ELF_MACHINE_NO_REL 1
08c3a6
-#define ELF_MACHINE_NO_RELA 0
08c3a6
-
08c3a6
 /* Undo the sub %sp, 6*4, %sp; add %sp, 22*4, %o0 below to get at the
08c3a6
    value we want in __libc_stack_end.  */
08c3a6
 #define DL_STACK_END(cookie) \
08c3a6
diff --git a/sysdeps/sparc/sparc64/dl-machine.h b/sysdeps/sparc/sparc64/dl-machine.h
08c3a6
index 3fd18c6e5ef21e38..3fa79d038fd38976 100644
08c3a6
--- a/sysdeps/sparc/sparc64/dl-machine.h
08c3a6
+++ b/sysdeps/sparc/sparc64/dl-machine.h
08c3a6
@@ -26,6 +26,8 @@
08c3a6
 #include <ldsodefs.h>
08c3a6
 #include <sysdep.h>
08c3a6
 #include <dl-plt.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 #define ELF64_R_TYPE_ID(info)	((info) & 0xff)
08c3a6
 #define ELF64_R_TYPE_DATA(info) ((info) >> 8)
08c3a6
@@ -118,10 +120,6 @@ elf_machine_plt_value (struct link_map *map, const Elf64_Rela *reloc,
08c3a6
 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
08c3a6
 #define ELF_MACHINE_JMP_SLOT	R_SPARC_JMP_SLOT
08c3a6
 
08c3a6
-/* The SPARC never uses Elf64_Rel relocations.  */
08c3a6
-#define ELF_MACHINE_NO_REL 1
08c3a6
-#define ELF_MACHINE_NO_RELA 0
08c3a6
-
08c3a6
 /* Set up the loaded object described by L so its unrelocated PLT
08c3a6
    entries will jump to the on-demand fixup code in dl-runtime.c.  */
08c3a6
 
08c3a6
diff --git a/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h b/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h
08c3a6
index db388a022d552b8c..72b75d3bebfed0b5 100644
08c3a6
--- a/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h
08c3a6
+++ b/sysdeps/unix/sysv/linux/powerpc/libc-vdso.h
08c3a6
@@ -24,7 +24,7 @@
08c3a6
 #include <sysdep-vdso.h>
08c3a6
 
08c3a6
 #if (defined(__PPC64__) || defined(__powerpc64__)) && _CALL_ELF != 2
08c3a6
-# include <dl-machine.h>
08c3a6
+# include <dl-funcdesc.h>
08c3a6
 /* The correct solution is for _dl_vdso_vsym to return the address of the OPD
08c3a6
    for the kernel VDSO function.  That address would then be stored in the
08c3a6
    __vdso_* variables and returned as the result of the IFUNC resolver function.
08c3a6
diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
08c3a6
index 90c77cfea1de8d63..94296719d4d9fb82 100644
08c3a6
--- a/sysdeps/x86_64/dl-machine.h
08c3a6
+++ b/sysdeps/x86_64/dl-machine.h
08c3a6
@@ -27,6 +27,8 @@
08c3a6
 #include <sysdep.h>
08c3a6
 #include <tls.h>
08c3a6
 #include <dl-tlsdesc.h>
08c3a6
+#include <dl-static-tls.h>
08c3a6
+#include <dl-machine-rel.h>
08c3a6
 
08c3a6
 /* Return nonzero iff ELF header is compatible with the running host.  */
08c3a6
 static inline int __attribute__ ((unused))
08c3a6
@@ -208,10 +210,6 @@ _dl_start_user:\n\
08c3a6
 // XXX This is a work-around for a broken linker.  Remove!
08c3a6
 #define ELF_MACHINE_IRELATIVE	R_X86_64_IRELATIVE
08c3a6
 
08c3a6
-/* The x86-64 never uses Elf64_Rel/Elf32_Rel relocations.  */
08c3a6
-#define ELF_MACHINE_NO_REL 1
08c3a6
-#define ELF_MACHINE_NO_RELA 0
08c3a6
-
08c3a6
 /* We define an initialization function.  This is called very early in
08c3a6
    _dl_sysdep_start.  */
08c3a6
 #define DL_PLATFORM_INIT dl_platform_init ()