Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20261022083502.2260111-1-mark.yang@lge.com>
Date: Thu, 22 Oct 2026 17:35:02 +0900
From: mark.yang@....com
To: musl@...ts.openwall.com
Cc: "mark.yang" <mark.yang@....com>
Subject: [PATCH] configure: add --sysconfdir for the dynamic linker path file

From: "mark.yang" <mark.yang@....com>

The dynamic linker looks for ld-musl-$ARCH.path in ../etc relative
to the directory of the program interpreter, so the location of the
path file is tied to where the dynamic linker is installed. A system
that puts /usr/lib/ld-musl-$ARCH.so.1 into PT_INTERP therefore reads
/usr/etc/ld-musl-$ARCH.path, while its configuration lives in /etc.

Add a --sysconfdir configure option to set the directory of the path
file independently of syslibdir.

Without the option nothing changes. Builds that already pass
--sysconfdir=/etc, which configure has ignored so far, now read
/etc/ld-musl-$ARCH.path. With the standard PT_INTERP this is the same
file as before.
---
 INSTALL        | 4 +++-
 Makefile       | 2 ++
 configure      | 6 +++++-
 ldso/dynlink.c | 5 +++++
 4 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/INSTALL b/INSTALL
index ddbbbb2f..9feda69b 100644
--- a/INSTALL
+++ b/INSTALL
@@ -161,7 +161,9 @@ used in the dynamic linker) containing a list of directories where you
 want the dynamic linker to search for shared libraries, separated by
 colons or newlines. If the dynamic linker has been installed in a
 non-default location, the path file also needs to reside at that
-location (../etc relative to the chosen syslibdir).
+location (../etc relative to the chosen syslibdir), unless
+--sysconfdir was given to configure, in which case the dynamic linker
+reads the path file from that directory.
 
 If you do not intend to use dynamic linking, you may disable it by
 passing --disable-shared to configure; this also cuts the build time
diff --git a/Makefile b/Makefile
index 3ad88b35..d038feb8 100644
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,7 @@ prefix = /usr/local/musl
 includedir = $(prefix)/include
 libdir = $(prefix)/lib
 syslibdir = /lib
+sysconfdir =
 
 MALLOC_DIR = mallocng
 SRC_DIRS = $(addprefix $(srcdir)/,src/* src/malloc/$(MALLOC_DIR) crt ldso $(COMPAT_SRC_DIRS))
@@ -48,6 +49,7 @@ CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc
 
 CFLAGS_ALL = $(CFLAGS_C99FSE)
 CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I$(srcdir)/arch/$(ARCH) -I$(srcdir)/arch/generic -Iobj/src/internal -I$(srcdir)/src/include -I$(srcdir)/src/internal -Iobj/include -I$(srcdir)/include
+CFLAGS_ALL += $(if $(sysconfdir),-DSYSCONFDIR='"$(sysconfdir)"')
 CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS_AUTO) $(CFLAGS)
 
 LDFLAGS_ALL = $(LDFLAGS_AUTO) $(LDFLAGS)
diff --git a/configure b/configure
index bc9fbe48..2b443ab3 100755
--- a/configure
+++ b/configure
@@ -21,6 +21,7 @@ Fine tuning of the installation directories:
   --libdir=DIR            library files for the linker [PREFIX/lib]
   --includedir=DIR        include files for the C compiler [PREFIX/include]
   --syslibdir=DIR         location for the dynamic linker [/lib]
+  --sysconfdir=DIR        location for the dynamic linker path file [SYSLIBDIR/../etc]
 
 System types:
   --target=TARGET         configure to run on target TARGET [detected]
@@ -130,6 +131,7 @@ bindir='$(exec_prefix)/bin'
 libdir='$(prefix)/lib'
 includedir='$(prefix)/include'
 syslibdir='/lib'
+sysconfdir=
 tools=
 tool_libs=
 build=
@@ -154,6 +156,7 @@ case "$arg" in
 --libdir=*) libdir=${arg#*=} ;;
 --includedir=*) includedir=${arg#*=} ;;
 --syslibdir=*) syslibdir=${arg#*=} ;;
+--sysconfdir=*) sysconfdir=${arg#*=} ;;
 --enable-shared|--enable-shared=yes) shared=yes ;;
 --disable-shared|--enable-shared=no) shared=no ;;
 --enable-static|--enable-static=yes) static=yes ;;
@@ -190,7 +193,7 @@ LIBCC=*) LIBCC=${arg#*=} ;;
 esac
 done
 
-for i in srcdir prefix exec_prefix bindir libdir includedir syslibdir ; do
+for i in srcdir prefix exec_prefix bindir libdir includedir syslibdir sysconfdir ; do
 stripdir $i
 done
 
@@ -814,6 +817,7 @@ bindir = $bindir
 libdir = $libdir
 includedir = $includedir
 syslibdir = $syslibdir
+sysconfdir = $sysconfdir
 CC = $CC
 CFLAGS = $CFLAGS
 CFLAGS_AUTO = $CFLAGS_AUTO
diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index 10471b23..20d78ba5 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -1127,6 +1127,10 @@ static struct dso *load_library(const char *name, struct dso *needed_by)
 		}
 		if (fd == -1) {
 			if (!sys_path) {
+#ifdef SYSCONFDIR
+				const char etc_ldso_path[] =
+					SYSCONFDIR "/ld-musl-" LDSO_ARCH ".path";
+#else
 				char *prefix = 0;
 				size_t prefix_len;
 				if (ldso.name[0]=='/') {
@@ -1146,6 +1150,7 @@ static struct dso *load_library(const char *name, struct dso *needed_by)
 				snprintf(etc_ldso_path, sizeof etc_ldso_path,
 					"%.*s/etc/ld-musl-" LDSO_ARCH ".path",
 					(int)prefix_len, prefix);
+#endif
 				fd = open(etc_ldso_path, O_RDONLY|O_CLOEXEC);
 				if (fd>=0) {
 					size_t n = 0;

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.