Commit Graph

76 Commits

Author SHA1 Message Date
Warner Losh
fa9896e082 Remove $FreeBSD$: two-line nroff pattern
Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:10 -06:00
Konstantin Belousov
8cc44a1e59 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
2022-11-11 12:06:30 +02:00
John F. Carr
6c799530d8 rtld.1: Fix misplaced text
PR:		262194
Fixes:		f90218886f ("rtld: introduce PRELOAD_FDS")
MFC after:	3 days
2022-02-25 11:16:35 -05:00
Konstantin Belousov
64ba1f4cf3 rtld: Implement LD_SHOW_AUXV
It dumps auxv as seen by interpreter, right before starting any user
code.

Copied from:	glibc
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2021-11-13 19:33:13 +02:00
Konstantin Belousov
ba7f9c1b61 rtld direct exec: add -d option
to ignore lack of execute permission on the binary.  The check is a
bad security theatre anyway.

Reviewed by:	arichardson, imp
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D32464
2021-10-13 03:41:48 +03:00
Fangrui Song
7da378f9de rtld: Switch to the standard symbol lookup behavior if LD_DYNAMIC_WEAK is set
The current lookup prefers a strong definition to a STB_WEAK definition
(similar to glibc pre-2.2 behavior) which does not conform to the ELF
specification.

The non-compliant behavior provoked https://reviews.llvm.org/D4418
which was intended to fix -shared-libasan but introduced
new problems (and caused some sanitizer tests (e.g.
test/asan/TestCases/interception_failure_test.cpp) to fail): sanitizer
interceptors are STB_GLOBAL instead of STB_WEAK, so defining a second
STB_GLOBAL interceptor can lead to a multiple definition linker error.
For example, in a -fsanitize={address,memory,...} build, libc functions
like malloc/free/strtol/... cannot be provided by user object files.

See
https://docs.freebsd.org/cgi/getmsg.cgi?fetch=16483939+0+archive/2014/freebsd-current/20140716.freebsd-current
for discussions.

This patch implements the ELF-compliant behavior when LD_DYNAMIC_WEAK is
set. STB_WEAK wrestling in symbol lookups in `Search the dynamic linker
itself` are untouched.

Reviewed by:	kib
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D26352
2021-08-16 13:55:35 +03:00
Konstantin Belousov
e3149e0a02 rtld: Rename -t option to -u (ignore LD_ vars)
Requested by:	arichardson
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2021-06-03 01:55:08 +03:00
Konstantin Belousov
d81f999ac2 rtld direct exec: add option to ignore LD_ variables
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2021-05-29 17:59:09 +03:00
Konstantin Belousov
d36d681615 rtld dl_iterate_phdr(): dlpi_tls_data is wrong
dl_iterate_phdr() dlpi_tls_data should provide the TLS module segment
address, and not the TLS init segment address as it does now.

Reported by:	emacsray@gmail.com
PR:	254774
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2021-04-06 03:23:08 +03:00
Mariusz Zaborski
e086aff91c rtld: fix the man page
In f90218886f in man page I used LD_PRELOAD_PATH_FDS instead of
LD_PRELOAD_FDS.

Reported by:	rpokala
2021-03-25 00:51:44 +01:00
Mariusz Zaborski
f90218886f rtld: introduce PRELOAD_FDS
The new PRELOAD_FDS variable accepts a list of file descriptors
that should be loaded into the process.

This may be used to optimize a loading process - in the case when
we already have a file descriptor to the library; we don't have
to look into multiple PATH to find it.

It may also be used in capability mode to load a single additional
library without the need to open a directory that contains it.

The last use of this functionality t may be a race-free method
of loading libraries.

Reviewed by:	kib, markj
Differential Revision:	https://reviews.freebsd.org/D29334
2021-03-24 23:40:48 +01:00
Gordon Bergling
812b09037d Fix a few mandoc issues
- whitespace at end of input line
- skipping paragraph macro: Pp at the end of Sh
- new sentence, new line
- consider using OS macro: Fx
- AUTHORS section without An macro
- skipping paragraph macro: Pp before Ss
2020-10-09 15:14:19 +00:00
Konstantin Belousov
e82d19822e rtld: Add -b option to allow to specify image name different from arg0.
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2020-05-31 22:37:33 +00:00
Konstantin Belousov
c8dd6c0599 rtld: Add -v switch to print some useful information about the rtld binary.
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2020-05-31 21:53:15 +00:00
Konstantin Belousov
d89d55087f Add version indicators to rtld.
It is wrong to relate on __FreeBSD_version, either from
include/param.h, kernel, or libc, to check for rtld features.
Rtld might be from newer world than the running userspace.

Add special private symbols exported by rtld itself, to indicate the
changes in runtime behavior, and features that cannot be otherwise
detected or deduced at runtime.

Note that the symbols are not exported from libc, so they intentionally
cannot be linked against, and exported from the private namespace from rtld.
Consumers are required to use dlsym(3).  For instance, for
_rtld_version_laddr_offset, user should do
	ptr = dlsym(RTLD_DEFAULT, "_rtld_version_laddr_offset")
or even
	ptr = dlvsym(RTLD_DEFAULT,  "_rtld_version_laddr_offset",
	    "FBSDprivate_1.0");
Non-null ptr means that the change is present.

Also add _rtld_version__FreeBSD_version indicator to report the
headers version used at time of the rtld build.

Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D24982
2020-05-26 19:22:46 +00:00
Konstantin Belousov
cf551abc8b Add serial comma.
Submitted by:	wblock
MFC after:	3 days
2017-09-01 16:56:37 +00:00
Konstantin Belousov
9152cb3868 Language improvements.
Submitted by:	wblock
MFC after:	3 days
Differential revision:	https://reviews.freebsd.org/D10826
2017-07-14 15:42:12 +00:00
Konstantin Belousov
109f3b8c69 Document direct execution mode for rtld.
Reviewed by:	emaste, jonathan (previous version)
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D10826
2017-05-29 13:38:26 +00:00
Konstantin Belousov
18934eb6b8 Correct explanation of the dynamic tokens handling.
Reviewed by:	emaste, jonathan
Sponsored by:	The FreeBSD Foundation
X-Differential Revision:	https://reviews.freebsd.org/D10826
2017-05-29 13:36:32 +00:00
Jonathan Anderson
dc902dbd60 Fix some nroff syntax in rtld.1.
When I originally documented the LD_LIBRARY_PATH_FDS environment variable,
I used `.Ev` rather than `.It Ev` to introduce it; this led to the
documentation being embedded in the previous paragraph (LD_LIBRARY_PATH).
2017-05-18 00:32:05 +00:00
Jilles Tjoelker
2d6acb22fe rtld(1): Document that LD_BIND_NOT is unset for setugid processes.
MFC after:	2 weeks
2017-03-16 22:15:43 +00:00
Konstantin Belousov
e35ddbe448 Implement LD_BIND_NOT knob for rtld.
From the manpage:
When set to a nonempty string, prevents modifications of the PLT slots
when doing bindings.  As result, each call of the PLT-resolved
function is resolved.  In combination with debug output, this provides
complete account of all bind actions at runtime.

Same feature exists on Linux and Solaris.

Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
2017-03-15 21:11:57 +00:00
Joel Dahl
df2d82e003 mdoc: remove superfluous paragraph macros. 2014-06-23 18:40:21 +00:00
Jonathan Anderson
02d3b38e0a Add the LD_LIBRARY_PATH_FDS environmental variable.
This variable allows the loading of shared libraries via directory descriptors
rather than via library paths.  If LD_LIBRARY_PATH_FDS=3:4:12, the directories
represented by file descriptors 3, 4 and 12 will searched for shared libraries
before the normal path-based mechanisms are used.  This allows us to execute
unprivileged binaries from within a Capsicum sandbox even if they require
shared libraries.

Approved by:	rwatson (mentor)
Reviewed by:	kib
MFC after:	3 weeks
Sponsored by:	DARPA/AFRL
2014-06-20 17:08:32 +00:00
Konstantin Belousov
bca2f6239d Import the DragonFly BSD commit 4f0bc915b65fcf5a23214f6d221d65c80be68ad4
by John Marino <draco@marino.st>, with the following (edited) commit
message
Date: Sat, 24 Mar 2012 06:40:50 +0100
Subject: [PATCH 1/1] rtld: Implement DT_RUNPATH and -z nodefaultlib

DT_RUNPATH is incorrectly being considered as an alias of DT_RPATH.  The
purpose of DT_RUNPATH is to have two different types of rpath: one that
can be overridden by the environment variable LD_LIBRARY_PATH and one that
can't.  With the currently implementation, LD_LIBRARY_PATH will always
trump any embedded rpath or runpath tags.

Current path search order by rtld:
==================================
LD_LIBRARY_PATH
DT_RPATH / DT_RUNPATH (always the same)
ldconfig hints file (default: /var/run/ld-elf.so.hints)
/usr/lib

New path search order by rtld:
==============================
DT_RPATH of the calling object if no DT_RUNPATH
DT_RPATH of the main binary if no DT_RUNPATH and binary isn't calling obj
LD_LIBRARY_PATH
DT_RUNPATH
ldconfig hints file
/usr/lib

The new path search matches how the linux runtime loader works.  The other
major added feature is support for linker flag "-z nodefaultlib".  When
this flag is passed to the linker, rtld will skip all references to the
standard library search path ("/usr/lib" in this case but it could handle
more color delimited paths) except in DT_RPATH and DT_RUNPATH.

New path search order by rtld with -z nodefaultlib flag set:
============================================================
DT_RPATH of the calling object if no DT_RUNPATH
DT_RPATH of the main binary if no DT_RUNPATH and binary isn't calling obj
LD_LIBRARY_PATH
DT_RUNPATH
ldconfig hints file (skips all references to /usr/lib)

FreeBSD notes:
- we fixed some bugs which were submitted to DragonFly and merged there
  as commit 1ff8a2bd3eb6e5587174c6a983303ea3a79e0002;
- we added LD_LIBRARY_PATH_RPATH environment variable to switch to
  the previous behaviour of considering DT_RPATH a synonym for DT_RUNPATH;
- the FreeBSD default search path is /lib:/usr/lib and not /usr/lib.

Reviewed by:   kan
MFC after:     1 month
MFC note:      flip the ld_library_path_rpath default value for stable/9
2012-07-15 10:53:48 +00:00
Konstantin Belousov
8569deaf1c Implement support for ELF filters in rtld. Both normal and auxillary
filters are implemented.

Filtees are loaded on demand, unless LD_LOADFLTR environment variable
is set or -z loadfltr was specified during the linking. This forces
rtld to upgrade read-locked rtld_bind_lock to write lock when it
encounters an object with filter during symbol lookup.

Consolidate common arguments of the symbol lookup functions in the
SymLook structure.  Track the state of the rtld locks in the
RtldLockState structure. Pass local RtldLockState through the rtld
symbol lookup calls to allow lock upgrades.

Reviewed by:	kan
Tested by:	Mykola Dzham <i levsha me>, nwhitehorn (powerpc)
2010-12-25 08:51:20 +00:00
Ulrich Spörlein
0d9deed52c mdoc: drop redundant .Pp and .LP calls
They have no effect when coming in pairs, or before .Bl/.Bd
2010-10-08 12:40:16 +00:00
Konstantin Belousov
b2e4ce45d9 Document RTLD_NODELETE, -z nodelete and -z origin support. 2009-04-01 14:38:20 +00:00
Xin LI
569e2ef6a9 Support for a new environment variable, LD_ELF_HINTS_PATH for overriding
the rtld hints file.  This environment variable would be unset if the
process is considered as tainted with setuid/setgid.  This feature gives
a convenient way of using a custom set of shared library that is not
located in the default location and switch back.

Feature requested by:	iXsystems
Original patch by:	John Hixson
MFC after:		2 weeks
2009-03-23 16:49:00 +00:00
Bruce M Simpson
523b17effe Make the meaning of the %A format specifier, as passed to
LD_TRACE_LOADED_OBJECTS_FMT[12], more obvious for users like me.
2008-05-15 10:47:14 +00:00
Christian S.J. Peron
b075897e99 Update the man page to reflect that certain variables will be unset in
the case that the program is set-user-ID or set-group-ID. Add missing
annotations for LIBMAP and LIBMAP_DISABLE.
2007-05-17 19:14:25 +00:00
Pav Lucistnik
88922cf00e Remove %m formatter, it's ifdef 0'ed in the code from the very beginning
MFC after:	1 week
2007-05-12 12:26:25 +00:00
Pav Lucistnik
b9e1d83e61 Expand documentation for LD_TRACE_LOADED_OBJECTS_FMT? variables
PR:		docs/66265 (inspired by)
Submitted by:	Michel Lavondes <fox@vader.aacc.cc.md.us>
MFC after:	1 week
2007-05-12 12:24:49 +00:00
John Baldwin
f0ac0f92fb Document LD_UTRACE.
MFC after:	3 days
2007-01-23 22:38:39 +00:00
Ruslan Ermilov
a3ec17db37 Markup fixes. 2006-09-17 21:48:47 +00:00
Pav Lucistnik
8a50f51b1b - Document LD_32_* environment variables
- Mention 32-bit files in FILES section

MFC after:	1 week
2006-03-27 00:53:58 +00:00
Ruslan Ermilov
cc4fdb1de9 Removed trailing whitespace.
Approved by:	re (blanket)
2005-06-14 08:41:11 +00:00
Matthew N. Dodd
5b08cb0449 Description from Dan:
Another handy libmap patch.  Lets you do stuff like this:

	LD_LIBMAP="libpthread.so.1=libthr.so.1" mythreadedapp

	If you already have a program-specific override in libmap.conf, note
	that you must use a program-specific override in LD_LIBMAP:

	LD_LIBMAP="[mythreadedapp],libpthread.so.1=libthr.so.1" mythreadedapp

PR:		bin/74471
Submitted by:	Dan Nelson <dnelson AT allantgroup.com>
MFC after:	2 weeks
2005-02-04 02:46:41 +00:00
Matthew N. Dodd
ded0e52363 LD_DUMP_REL_PRE and LD_DUMP_REL_POST don't output to stderr; don't
claim that they do.
2003-06-19 04:34:09 +00:00
Matthew N. Dodd
c5d061c17a Provide a mechanism for dumping relocation information.
Setting the LD_DUMP_REL_PRE or LD_DUMP_REL_POST environment variables
cause rtld-elf to output a table of all relocations.

This is useful for debugging.
2003-06-19 03:55:38 +00:00
Ruslan Ermilov
09f84dd1d3 Assorted mdoc(7) fixes. 2003-06-02 15:02:06 +00:00
Matthew N. Dodd
4df60d1cac Use the environment variable LD_LIBMAP_DISABLE to disable
libmap.conf(5) functionality.
2003-05-31 14:45:11 +00:00
Robert Watson
94deb3f034 Since libmap.conf is referenced in rtld.1, include it in the references
section.

Approved by:	re (scottl)
2003-05-17 19:46:49 +00:00
Ruslan Ermilov
60cdf2f1a0 mdoc(7) police: Normalize the FILES section.
Approved by:	re (blanket)
2003-05-16 21:34:21 +00:00
Matthew N. Dodd
29ade36225 Dynamic object dependency mapping: libmap.
This is an optional feature, disabled by default.

This will be useful to people testing the various POSIX threading
libraries under -CURRENT but can easily serve other needs.
2003-04-07 16:21:26 +00:00
Alexey Zelkin
d9943f166b Advertize rtld(1) as ld.so(1) in manual pages world 2003-02-13 23:07:28 +00:00
Ruslan Ermilov
8d5d039f80 Uniformly refer to a file system as "file system".
Approved by:	re
2002-12-12 17:26:04 +00:00
Philippe Charnier
3f162cb85d The .Nm utility 2002-07-06 19:19:48 +00:00
David E. O'Brien
2024994319 Add support such that if LD_TRACE_LOADED_OBJECTS_ALL is defined to a
non-empty string in the environment; we indicate which objects caused
each object to be loaded.

PR:		30908
Submitted-by:	Mike Meyer <mwm@mired.org>
2002-02-17 07:04:32 +00:00
Ruslan Ermilov
bcf2b1b312 mdoc(7) police: tidy up. 2002-01-10 17:49:57 +00:00