Re: [PATCH] ld.so - add environment placeholders

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Alon,

Long after the fact...

On 22 August 2011 at 21:21, Alon Bar-Lev <alon.barlev@xxxxxxxxx> wrote:
> Discussion is here[1].
>
> Apparently there is a hidden feature in ld.so, it support variable
> placeholders within environment.
>
> This is great for supporting mixed multilib environment.
>
> Example:
>
> export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/my/\${LIB}"
>
> I believe this worth a documentation, as almost nobody knows this.
>
> ---
>  ENVIRONMENT
> +       ld.so understands the strings $ORIGIN, $LIB and $PLATFORM  (or  equiva‐
> +       lently   ${var})   in  some  of  the  environment  variables,  such  as
> +       LD_LIBRARY_PATH and LD_PRELOAD:
> +
> +              ORIGIN is expanded to the location of the binary which  is  cur‐
> +              rently loaded.
> +
> +              LIB  is  expanded to lib, lib64 or any other multilib configura‐
> +              tion based on the ld configuration.  Use when mixed  environment
> +              (32bit and 64bit) searches for same libraries names.
> +
> +              PLATFORM is expanded to the running platform.
>
>         There are four important environment variables.
> ---
>
> Any test will do! as long as this feature gets documented.
>
> Signed-off-by: Alon Bar-Lev <alon.barlev@xxxxxxxxx>
>
> [1] http://sourceware.org/ml/libc-alpha/2011-08/msg00089.html
>
> ---
>
> [Attached]
> I am not subscribed, so please CC me.

I applied the patch below. Thanks for the report, and sorry that it
fell on the floor long ago.

Cheers,

Michael

diff --git a/man8/ld.so.8 b/man8/ld.so.8
index b33f417..59c959e 100644
--- a/man8/ld.so.8
+++ b/man8/ld.so.8
@@ -162,6 +162,14 @@ Use
 instead of
 .B LD_LIBRARY_PATH
 environment variable setting (see below).
+The names
+.IR ORIGIN ,
+.IR LIB ,
+and
+.IR PLATFORM
+are interpreted as for the
+.BR LD_LIBRARY_PATH
+environment variable.
 .TP
 .BI \-\-inhibit\-rpath " list"
 Ignore RPATH and RUNPATH information in object names in
@@ -258,6 +266,31 @@ Similar to the
 .B PATH
 environment variable.
 This variable is ignored in secure-execution mode.
+
+Within the pathnames specified in
+.BR LD_LIBRARY_PATH ,
+the dynamic linker expands the strings
+.IR $ORIGIN ,
+.IR $LIB ,
+and
+.IR $PLATFORM
+(or the versions using curly braces around the names)
+as described above in
+.IR "Rpath token expansion" .
+Thus, for example,
+the following would cause a library to be searched for in either the
+.I lib
+or
+.I lib64
+subdirectory below the directory containing the program to be executed:
+
+    $ \fBLD_LIBRARY_PATH='$ORIGIN/$LIB' prog\fP
+
+(Note the use of single quotes, which prevent expansion of
+.I ORIGIN
+and
+.I LIB
+as shell variables!)
 .TP
 .B LD_PRELOAD
 A list of additional, user-specified, ELF shared
@@ -269,6 +302,23 @@ In secure-execution mode,
 preload pathnames containing slashes are ignored,
 and shared objects in the standard search directories are loaded
 only if the set-user-ID mode bit is enabled on the shared object file.
+
+Within the pathnames specified in
+.BR LD_PRELOAD ,
+the dynamic linker understands the strings
+.IR $ORIGIN ,
+.IR $LIB ,
+and
+.IR $PLATFORM
+(or the versions using curly braces around the names)
+as described above in
+.IR "Rpath token expansion" .
+.\" Tested with the following:
+.\"
+.\"    LD_PRELOAD='$LIB/libmod.so' LD_LIBRARY_PATH=. ./prog
+.\"
+.\" which will reload the libmod.so in 'lib' or 'lib64', using it
+.\" in preference to the version in '.'.
 .TP
 .B LD_TRACE_LOADED_OBJECTS
 (ELF only)


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux