Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1 | From 1b97befbe693eb93a77b6098f6ae1394a53462f4 Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Wed, 18 Mar 2015 01:51:38 +0000 |
| 4 | Subject: [PATCH] nativesdk-glibc: Raise the size of arrays containing dl paths |
| 5 | |
| 6 | This patch puts the dynamic loader path in the binaries, SYSTEM_DIRS strings |
| 7 | and lengths as well as ld.so.cache path in the dynamic loader to specific |
| 8 | sections in memory. The sections that contain paths have been allocated a 4096 |
| 9 | byte section, which is the maximum path length in linux. This will allow the |
| 10 | relocating script to parse the ELF binary, detect the section and easily replace |
| 11 | the strings in a certain path. |
| 12 | |
| 13 | Upstream-Status: Inappropriate [SDK specific] |
| 14 | |
| 15 | Signed-off-by: Laurentiu Palcu <laurentiu.palcu@intel.com> |
| 16 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 17 | --- |
| 18 | elf/dl-cache.c | 4 ++++ |
| 19 | elf/dl-load.c | 4 ++-- |
| 20 | elf/interp.c | 2 +- |
| 21 | elf/ldconfig.c | 3 +++ |
| 22 | elf/rtld.c | 5 +++-- |
| 23 | iconv/gconv_conf.c | 2 +- |
| 24 | sysdeps/generic/dl-cache.h | 4 ---- |
| 25 | 7 files changed, 14 insertions(+), 10 deletions(-) |
| 26 | |
| 27 | diff --git a/elf/dl-cache.c b/elf/dl-cache.c |
| 28 | index 3eedd9afcf..efdfe5cae7 100644 |
| 29 | --- a/elf/dl-cache.c |
| 30 | +++ b/elf/dl-cache.c |
| 31 | @@ -133,6 +133,10 @@ do \ |
| 32 | while (0) |
| 33 | |
| 34 | |
| 35 | +const char LD_SO_CACHE[4096] __attribute__ ((section (".ldsocache"))) = |
| 36 | + SYSCONFDIR "/ld.so.cache"; |
| 37 | + |
| 38 | + |
| 39 | int |
| 40 | _dl_cache_libcmp (const char *p1, const char *p2) |
| 41 | { |
| 42 | diff --git a/elf/dl-load.c b/elf/dl-load.c |
| 43 | index 7cb8a86fab..e32d4aa936 100644 |
| 44 | --- a/elf/dl-load.c |
| 45 | +++ b/elf/dl-load.c |
| 46 | @@ -110,8 +110,8 @@ static size_t max_capstrlen attribute_relro; |
| 47 | gen-trusted-dirs.awk. */ |
| 48 | #include "trusted-dirs.h" |
| 49 | |
| 50 | -static const char system_dirs[] = SYSTEM_DIRS; |
| 51 | -static const size_t system_dirs_len[] = |
| 52 | +static const char system_dirs[4096] __attribute__ ((section (".sysdirs"))) = SYSTEM_DIRS; |
| 53 | +volatile static const size_t system_dirs_len[] __attribute__ ((section (".sysdirslen"))) = |
| 54 | { |
| 55 | SYSTEM_DIRS_LEN |
| 56 | }; |
| 57 | diff --git a/elf/interp.c b/elf/interp.c |
| 58 | index 331cc1df48..885b2d9476 100644 |
| 59 | --- a/elf/interp.c |
| 60 | +++ b/elf/interp.c |
| 61 | @@ -18,5 +18,5 @@ |
| 62 | |
| 63 | #include <runtime-linker.h> |
| 64 | |
| 65 | -const char __invoke_dynamic_linker__[] __attribute__ ((section (".interp"))) |
| 66 | +const char __invoke_dynamic_linker__[4096] __attribute__ ((section (".interp"))) |
| 67 | = RUNTIME_LINKER; |
| 68 | diff --git a/elf/ldconfig.c b/elf/ldconfig.c |
| 69 | index 681ed78496..8833ed0a6b 100644 |
| 70 | --- a/elf/ldconfig.c |
| 71 | +++ b/elf/ldconfig.c |
| 72 | @@ -168,6 +168,9 @@ static struct argp argp = |
| 73 | options, parse_opt, NULL, doc, NULL, more_help, NULL |
| 74 | }; |
| 75 | |
| 76 | + |
| 77 | +extern const char LD_SO_CACHE[4096] __attribute__ ((section (".ldsocache"))); |
| 78 | + |
| 79 | /* Check if string corresponds to an important hardware capability or |
| 80 | a platform. */ |
| 81 | static int |
| 82 | diff --git a/elf/rtld.c b/elf/rtld.c |
| 83 | index 553cfbd1b7..39347c2c03 100644 |
| 84 | --- a/elf/rtld.c |
| 85 | +++ b/elf/rtld.c |
| 86 | @@ -175,6 +175,7 @@ dso_name_valid_for_suid (const char *p) |
| 87 | } |
| 88 | return *p != '\0'; |
| 89 | } |
| 90 | +extern const char LD_SO_CACHE[4096] __attribute__ ((section (".ldsocache"))); |
| 91 | |
| 92 | /* LD_AUDIT variable contents. Must be processed before the |
| 93 | audit_list below. */ |
| 94 | @@ -1222,13 +1223,13 @@ of this helper program; chances are you did not intend to run this program.\n\ |
| 95 | --list list all dependencies and how they are resolved\n\ |
| 96 | --verify verify that given object really is a dynamically linked\n\ |
| 97 | object we can handle\n\ |
| 98 | - --inhibit-cache Do not use " LD_SO_CACHE "\n\ |
| 99 | + --inhibit-cache Do not use %s\n\ |
| 100 | --library-path PATH use given PATH instead of content of the environment\n\ |
| 101 | variable LD_LIBRARY_PATH\n\ |
| 102 | --inhibit-rpath LIST ignore RUNPATH and RPATH information in object names\n\ |
| 103 | in LIST\n\ |
| 104 | --audit LIST use objects named in LIST as auditors\n\ |
| 105 | - --preload LIST preload objects named in LIST\n"); |
| 106 | + --preload LIST preload objects named in LIST\n", LD_SO_CACHE); |
| 107 | |
| 108 | ++_dl_skip_args; |
| 109 | --_dl_argc; |
| 110 | diff --git a/iconv/gconv_conf.c b/iconv/gconv_conf.c |
| 111 | index 735bd1f2d5..25100ba666 100644 |
| 112 | --- a/iconv/gconv_conf.c |
| 113 | +++ b/iconv/gconv_conf.c |
| 114 | @@ -36,7 +36,7 @@ |
| 115 | |
| 116 | |
| 117 | /* This is the default path where we look for module lists. */ |
| 118 | -static const char default_gconv_path[] = GCONV_PATH; |
| 119 | +static char default_gconv_path[4096] __attribute__ ((section (".gccrelocprefix"))) = GCONV_PATH; |
| 120 | |
| 121 | /* Type to represent search path. */ |
| 122 | struct path_elem |
| 123 | diff --git a/sysdeps/generic/dl-cache.h b/sysdeps/generic/dl-cache.h |
| 124 | index 6b310e9e15..3877311df4 100644 |
| 125 | --- a/sysdeps/generic/dl-cache.h |
| 126 | +++ b/sysdeps/generic/dl-cache.h |
| 127 | @@ -27,10 +27,6 @@ |
| 128 | ((flags) == 1 || (flags) == _DL_CACHE_DEFAULT_ID) |
| 129 | #endif |
| 130 | |
| 131 | -#ifndef LD_SO_CACHE |
| 132 | -# define LD_SO_CACHE SYSCONFDIR "/ld.so.cache" |
| 133 | -#endif |
| 134 | - |
| 135 | #ifndef add_system_dir |
| 136 | # define add_system_dir(dir) add_dir (dir) |
| 137 | #endif |