aboutsummaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2024-12-20 15:52:57 +0100
committerFlorian Weimer <fweimer@redhat.com>2024-12-20 15:52:57 +0100
commit2b1dba3eb364aa65ce4ee947c39fb8d2d75e69b5 (patch)
tree0036fd9611c8a9cda941c72ef80d16201380e24d /sysdeps
parent322e9d4e443084336ea41a8e7bf72456ab273b73 (diff)
downloadglibc-2b1dba3eb364aa65ce4ee947c39fb8d2d75e69b5.zip
glibc-2b1dba3eb364aa65ce4ee947c39fb8d2d75e69b5.tar.gz
glibc-2b1dba3eb364aa65ce4ee947c39fb8d2d75e69b5.tar.bz2
elf: Introduce is_rtld_link_map
Unconditionally define it to false for static builds. This avoids the awkward use of weak_extern for _dl_rtld_map in checks that cannot be possibly true on static builds. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/arm/dl-machine.h11
-rw-r--r--sysdeps/generic/ldsodefs.h16
-rw-r--r--sysdeps/mips/dl-machine.h16
-rw-r--r--sysdeps/powerpc/powerpc64/dl-machine.h4
-rw-r--r--sysdeps/sh/dl-machine.h13
-rw-r--r--sysdeps/x86/dl-prop.h2
6 files changed, 24 insertions, 38 deletions
diff --git a/sysdeps/arm/dl-machine.h b/sysdeps/arm/dl-machine.h
index 9186831..b328287 100644
--- a/sysdeps/arm/dl-machine.h
+++ b/sysdeps/arm/dl-machine.h
@@ -351,16 +351,7 @@ elf_machine_rel (struct link_map *map, struct r_scope_elem *scope[],
{
ElfW(Addr) tmp;
# ifndef RTLD_BOOTSTRAP
- /* This is defined in rtld.c, but nowhere in the static
- libc.a; make the reference weak so static programs can
- still link. This declaration cannot be done when
- compiling rtld.c (i.e. #ifdef RTLD_BOOTSTRAP) because
- rtld.c contains the common defn for _dl_rtld_map, which
- is incompatible with a weak decl in the same file. */
-# ifndef SHARED
- weak_extern (_dl_rtld_map);
-# endif
- if (map == &GL(dl_rtld_map))
+ if (is_rtld_link_map (map))
/* Undo the relocation done here during bootstrapping.
Now we will relocate it anew, possibly using a
binding found in the user program or a loaded library
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 384640b..2c25c8d 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -1323,10 +1323,17 @@ rtld_active (void)
return GLRO(dl_init_all_dirs) != NULL;
}
+/* Returns true of L is the link map of the dynamic linker itself. */
+static inline bool
+is_rtld_link_map (const struct link_map *l)
+{
+ return l == &GL(dl_rtld_map);
+}
+
static inline struct auditstate *
link_map_audit_state (struct link_map *l, size_t index)
{
- if (l == &GL (dl_rtld_map))
+ if (is_rtld_link_map (l))
/* The auditstate array is stored separately. */
return &GL (dl_rtld_auditstate) [index];
else
@@ -1389,6 +1396,13 @@ void DL_ARCH_FIXUP_ATTRIBUTE _dl_audit_pltexit (struct link_map *l,
attribute_hidden;
#else /* !SHARED */
+/* No special dynamic linker link map in static builds. */
+static inline bool
+is_rtld_link_map (const struct link_map *l)
+{
+ return false;
+}
+
static inline void
_dl_audit_objclose (struct link_map *l)
{
diff --git a/sysdeps/mips/dl-machine.h b/sysdeps/mips/dl-machine.h
index 10e30f1..7a361ed 100644
--- a/sysdeps/mips/dl-machine.h
+++ b/sysdeps/mips/dl-machine.h
@@ -436,16 +436,6 @@ elf_machine_reloc (struct link_map *map, struct r_scope_elem *scope[],
const unsigned long int r_type = ELFW(R_TYPE) (r_info);
ElfW(Addr) *addr_field = (ElfW(Addr) *) reloc_addr;
-#if !defined RTLD_BOOTSTRAP && !defined SHARED
- /* This is defined in rtld.c, but nowhere in the static libc.a;
- make the reference weak so static programs can still link. This
- declaration cannot be done when compiling rtld.c (i.e. #ifdef
- RTLD_BOOTSTRAP) because rtld.c contains the common defn for
- _dl_rtld_map, which is incompatible with a weak decl in the same
- file. */
- weak_extern (GL(dl_rtld_map));
-#endif
-
switch (r_type)
{
#if !defined (RTLD_BOOTSTRAP)
@@ -534,7 +524,7 @@ elf_machine_reloc (struct link_map *map, struct r_scope_elem *scope[],
though it's not ABI compliant. Some day we should
bite the bullet and stop doing this. */
#ifndef RTLD_BOOTSTRAP
- if (map != &GL(dl_rtld_map))
+ if (!is_rtld_link_map (map))
#endif
reloc_value += SYMBOL_ADDRESS (map, sym, true);
}
@@ -553,7 +543,7 @@ elf_machine_reloc (struct link_map *map, struct r_scope_elem *scope[],
}
else
#ifndef RTLD_BOOTSTRAP
- if (map != &GL(dl_rtld_map))
+ if (!is_rtld_link_map (map))
#endif
reloc_value += map->l_addr;
@@ -749,7 +739,7 @@ elf_machine_got_rel (struct link_map *map, struct r_scope_elem *scope[], int laz
n = map->l_info[DT_MIPS (LOCAL_GOTNO)]->d_un.d_val;
/* The dynamic linker's local got entries have already been relocated. */
- if (map != &GL(dl_rtld_map))
+ if (!is_rtld_link_map (map))
{
/* got[0] is reserved. got[1] is also reserved for the dynamic object
generated by gnu ld. Skip these reserved entries from relocation. */
diff --git a/sysdeps/powerpc/powerpc64/dl-machine.h b/sysdeps/powerpc/powerpc64/dl-machine.h
index 2b6f5d2..5855393 100644
--- a/sysdeps/powerpc/powerpc64/dl-machine.h
+++ b/sysdeps/powerpc/powerpc64/dl-machine.h
@@ -537,7 +537,7 @@ elf_machine_fixup_plt (struct link_map *map, lookup_t sym_map,
if (finaladdr != 0 && map != sym_map && !sym_map->l_relocated
#if !defined RTLD_BOOTSTRAP && defined SHARED
/* Bootstrap map doesn't have l_relocated set for it. */
- && sym_map != &GL(dl_rtld_map)
+ && !is_rtld_link_map (sym_map)
#endif
)
offset = sym_map->l_addr;
@@ -662,7 +662,7 @@ resolve_ifunc (Elf64_Addr value,
if (map != sym_map
# if !defined RTLD_BOOTSTRAP && defined SHARED
/* Bootstrap map doesn't have l_relocated set for it. */
- && sym_map != &GL(dl_rtld_map)
+ && !is_rtld_link_map (map)
# endif
&& !sym_map->l_relocated)
{
diff --git a/sysdeps/sh/dl-machine.h b/sysdeps/sh/dl-machine.h
index c2c970d..01cd511 100644
--- a/sysdeps/sh/dl-machine.h
+++ b/sysdeps/sh/dl-machine.h
@@ -284,7 +284,7 @@ elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[],
if (__glibc_unlikely (r_type == R_SH_RELATIVE))
{
#ifndef RTLD_BOOTSTRAP
- if (map != &GL(dl_rtld_map)) /* Already done in rtld itself. */
+ if (is_rtld_link_map (map)) /* Already done in rtld itself. */
#endif
{
if (reloc->r_addend)
@@ -380,16 +380,7 @@ elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[],
case R_SH_DIR32:
{
#if !defined RTLD_BOOTSTRAP
- /* This is defined in rtld.c, but nowhere in the static
- libc.a; make the reference weak so static programs can
- still link. This declaration cannot be done when
- compiling rtld.c (i.e. #ifdef RTLD_BOOTSTRAP) because
- rtld.c contains the common defn for _dl_rtld_map, which
- is incompatible with a weak decl in the same file. */
-# ifndef SHARED
- weak_extern (_dl_rtld_map);
-# endif
- if (map == &GL(dl_rtld_map))
+ if (is_rtld_link_map (map))
/* Undo the relocation done here during bootstrapping.
Now we will relocate it anew, possibly using a
binding found in the user program or a loaded library
diff --git a/sysdeps/x86/dl-prop.h b/sysdeps/x86/dl-prop.h
index 08387df..62619d7 100644
--- a/sysdeps/x86/dl-prop.h
+++ b/sysdeps/x86/dl-prop.h
@@ -46,7 +46,7 @@ dl_isa_level_check (struct link_map *m, const char *program)
#ifdef SHARED
/* Skip ISA level check for ld.so since ld.so won't run if its ISA
level is higher than CPU. */
- if (l == &GL(dl_rtld_map) || l->l_real == &GL(dl_rtld_map))
+ if (is_rtld_link_map (l) || is_rtld_link_map (l->l_real))
continue;
#endif