Skip to content

Commit d786960

Browse files
liblol: search lol libs before all other pathes
We put lol libs and other necessary libs which need to be preferred before executables' RPATH and LD_LIBRARY_PATH. Also provide /opt/lol/local/preload-lib and /opt/lol/local/lib for our users to add their own libs.
1 parent f1a7793 commit d786960

File tree

5 files changed

+105
-29
lines changed

5 files changed

+105
-29
lines changed

autobuild/build

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ rootsbindir = \${exec_prefix}/sbin
6161
complocaledir = /usr/lib/locale
6262
localtime-file = /etc/localtime
6363
sysconfdir = $LOLPREFIX/etc
64-
user-defined-trusted-dirs-pre = $LOLPREFIX/support/lib/$OWTARGET
65-
user-defined-trusted-dirs = $LOLPREFIX/lib/$OWTARGET $LOLPREFIX/lib
64+
user-defined-trusted-dirs-pre = $LOLPREFIX/local/preload-lib $LOLPREFIX/support/lib/$OWTARGET
65+
user-defined-trusted-dirs = $LOLPREFIX/local/lib $LOLPREFIX/lib/$OWTARGET $LOLPREFIX/lib
6666
6767
CFLAGS = -pipe $cflags_common
6868
ASFLAGS = -pipe $cflags_common
@@ -195,5 +195,11 @@ abinfo "Building Glibc ..."
195195
glibc_source
196196
glibc_build
197197

198+
abinfo "Making symlinks for system provided libs ..."
199+
system_libs_prio=("/usr/lib/libstdc++.so.6")
200+
for i in "${system_libs_prio[@]}"; do
201+
ln -sfv "$i" "$PKGDIR$LOLPREFIX/support/lib/$OWTARGET/"
202+
done
203+
198204
abinfo "Installing package hooks ..."
199205
install_hooks

autobuild/patches/glibc/0009-able-to-prepend-trusted-dirs.patch

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
From ab1f75bb30336948c3de6a8355994314b3fdc4a3 Mon Sep 17 00:00:00 2001
2+
From: Miao Wang <[email protected]>
3+
Date: Sun, 14 Jan 2024 13:28:41 +0800
4+
Subject: [PATCH 09/10] prepend trusted-dirs
5+
6+
and search prepended trusted-dirs before other pathes
7+
---
8+
elf/Makefile | 3 ++-
9+
elf/dl-load.c | 26 ++++++++++++++++++++++++--
10+
2 files changed, 26 insertions(+), 3 deletions(-)
11+
12+
diff --git a/elf/Makefile b/elf/Makefile
13+
index c00e2ccf..ed1f709c 100644
14+
--- a/elf/Makefile
15+
+++ b/elf/Makefile
16+
@@ -1355,9 +1355,10 @@ endif
17+
$(objpfx)trusted-dirs.h: $(objpfx)trusted-dirs.st; @:
18+
$(objpfx)trusted-dirs.st: Makefile $(..)Makeconfig
19+
$(make-target-directory)
20+
- echo "$(subst :, ,$(default-rpath) $(user-defined-trusted-dirs))" \
21+
+ echo "$(subst :, ,$(user-defined-trusted-dirs-pre) $(default-rpath) $(user-defined-trusted-dirs))" \
22+
| $(AWK) -f gen-trusted-dirs.awk > ${@:st=T};
23+
echo '#define DL_DST_LIB "$(notdir $(slibdir))"' >> ${@:st=T}
24+
+ echo '#define SYSTEM_DIRS_PRE_COUNT $(words $(subst :, ,$(user-defined-trusted-dirs-pre)))' >> ${@:st=T}
25+
$(move-if-change) ${@:st=T} ${@:st=h}
26+
touch $@
27+
CPPFLAGS-dl-load.c += -I$(objpfx). -I$(csu-objpfx).
28+
diff --git a/elf/dl-load.c b/elf/dl-load.c
29+
index 9a87fda9..d11309f2 100644
30+
--- a/elf/dl-load.c
31+
+++ b/elf/dl-load.c
32+
@@ -123,6 +123,9 @@ static const size_t system_dirs_len[] =
33+
SYSTEM_DIRS_LEN
34+
};
35+
#define nsystem_dirs_len array_length (system_dirs_len)
36+
+#define normal_system_dirs_len (nsystem_dirs_len - SYSTEM_DIRS_PRE_COUNT)
37+
+
38+
+static_assert (SYSTEM_DIRS_PRE_COUNT < nsystem_dirs_len, "should have at least one system dir");
39+
40+
static bool
41+
is_trusted_path_normalize (const char *path, size_t len)
42+
@@ -723,7 +726,7 @@ _dl_init_paths (const char *llp, const char *source,
43+
44+
/* First set up the rest of the default search directory entries. */
45+
aelem = __rtld_search_dirs.dirs = (struct r_search_path_elem **)
46+
- malloc ((nsystem_dirs_len + 1) * sizeof (struct r_search_path_elem *));
47+
+ malloc ((nsystem_dirs_len + 2) * sizeof (struct r_search_path_elem *));
48+
if (__rtld_search_dirs.dirs == NULL)
49+
{
50+
errstring = N_("cannot create search path array");
51+
@@ -748,11 +751,17 @@ _dl_init_paths (const char *llp, const char *source,
52+
pelem = GL(dl_all_dirs) = __rtld_search_dirs.dirs[0];
53+
strp = system_dirs;
54+
idx = 0;
55+
+ aelem = &__rtld_search_dirs.dirs[normal_system_dirs_len + 1];
56+
57+
do
58+
{
59+
size_t cnt;
60+
61+
+ if (aelem == &__rtld_search_dirs.dirs[nsystem_dirs_len + 1]){
62+
+ *aelem = NULL;
63+
+ aelem = &__rtld_search_dirs.dirs[0];
64+
+ }
65+
+
66+
*aelem++ = pelem;
67+
68+
pelem->what = "system search path";
69+
@@ -2022,9 +2031,22 @@ _dl_map_object (struct link_map *loader, const char *name,
70+
71+
fd = -1;
72+
73+
+ if (SYSTEM_DIRS_PRE_COUNT > 0
74+
+ && ((l = loader ?: GL(dl_ns)[nsid]._ns_loaded) == NULL
75+
+ || __glibc_likely (!(l->l_flags_1 & DF_1_NODEFLIB)))
76+
+ && __rtld_search_dirs.dirs != (void *) -1)
77+
+ {
78+
+ struct r_search_path_struct pre_sp = {
79+
+ .dirs = &__rtld_search_dirs.dirs[normal_system_dirs_len + 1],
80+
+ .malloced = 0,
81+
+ };
82+
+ fd = open_path (name, namelen, mode, &pre_sp,
83+
+ &realname, &fb, l, LA_SER_DEFAULT, &found_other_class);
84+
+ }
85+
+
86+
/* When the object has the RUNPATH information we don't use any
87+
RPATHs. */
88+
- if (loader == NULL || loader->l_info[DT_RUNPATH] == NULL)
89+
+ if (fd == -1 && (loader == NULL || loader->l_info[DT_RUNPATH] == NULL))
90+
{
91+
/* This is the executable's map (if there is one). Make sure that
92+
we do not look at it twice. */
93+
--
94+
2.43.0
95+

autobuild/patches/glibc/0010-Add-___brk_addr-symbol.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From c2ef1e7fe9b5c0cec43197e440cc5b4a05bbde24 Mon Sep 17 00:00:00 2001
1+
From 8f53c5c593728dee6391cc064a1ebf89e3d70dd8 Mon Sep 17 00:00:00 2001
22
From: Miao Wang <[email protected]>
33
Date: Mon, 15 Jan 2024 04:16:47 +0800
44
Subject: [PATCH 10/10] Add ___brk_addr symbol

autobuild/patches/glibc/series

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
0006-add-syscall-fallback-for-stat-at.patch
77
0007-add-more-pthread-symbols.patch
88
0008-remove-clone3-for-compatibility-with-qq.patch
9-
0009-able-to-prepend-trusted-dirs.patch
9+
0009-prepend-trusted-dirs.patch
1010
0010-Add-___brk_addr-symbol.patch

0 commit comments

Comments
 (0)