blob: 2899c0b845ac16aae6e4af0677530c82a2497bf8 [file] [log] [blame]
Patrick Williams864cc432023-02-09 14:54:44 -06001From 66e971a785aae80ba838a2604c679db70cbb8b3b Mon Sep 17 00:00:00 2001
Andrew Geissler82c905d2020-04-13 13:39:40 -05002From: Khem Raj <raj.khem@gmail.com>
3Date: Wed, 18 Mar 2015 01:51:38 +0000
Andrew Geisslerd1e89492021-02-12 15:35:20 -06004Subject: [PATCH] nativesdk-glibc: Raise the size of arrays containing dl paths
Andrew Geissler82c905d2020-04-13 13:39:40 -05005
6This patch puts the dynamic loader path in the binaries, SYSTEM_DIRS strings
7and lengths as well as ld.so.cache path in the dynamic loader to specific
8sections in memory. The sections that contain paths have been allocated a 4096
9byte section, which is the maximum path length in linux. This will allow the
10relocating script to parse the ELF binary, detect the section and easily replace
11the strings in a certain path.
12
13Upstream-Status: Inappropriate [SDK specific]
14
15Signed-off-by: Laurentiu Palcu <laurentiu.palcu@intel.com>
16Signed-off-by: Khem Raj <raj.khem@gmail.com>
17---
18 elf/dl-cache.c | 4 ++++
19 elf/dl-load.c | 4 ++--
Andrew Geisslerd1e89492021-02-12 15:35:20 -060020 elf/dl-usage.c | 6 ++++--
Andrew Geissler82c905d2020-04-13 13:39:40 -050021 elf/interp.c | 2 +-
Patrick Williams864cc432023-02-09 14:54:44 -060022 elf/ldconfig.c | 2 ++
Andrew Geisslerd1e89492021-02-12 15:35:20 -060023 elf/rtld.c | 1 +
Andrew Geissler82c905d2020-04-13 13:39:40 -050024 iconv/gconv_conf.c | 2 +-
25 sysdeps/generic/dl-cache.h | 4 ----
Patrick Williams864cc432023-02-09 14:54:44 -060026 8 files changed, 15 insertions(+), 10 deletions(-)
Andrew Geissler82c905d2020-04-13 13:39:40 -050027
28diff --git a/elf/dl-cache.c b/elf/dl-cache.c
Patrick Williams864cc432023-02-09 14:54:44 -060029index 07c054b11a..0fa36548b0 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -050030--- a/elf/dl-cache.c
31+++ b/elf/dl-cache.c
Patrick Williams92b42cb2022-09-03 06:53:57 -050032@@ -352,6 +352,10 @@ search_cache (const char *string_table, uint32_t string_table_size,
Andrew Geisslerd1e89492021-02-12 15:35:20 -060033 return best;
34 }
Andrew Geissler82c905d2020-04-13 13:39:40 -050035
36+const char LD_SO_CACHE[4096] __attribute__ ((section (".ldsocache"))) =
37+ SYSCONFDIR "/ld.so.cache";
38+
39+
40 int
41 _dl_cache_libcmp (const char *p1, const char *p2)
42 {
43diff --git a/elf/dl-load.c b/elf/dl-load.c
Patrick Williams864cc432023-02-09 14:54:44 -060044index e514bdcc21..c43747a3a8 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -050045--- a/elf/dl-load.c
46+++ b/elf/dl-load.c
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000047@@ -117,8 +117,8 @@ enum { ncapstr = 1, max_capstrlen = 0 };
Andrew Geissler82c905d2020-04-13 13:39:40 -050048 gen-trusted-dirs.awk. */
49 #include "trusted-dirs.h"
50
51-static const char system_dirs[] = SYSTEM_DIRS;
52-static const size_t system_dirs_len[] =
53+static const char system_dirs[4096] __attribute__ ((section (".sysdirs"))) = SYSTEM_DIRS;
54+volatile static const size_t system_dirs_len[] __attribute__ ((section (".sysdirslen"))) =
55 {
56 SYSTEM_DIRS_LEN
57 };
Andrew Geisslerd1e89492021-02-12 15:35:20 -060058diff --git a/elf/dl-usage.c b/elf/dl-usage.c
Patrick Williams864cc432023-02-09 14:54:44 -060059index 53535c1583..3ba7d9d200 100644
Andrew Geisslerd1e89492021-02-12 15:35:20 -060060--- a/elf/dl-usage.c
61+++ b/elf/dl-usage.c
62@@ -25,6 +25,8 @@
63 #include <dl-procinfo.h>
64 #include <dl-hwcaps.h>
65
66+extern const char LD_SO_CACHE[4096] __attribute__ ((section (".ldsocache")));
67+
68 void
69 _dl_usage (const char *argv0, const char *wrong_option)
70 {
Patrick Williams864cc432023-02-09 14:54:44 -060071@@ -184,7 +186,7 @@ setting environment variables (which would be inherited by subprocesses).\n\
Andrew Geisslerd1e89492021-02-12 15:35:20 -060072 --list list all dependencies and how they are resolved\n\
73 --verify verify that given object really is a dynamically linked\n\
74 object we can handle\n\
75- --inhibit-cache Do not use " LD_SO_CACHE "\n\
76+ --inhibit-cache Do not use %s\n\
77 --library-path PATH use given PATH instead of content of the environment\n\
78 variable LD_LIBRARY_PATH\n\
79 --glibc-hwcaps-prepend LIST\n\
Patrick Williams864cc432023-02-09 14:54:44 -060080@@ -207,7 +209,7 @@ setting environment variables (which would be inherited by subprocesses).\n\
Andrew Geisslerd1e89492021-02-12 15:35:20 -060081 \n\
82 This program interpreter self-identifies as: " RTLD "\n\
83 ",
84- argv0);
85+ argv0, LD_SO_CACHE);
86 print_search_path_for_help (state);
87 print_hwcaps_subdirectories (state);
Patrick Williams864cc432023-02-09 14:54:44 -060088 _exit (EXIT_SUCCESS);
Andrew Geissler82c905d2020-04-13 13:39:40 -050089diff --git a/elf/interp.c b/elf/interp.c
Patrick Williams864cc432023-02-09 14:54:44 -060090index ae21ae0cb3..b168e6da66 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -050091--- a/elf/interp.c
92+++ b/elf/interp.c
93@@ -18,5 +18,5 @@
94
95 #include <runtime-linker.h>
96
97-const char __invoke_dynamic_linker__[] __attribute__ ((section (".interp")))
98+const char __invoke_dynamic_linker__[4096] __attribute__ ((section (".interp")))
99 = RUNTIME_LINKER;
100diff --git a/elf/ldconfig.c b/elf/ldconfig.c
Patrick Williams864cc432023-02-09 14:54:44 -0600101index 166dccb528..8dda23c92c 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -0500102--- a/elf/ldconfig.c
103+++ b/elf/ldconfig.c
Patrick Williams864cc432023-02-09 14:54:44 -0600104@@ -150,6 +150,8 @@ static struct argp argp =
Andrew Geissler82c905d2020-04-13 13:39:40 -0500105 options, parse_opt, NULL, doc, NULL, more_help, NULL
106 };
107
Andrew Geissler82c905d2020-04-13 13:39:40 -0500108+extern const char LD_SO_CACHE[4096] __attribute__ ((section (".ldsocache")));
109+
Patrick Williams864cc432023-02-09 14:54:44 -0600110 /* Handle program arguments. */
111 static error_t
112 parse_opt (int key, char *arg, struct argp_state *state)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500113diff --git a/elf/rtld.c b/elf/rtld.c
Patrick Williams864cc432023-02-09 14:54:44 -0600114index b8467f37cf..be7bd08bc3 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -0500115--- a/elf/rtld.c
116+++ b/elf/rtld.c
Patrick Williams864cc432023-02-09 14:54:44 -0600117@@ -190,6 +190,7 @@ dso_name_valid_for_suid (const char *p)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500118 }
119 return *p != '\0';
120 }
121+extern const char LD_SO_CACHE[4096] __attribute__ ((section (".ldsocache")));
122
Andrew Geissler635e0e42020-08-21 15:58:33 -0500123 static void
124 audit_list_init (struct audit_list *list)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500125diff --git a/iconv/gconv_conf.c b/iconv/gconv_conf.c
Patrick Williams864cc432023-02-09 14:54:44 -0600126index 21165a558a..3dd67b0ea2 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -0500127--- a/iconv/gconv_conf.c
128+++ b/iconv/gconv_conf.c
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000129@@ -35,7 +35,7 @@
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500130 #include <gconv_parseconfdir.h>
Andrew Geissler82c905d2020-04-13 13:39:40 -0500131
132 /* This is the default path where we look for module lists. */
133-static const char default_gconv_path[] = GCONV_PATH;
134+static char default_gconv_path[4096] __attribute__ ((section (".gccrelocprefix"))) = GCONV_PATH;
135
136 /* Type to represent search path. */
137 struct path_elem
138diff --git a/sysdeps/generic/dl-cache.h b/sysdeps/generic/dl-cache.h
Patrick Williams864cc432023-02-09 14:54:44 -0600139index bd39ff7fb7..38f9e2ad57 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -0500140--- a/sysdeps/generic/dl-cache.h
141+++ b/sysdeps/generic/dl-cache.h
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600142@@ -34,10 +34,6 @@
Andrew Geissler82c905d2020-04-13 13:39:40 -0500143 ((flags) == 1 || (flags) == _DL_CACHE_DEFAULT_ID)
144 #endif
145
146-#ifndef LD_SO_CACHE
147-# define LD_SO_CACHE SYSCONFDIR "/ld.so.cache"
148-#endif
149-
150 #ifndef add_system_dir
151 # define add_system_dir(dir) add_dir (dir)
152 #endif