git: 8cc44a1e59f6 - main - rtld: add support for the $LIB token

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Fri, 11 Nov 2022 10:06:48 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=8cc44a1e59f648eb5bea5afe6d9aa1d7f927c9d7

commit 8cc44a1e59f648eb5bea5afe6d9aa1d7f927c9d7
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-11-10 16:35:00 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-11-11 10:06:30 +0000

    rtld: add support for the $LIB token
    
    similar to the same token in glibc.
    
    Requested and reviewed by:      bapt
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D37329
---
 libexec/rtld-elf/rtld.1       | 10 +++++++++-
 libexec/rtld-elf/rtld.c       |  2 ++
 libexec/rtld-elf/rtld_paths.h |  5 +++++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/libexec/rtld-elf/rtld.1 b/libexec/rtld-elf/rtld.1
index c29d1fb1f90c..4ae811455609 100644
--- a/libexec/rtld-elf/rtld.1
+++ b/libexec/rtld-elf/rtld.1
@@ -28,7 +28,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd November 13, 2021
+.Dd November 10, 2022
 .Dt RTLD 1
 .Os
 .Sh NAME
@@ -76,6 +76,14 @@ Translated to the name of the operating system implementation.
 Translated to the release level of the operating system.
 .It Pa $PLATFORM
 Translated to the machine hardware platform.
+.It Pa $LIB
+Translated to the system library path component on the platform.
+It is
+.Pa lib
+for native binaries, and typically
+.Pa lib32
+for compat32 binaries.
+Other translations might exist for other ABIs supported on the platform.
 .El
 .Pp
 The
diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index 2e99ba4d69cf..2a142d333740 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -1200,6 +1200,8 @@ static const struct {
 	{ .kw = "${OSREL}", .pass_obj = false, .subst = uts.release },
 	{ .kw = "$PLATFORM", .pass_obj = false, .subst = uts.machine },
 	{ .kw = "${PLATFORM}", .pass_obj = false, .subst = uts.machine },
+	{ .kw = "$LIB", .pass_obj = false, .subst = TOKEN_LIB },
+	{ .kw = "${LIB}", .pass_obj = false, .subst = TOKEN_LIB },
 };
 
 static char *
diff --git a/libexec/rtld-elf/rtld_paths.h b/libexec/rtld-elf/rtld_paths.h
index ae4d1c473271..c051db7b580f 100644
--- a/libexec/rtld-elf/rtld_paths.h
+++ b/libexec/rtld-elf/rtld_paths.h
@@ -45,6 +45,7 @@
 #define	_BASENAME_RTLD		_COMPAT32_BASENAME_RTLD
 #define	STANDARD_LIBRARY_PATH	"/lib32:/usr/lib32"
 #define	LD_			"LD_32_"
+#define	TOKEN_LIB		"lib32"
 #endif
 
 #ifndef _PATH_ELF_HINTS
@@ -75,6 +76,10 @@
 #define	LD_			"LD_"
 #endif
 
+#ifndef TOKEN_LIB
+#define	TOKEN_LIB		"lib"
+#endif
+
 #ifdef IN_RTLD
 extern const char *ld_elf_hints_default;
 extern const char *ld_path_libmap_conf;