From: Florian Weimer <fweimer@redhat.com>
To: libc-alpha@sourceware.org
Subject: [PATCH 22/33] elf: _dl_rtld_map should not exist in static builds
Date: Tue, 04 Jul 2023 22:03:53 +0200 [thread overview]
Message-ID: <943e9e8148b3f0213c272ce1970574cb536ebcc6.1688499219.git.fweimer@redhat.com> (raw)
In-Reply-To: <cover.1688499219.git.fweimer@redhat.com>
We have separate objects for SHARED and !SHARED, so there is no need
to make the rtld link map equality check somehow work in static
builds. Instead, hide the _dl_rtld_map reference in the new
is_rtld_link_map function, and simply define that to return false
for !SHARED because the static linked loader does not have a link
map.
---
elf/do-rel.h | 11 +----------
elf/dynamic-link.h | 2 +-
sysdeps/arm/dl-machine.h | 11 +----------
sysdeps/generic/ldsodefs.h | 14 ++++++++++++++
sysdeps/mips/dl-machine.h | 16 +++-------------
sysdeps/powerpc/powerpc64/dl-machine.h | 4 ++--
sysdeps/sh/dl-machine.h | 7 ++-----
7 files changed, 24 insertions(+), 41 deletions(-)
diff --git a/elf/do-rel.h b/elf/do-rel.h
index 75017c6460..e817d0da48 100644
--- a/elf/do-rel.h
+++ b/elf/do-rel.h
@@ -102,16 +102,7 @@ elf_dynamic_do_Rel (struct link_map_private *map, struct r_scope_elem *scope[],
else
#endif
{
- /* 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 (GL(dl_rtld_map));
-# endif
- if (map != &GL(dl_rtld_map)) /* Already done in rtld itself. */
+ if (!is_rtld_link_map (map)) /* Already done in rtld itself. */
# if !defined DO_RELA || defined ELF_MACHINE_REL_RELATIVE
/* Rela platforms get the offset from r_addend and this must
be copied in the relocation address. Therefore we can skip
diff --git a/elf/dynamic-link.h b/elf/dynamic-link.h
index 2f72240b6a..8f4d096182 100644
--- a/elf/dynamic-link.h
+++ b/elf/dynamic-link.h
@@ -190,7 +190,7 @@ elf_machine_lazy_rel (struct link_map_private *map,
do { \
int edr_lazy = elf_machine_runtime_setup ((map), (scope), (lazy), \
(consider_profile)); \
- if (((map) != &GL(dl_rtld_map) || DO_RTLD_BOOTSTRAP)) \
+ if ((!is_rtld_link_map (map) || DO_RTLD_BOOTSTRAP)) \
ELF_DYNAMIC_DO_RELR (map); \
ELF_DYNAMIC_DO_REL ((map), (scope), edr_lazy, skip_ifunc); \
ELF_DYNAMIC_DO_RELA ((map), (scope), edr_lazy, skip_ifunc); \
diff --git a/sysdeps/arm/dl-machine.h b/sysdeps/arm/dl-machine.h
index a4b0cde4a0..13252e449c 100644
--- a/sysdeps/arm/dl-machine.h
+++ b/sysdeps/arm/dl-machine.h
@@ -354,16 +354,7 @@ elf_machine_rel (struct link_map_private *map, struct r_scope_elem *scope[],
Elf32_Addr x;
} __attribute__ ((packed, may_alias));
# 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 fb74e9b939..1800469aa6 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -406,8 +406,10 @@ struct rtld_global
/* List of search directories. */
EXTERN struct r_search_path_elem *_dl_all_dirs;
+#ifdef SHARED
/* Structure describing the dynamic linker itself. */
EXTERN struct link_map_private _dl_rtld_map;
+#endif
#if !PTHREAD_IN_LIBC && defined SHARED \
&& defined __rtld_lock_default_lock_recursive
@@ -1326,6 +1328,18 @@ dl_init_static_tls (struct link_map_private *map)
void __rtld_static_init (struct link_map_private *map) attribute_hidden;
#endif
+/* Returns true if MAP is the dynamic loader itself. Statically
+ linked binaries do not have a dynamic loader, so return false. */
+static inline bool
+is_rtld_link_map (const struct link_map_private *map)
+{
+#ifdef SHARED
+ return map == &GL (dl_rtld_map);
+#else
+ return false;
+#endif
+}
+
/* Return true if the ld.so copy in this namespace is actually active
and working. If false, the dl_open/dlfcn hooks have to be used to
call into the outer dynamic linker (which happens after static
diff --git a/sysdeps/mips/dl-machine.h b/sysdeps/mips/dl-machine.h
index b7b1705f65..2eb01ca7cb 100644
--- a/sysdeps/mips/dl-machine.h
+++ b/sysdeps/mips/dl-machine.h
@@ -436,16 +436,6 @@ elf_machine_reloc (struct link_map_private *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_private *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_private *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_public.l_addr;
@@ -752,7 +742,7 @@ elf_machine_got_rel (struct link_map_private *map,
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 3894c6eaa9..0c20bc564f 100644
--- a/sysdeps/powerpc/powerpc64/dl-machine.h
+++ b/sysdeps/powerpc/powerpc64/dl-machine.h
@@ -515,7 +515,7 @@ elf_machine_fixup_plt (struct link_map_private *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_public.l_addr;
@@ -641,7 +641,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 (sym_map)
# endif
&& !sym_map->l_relocated)
{
diff --git a/sysdeps/sh/dl-machine.h b/sysdeps/sh/dl-machine.h
index 582b3b31d5..f575fd59c8 100644
--- a/sysdeps/sh/dl-machine.h
+++ b/sysdeps/sh/dl-machine.h
@@ -283,7 +283,7 @@ elf_machine_rela (struct link_map_private *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)
@@ -386,10 +386,7 @@ elf_machine_rela (struct link_map_private *map, struct r_scope_elem *scope[],
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
--
2.41.0
next prev parent reply other threads:[~2023-07-04 20:03 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-04 20:02 [PATCH 00/33] RFC: RELRO link maps Florian Weimer
2023-07-04 20:02 ` [PATCH 01/33] support: Add <support/memprobe.h> for protection flags probing Florian Weimer
2023-07-04 20:02 ` [PATCH 02/33] misc: Enable internal use of memory protection keys Florian Weimer
2023-07-04 20:02 ` [PATCH 03/33] elf: Remove _dl_sysdep_open_object hook function Florian Weimer
2023-07-04 20:02 ` [PATCH 04/33] elf: Eliminate second loop in find_version in dl-version.c Florian Weimer
2023-07-04 20:02 ` [PATCH 05/33] elf: In rtld_setup_main_map, assume ld.so has a DYNAMIC segment Florian Weimer
2023-07-04 20:02 ` [PATCH 06/33] elf: Remove version assert in check_match in elf/dl-lookup.c Florian Weimer
2023-07-04 20:02 ` [PATCH 07/33] elf: Disambiguate some failures in _dl_load_cache_lookup Florian Weimer
2023-07-04 20:02 ` [PATCH 08/33] elf: Eliminate alloca in open_verify Florian Weimer
2023-07-04 20:02 ` [PATCH 09/33] Do not export <alloc_buffer.h> functions from libc Florian Weimer
2023-07-04 20:02 ` [PATCH 10/33] elf: Make <alloc_buffer.h> usable in ld.so Florian Weimer
2023-07-04 20:03 ` [PATCH 11/33] elf: Merge the three implementations of _dl_dst_substitute Florian Weimer
2023-07-04 20:03 ` [PATCH 12/33] elf: _dl_find_object may return 1 during early startup (bug 30515) Florian Weimer
2023-07-04 20:03 ` [PATCH 13/33] elf: Move __rtld_malloc_init_stubs call into _dl_start_final Florian Weimer
2023-07-04 20:03 ` [PATCH 14/33] elf: Merge __dl_libc_freemem into __rtld_libc_freeres Florian Weimer
2023-07-04 20:03 ` [PATCH 15/33] elf: Use struct link_map_private for the internal link map Florian Weimer
2023-07-04 20:03 ` [PATCH 16/33] elf: Remove run-time-writable fields from struct link_map_private Florian Weimer
2023-07-04 20:03 ` [PATCH 17/33] elf: Move l_tls_offset into read-write part of link map Florian Weimer
2023-07-04 20:03 ` [PATCH 18/33] elf: Allocate auditor state after read-write " Florian Weimer
2023-07-04 20:03 ` [PATCH 19/33] elf: Move link map fields used by dependency sorting to writable part Florian Weimer
2023-07-04 20:03 ` [PATCH 20/33] elf: Split _dl_lookup_map, _dl_map_new_object from _dl_map_object Florian Weimer
2023-07-04 20:03 ` [PATCH 21/33] elf: Add l_soname accessor function for DT_SONAME values Florian Weimer
2023-07-04 20:03 ` Florian Weimer [this message]
2023-07-04 20:03 ` [PATCH 23/33] elf: Introduce GLPM accessor for the protected memory area Florian Weimer
2023-07-04 20:04 ` [PATCH 24/33] elf: Bootstrap allocation for future protected memory allocator Florian Weimer
2023-07-04 20:04 ` [PATCH 25/33] elf: Implement a basic " Florian Weimer
2023-07-04 20:04 ` [PATCH 26/33] elf: Move most of the _dl_find_object data to the protected heap Florian Weimer
2023-07-04 20:04 ` [PATCH 27/33] elf: Switch to a region-based protected memory allocator Florian Weimer
2023-07-04 20:04 ` [PATCH 28/33] elf: Determine the caller link map in _dl_open Florian Weimer
2023-07-04 20:04 ` [PATCH 29/33] elf: Add fast path to dlopen for fully-opened maps Florian Weimer
2023-07-04 20:04 ` [PATCH 30/33] elf: Use _dl_find_object instead of _dl_find_dso_for_object in dlopen Florian Weimer
2023-07-04 20:04 ` [PATCH 31/33] elf: Put critical _dl_find_object pointers into protected memory area Florian Weimer
2023-07-04 20:04 ` [PATCH 32/33] elf: Add hash tables to speed up DT_NEEDED, dlopen lookups Florian Weimer
2023-07-04 20:04 ` [PATCH 33/33] elf: Use memory protection keys for the protected memory allocator Florian Weimer
2023-07-04 20:07 ` [PATCH 00/33] RFC: RELRO link maps Florian Weimer
2023-07-05 15:54 ` Carlos O'Donell
2023-07-05 15:57 ` Florian Weimer
2023-07-05 17:48 ` Carlos O'Donell
2023-07-05 17:58 ` Adhemerval Zanella Netto
2023-07-07 11:10 ` Florian Weimer
2023-07-07 12:42 ` Florian Weimer
2023-07-07 12:48 ` Adhemerval Zanella Netto
2023-07-07 13:18 ` Florian Weimer
2023-07-07 13:58 ` Adhemerval Zanella Netto
2023-07-07 14:55 ` Florian Weimer
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=943e9e8148b3f0213c272ce1970574cb536ebcc6.1688499219.git.fweimer@redhat.com \
--to=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
/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).