summaryrefslogtreecommitdiff
path: root/elf/dl-reloc-static-pie.c
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2021-08-22 16:29:16 -0700
committerFangrui Song <maskray@google.com>2021-08-22 16:29:16 -0700
commit5544862ebedb02e75b6b333c2d44ad9eb51ea36e (patch)
treeb0232a628501d4028e0469ed1152df837d086a8d /elf/dl-reloc-static-pie.c
parentbca0f5cbc9257c13322b99e55235c4f21ba0bd82 (diff)
downloadglibc-maskray/nesting.tar.gz
elf: Avoid nested functions in the loader (aarch64, x86-64) [BZ #27220]maskray/nesting
dynamic-link.h is included more than once in some elf/ files (rtld.c, dl-conflict.c, dl-reloc.c, dl-reloc-static-pie.c) and uses GCC nested functions. This harms readability and the nested functions usage is the biggest obstacle prevents CC=clang (which doesn't support the feature). To un-nest elf_machine_rela, the key idea is to pass the variable in the containing scope as an extra argument. Stan Shebs implemented this in the google/grte/v5-2.27/master branch. This patch squashes and cleans up the commits. This patch just fixes aarch64 and x86-64: they use the `#ifndef NESTING` branch to avoid nested functions. The `#ifdef NESTING` branch is used by all other ports whose dl-machine.h files haven't been migrated. For the time being, there is some duplicated code. `#ifdef NESTING` dispatches can be removed in the future when all arches are migrated. I can fix powerpc64, riscv, and other arches subsequently. Migrating all ports at once is just too risky. Also, appreciate help from arch maintainers. Tested on {aarch64,x86_64}-linux-gnu (!NESTING) and powerpc64le-linux-gnu (NESTING).
Diffstat (limited to 'elf/dl-reloc-static-pie.c')
-rw-r--r--elf/dl-reloc-static-pie.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/elf/dl-reloc-static-pie.c b/elf/dl-reloc-static-pie.c
index d5bd2f31e9..0ab4613021 100644
--- a/elf/dl-reloc-static-pie.c
+++ b/elf/dl-reloc-static-pie.c
@@ -23,6 +23,13 @@
#include <ldsodefs.h>
#include "dynamic-link.h"
+#ifndef NESTING
+# define STATIC_PIE_BOOTSTRAP
+# define BOOTSTRAP_MAP (main_map)
+# define RESOLVE_MAP(sym, version, flags) BOOTSTRAP_MAP
+# include "dynamic-link.h"
+#endif /* n NESTING */
+
/* Relocate static executable with PIE. */
void
@@ -30,10 +37,12 @@ _dl_relocate_static_pie (void)
{
struct link_map *main_map = _dl_get_dl_main_map ();
+#ifdef NESTING
# define STATIC_PIE_BOOTSTRAP
# define BOOTSTRAP_MAP (main_map)
# define RESOLVE_MAP(sym, version, flags) BOOTSTRAP_MAP
# include "dynamic-link.h"
+#endif /* NESTING */
/* Figure out the run-time load address of static PIE. */
main_map->l_addr = elf_machine_load_address ();
@@ -48,7 +57,11 @@ _dl_relocate_static_pie (void)
/* Relocate ourselves so we can do normal function calls and
data access using the global offset table. */
- ELF_DYNAMIC_RELOCATE (main_map, 0, 0, 0);
+ ELF_DYNAMIC_RELOCATE (main_map, 0, 0, 0
+#ifndef NESTING
+ , main_map
+#endif
+ );
main_map->l_relocated = 1;
/* Initialize _r_debug. */