blob: 14bcaf3ef9eb289dbc0a45f5db272d3ec82a76ed [file] [log] [blame]
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001From 88a31cd08801df53249963f3b26c7dbcee6ae2f8 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 +-
22 elf/ldconfig.c | 3 +++
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 ----
Andrew Geisslerd1e89492021-02-12 15:35:20 -060026 8 files changed, 16 insertions(+), 10 deletions(-)
Andrew Geissler82c905d2020-04-13 13:39:40 -050027
28diff --git a/elf/dl-cache.c b/elf/dl-cache.c
Patrick Williams0ca19cc2021-08-16 14:03:13 -050029index 2b8da8650d..3d9787bda4 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -050030--- a/elf/dl-cache.c
31+++ b/elf/dl-cache.c
Patrick Williams0ca19cc2021-08-16 14:03:13 -050032@@ -355,6 +355,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
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000044index daa3af6c51..e323952993 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 Williams0ca19cc2021-08-16 14:03:13 -050059index 5ad3a72559..88f26d3692 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 {
71@@ -244,7 +246,7 @@ setting environment variables (which would be inherited by subprocesses).\n\
72 --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 Williams0ca19cc2021-08-16 14:03:13 -050080@@ -267,7 +269,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);
88 print_legacy_hwcap_directories ();
Andrew Geissler82c905d2020-04-13 13:39:40 -050089diff --git a/elf/interp.c b/elf/interp.c
Andrew Geisslerd1e89492021-02-12 15:35:20 -060090index 91966702ca..dc86c20e83 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
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000101index 101d56ac8e..33debef60a 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -0500102--- a/elf/ldconfig.c
103+++ b/elf/ldconfig.c
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000104@@ -176,6 +176,9 @@ static struct argp argp =
Andrew Geissler82c905d2020-04-13 13:39:40 -0500105 options, parse_opt, NULL, doc, NULL, more_help, NULL
106 };
107
108+
109+extern const char LD_SO_CACHE[4096] __attribute__ ((section (".ldsocache")));
110+
111 /* Check if string corresponds to an important hardware capability or
112 a platform. */
113 static int
114diff --git a/elf/rtld.c b/elf/rtld.c
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000115index 4b09e84b0d..56d93ff616 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -0500116--- a/elf/rtld.c
117+++ b/elf/rtld.c
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000118@@ -193,6 +193,7 @@ dso_name_valid_for_suid (const char *p)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500119 }
120 return *p != '\0';
121 }
122+extern const char LD_SO_CACHE[4096] __attribute__ ((section (".ldsocache")));
123
Andrew Geissler635e0e42020-08-21 15:58:33 -0500124 static void
125 audit_list_init (struct audit_list *list)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500126diff --git a/iconv/gconv_conf.c b/iconv/gconv_conf.c
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000127index 077082af66..46b6152455 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -0500128--- a/iconv/gconv_conf.c
129+++ b/iconv/gconv_conf.c
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000130@@ -35,7 +35,7 @@
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500131 #include <gconv_parseconfdir.h>
Andrew Geissler82c905d2020-04-13 13:39:40 -0500132
133 /* This is the default path where we look for module lists. */
134-static const char default_gconv_path[] = GCONV_PATH;
135+static char default_gconv_path[4096] __attribute__ ((section (".gccrelocprefix"))) = GCONV_PATH;
136
137 /* Type to represent search path. */
138 struct path_elem
139diff --git a/sysdeps/generic/dl-cache.h b/sysdeps/generic/dl-cache.h
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600140index 964d50a486..94bf68ca9d 100644
Andrew Geissler82c905d2020-04-13 13:39:40 -0500141--- a/sysdeps/generic/dl-cache.h
142+++ b/sysdeps/generic/dl-cache.h
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600143@@ -34,10 +34,6 @@
Andrew Geissler82c905d2020-04-13 13:39:40 -0500144 ((flags) == 1 || (flags) == _DL_CACHE_DEFAULT_ID)
145 #endif
146
147-#ifndef LD_SO_CACHE
148-# define LD_SO_CACHE SYSCONFDIR "/ld.so.cache"
149-#endif
150-
151 #ifndef add_system_dir
152 # define add_system_dir(dir) add_dir (dir)
153 #endif