History log of /freebsd-current/libexec/rtld-elf/libmap.c
Revision Date Author Comments
# 42b38843 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .h pattern

Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/


# ca2560bd 17-Oct-2022 Konstantin Belousov <kib@FreeBSD.org>

rtld: fix typo in comment

Sponsored by: The FreeBSD Foundation
MFC after: 3 days


# 1251cf8a 18-Sep-2022 Konstantin Belousov <kib@FreeBSD.org>

rtld-elf/libmap.c: correct comment

There is no intent to support TLS for rtld.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week


# 33dba3bb 12-Oct-2021 Konstantin Belousov <kib@FreeBSD.org>

rtld-elf/paths.h: Make it usable outside rtld

but still for tightly coupled things like ldd(1)

Rename paths.h to rtld_paths.h.
Add guard for rtld-specific externs declarations.
Add _COMPAT32_BASENAME_RTLD and _COMPAT32_PATH_RTLD.

Reviewed by: arichardson, jhb
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D32464


# aa68b3bb 16-Aug-2021 Konstantin Belousov <kib@FreeBSD.org>

rtld: constify most variables holding references to the environment values

Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D31545


# 741d7812 01-Jan-2021 Konstantin Belousov <kib@FreeBSD.org>

rtld: call close(2) after errno is saved

to prevent obliteration of error value from the original syscall.
Also improve error message for short read.

Submitted by: Konrad Sewiłło-Jopek
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D27864


# b54a59f3 30-Jun-2019 Alex Richardson <arichardson@FreeBSD.org>

Reduce size of rtld by 22% by pulling in less code from libc

Currently RTLD is linked against libc_nossp_pic which means that any libc
symbol used in rtld can pull in a lot of depedencies. This was causing
symbol such as __libc_interposing and all the pthread stubs to be included
in RTLD even though they are not required. It turns out most of these
dependencies can easily be avoided by providing overrides inside of rtld.

This change is motivated by CHERI, where we have an experimental ABI that
requires additional relocation processing to allow the use of function
pointers inside of rtld. Instead of adding this self-relocation code to
RTLD I attempted to remove most function pointers from RTLD and discovered
that most of them came from the libc dependencies instead of being actually
used inside rtld.

A nice side-effect of this change is that rtld is now 22% smaller on amd64.

text data bss dec hex filename
0x21eb6 0xce0 0xe60 145910 239f6 /home/alr48/ld-elf-x86.before.so.1
0x1a6ed 0x728 0xdd8 113645 1bbed /home/alr48/ld-elf-x86.after.so.1

The number of R_X86_64_RELATIVE relocations that need to be processed on
startup has also gone down from 368 to 187 (almost 50% less).

Reviewed By: kib
Differential Revision: https://reviews.freebsd.org/D20663


# 3ab5b6bd 29-Oct-2018 Alex Richardson <arichardson@FreeBSD.org>

rtld-elf: fix more warnings to allow compiling with WARNS=6

Reviewed By: kib
Approved By: brooks (mentor)
Differential Revision: https://reviews.freebsd.org/D17154


# 903e0ffd 29-Oct-2018 Alex Richardson <arichardson@FreeBSD.org>

rtld-elf: compile with WANRS=4 warnings other than -Wcast-align

Reviewed By: kib
Approved By: brooks (mentor)
Differential Revision: https://reviews.freebsd.org/D17153


# 78b64846 29-Oct-2018 Alex Richardson <arichardson@FreeBSD.org>

rtld-elf: make it compile with WARNS=3

Reviewed By: kib
Approved By: brooks (mentor)
Differential Revision: https://reviews.freebsd.org/D17150


# 6c306765 26-Sep-2018 Konstantin Belousov <kib@FreeBSD.org>

When doing lm_add(), check for duplicates.

This is useful when lm_find() moves the match to the global mapping,
since lm_find() could be called with a same path more than once.

Reported and tested by: Andreas Longwitz <longwitz@incore.de>
Sponsored by: The FreeBSD Foundation
Approved by: re (gjb)
MFC after: 1 week


# c1a0a86e 02-Sep-2018 Konstantin Belousov <kib@FreeBSD.org>

Style cleanup. No functional changes.

Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Approved by: re (rgrimes)


# 152036a0 28-Oct-2017 Edward Tomasz Napierala <trasz@FreeBSD.org>

Plug memory leak on error case.

Reported by: Coverity
CID: 1382112
MFC after: 2 weeks


# a8b31c14 24-Oct-2017 Edward Tomasz Napierala <trasz@FreeBSD.org>

Use xmalloc and read(2) instead of mmap(2) to read in libmap.conf(5).
This removes the need to call munmap(2) afterwards.

MFC after: 2 weeks
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D12767


# 6b61e3e4 22-Oct-2017 Edward Tomasz Napierala <trasz@FreeBSD.org>

Don't call realpath(3) from libmap rtld code. This gets rid of a few calls
to fstatat(2) at binary startup; the difference looks like this:

--- przed 2017-10-14 13:55:49.983528000 +0100
+++ po 2017-10-14 14:10:39.134343000 +0100
@@ -1,15 +1,10 @@
mmap(0x0,32768,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 34366173184 (0x800623000)
issetugid() = 0 (0x0)
-fstatat(AT_FDCWD,"/etc",{ mode=drwxr-xr-x ,inode=1364352,size=2560,blksize=32768 },AT_SYMLINK_NOFOLLOW) = 0 (0x0)
-fstatat(AT_FDCWD,"/etc/libmap.conf",{ mode=-rw-r--r-- ,inode=1373288,size=102,blksize=32768 },AT_SYMLINK_NOFOLLOW) = 0 (0x0)
openat(AT_FDCWD,"/etc/libmap.conf",O_RDONLY|O_CLOEXEC,00) = 3 (0x3)
fstat(3,{ mode=-rw-r--r-- ,inode=1373288,size=102,blksize=32768 }) = 0 (0x0)
mmap(0x0,102,PROT_READ,MAP_PRIVATE,3,0x0) = 34366205952 (0x80062b000)
close(3) = 0 (0x0)
-fstatat(AT_FDCWD,"/usr",{ mode=drwxr-xr-x ,inode=561792,size=512,blksize=32768 },AT_SYMLINK_NOFOLLOW) = 0 (0x0)
-fstatat(AT_FDCWD,"/usr/local",{ mode=drwxr-xr-x ,inode=561800,size=512,blksize=32768 },AT_SYMLINK_NOFOLLOW) = 0 (0x0)
-fstatat(AT_FDCWD,"/usr/local/etc",{ mode=drwxr-xr-x ,inode=653279,size=1536,blksize=32768 },AT_SYMLINK_NOFOLLOW) = 0 (0x0)
-fstatat(AT_FDCWD,"/usr/local/etc/libmap.d",0x7fffffffcf50,AT_SYMLINK_NOFOLLOW) ERR#2 'No such file or directory'
+open("/usr/local/etc/libmap.d",O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC,0165) ERR#2 'No such file or directory'
munmap(0x80062b000,102) = 0 (0x0)
openat(AT_FDCWD,"/var/run/ld-elf.so.hints",O_RDONLY|O_CLOEXEC,00) = 3 (0x3)
read(3,"Ehnt\^A\0\0\0\M^@\0\0\0\M-2\0\0"...,128) = 128 (0x80)

Reviewed by: kib
MFC after: 2 weeks
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D12741


# 3deca56f 30-Oct-2015 Warner Losh <imp@FreeBSD.org>

Rather than using the #define for path names, indirect through a char *
variable that could change for different executable types detected.


# b2a4014c 30-Oct-2015 Warner Losh <imp@FreeBSD.org>

Move all the paths into a new path.h to centralize them.


# 0fa46a42 20-Aug-2014 Pedro F. Giffuni <pfg@FreeBSD.org>

Always check the limits of array index variables before using them.

Obtained from: DragonFlyBSD
MFC after: 1 week


# 490c68de 18-May-2014 Konstantin Belousov <kib@FreeBSD.org>

Fix LD_LIBMAP.
The r232862 passed the pointer to end of string to lmc_parse() and free().

Submitted by: Wolfgang Jenkner <wjenkner@inode.at>
MFC after: 1 week


# 8182b3be 21-Sep-2013 Dag-Erling Smørgrav <des@FreeBSD.org>

Make the directory mapping functionality, which was previously only
available in 32-bit compatibility mode, unconditional.

Overhaul the man page, which had evolved more by accretion than by design.

Approved by: re (gjb)
MFC after: 3 weeks


# e1942829 04-Nov-2012 Jilles Tjoelker <jilles@FreeBSD.org>

rtld: Fix fd leak with parallel dlopen and fork/exec.

Rtld did not set FD_CLOEXEC on its internal file descriptors; therefore,
such a file descriptor may be passed to a process created by another thread
running in parallel to dlopen() or fdlopen().

No other threads are expected to be running during parsing of the hints
and libmap files but the file descriptors need not be passed to child
processes so add O_CLOEXEC there as well.

This change will break fdlopen() (as used by OpenPAM) on kernels without
F_DUPFD_CLOEXEC (added in July). Note that running new userland on old
kernels is not supported.

Reviewed by: kib


# 5c98f307 05-May-2012 Baptiste Daroussin <bapt@FreeBSD.org>

open the resolved path
fix debug message

Submitted by: John Marino <draco@marino.st>
Approved by: des (mentor)


# faf66437 30-Apr-2012 Baptiste Daroussin <bapt@FreeBSD.org>

Add two special directives to libmap.conf:
include <file>:
Parse the contents of file before continuing with the current file.
includedir <dir>:
Parse the contents of every file in dir that ends in .conf before continuing
with the current file.
Any file or directory encountered while processing include or includedir
directives will be parsed exactly once, even if it is encountered multiple
times.

Reviewed by: kib, des
Approved by: des (mentor)
MFC after: 1 month


# 6fea10fb 14-Mar-2012 Konstantin Belousov <kib@FreeBSD.org>

Rtld on diet 3.

Stop using strerror(3) in rtld, which brings in msgcat and stdio.
Directly access sys_errlist array of errno messages with private
rtld_strerror() function.

Now,
$ size /libexec/ld-elf.so.1
text data bss dec hex filename
96983 2480 8744 108207 1a6af /libexec/ld-elf.so.1

Reviewed by: dim, kan
MFC after: 2 weeks


# 68f1db20 11-Mar-2012 Konstantin Belousov <kib@FreeBSD.org>

Rtld on diet part 2:

Do not use stdio for libmap.conf read. Directly map the file and
parse lines from the mappings.

Reviewed by: kan
MFC after: 3 weeks


# 44976aca 06-Mar-2012 Sergey Kandaurov <pluknet@FreeBSD.org>

Cosmetic nit:
- rename isspace1() macro to the more appropriate rtld_isspace().

Discussed with: kib


# b36070f5 05-Mar-2012 Konstantin Belousov <kib@FreeBSD.org>

The libmap.conf initialization is performed before TLS is functional.
Since after r232498 the ctype macros require working access to
thread-local variables, rtld crashes when libmap.conf is present.

Use hand-made isspace1() macro which is enough to detect spaces in
libmap.conf.

Reported by: alc, lme, many on current@
Tested by: lme
Reviewed by: dim, kan
MFC after: 1 week


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 8c6a035e 30-Jan-2006 Peter Wemm <peter@FreeBSD.org>

Fix a malloc overrun in 32-bit compat libmap lookup code.


# 5b08cb04 03-Feb-2005 Matthew N. Dodd <mdodd@FreeBSD.org>

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


# d33da23f 03-Feb-2005 Matthew N. Dodd <mdodd@FreeBSD.org>

style(9)


# 966efcc7 23-May-2004 Matthew N. Dodd <mdodd@FreeBSD.org>

Support basename and path based constrained matches.

eg:
[foo]
...

matches any executable 'foo'

[/usr/bin/foo/]
...

matches any executable under the directory /usr/bin/foo/

Exact matches continue to function as before.

PR: bin/66769
Submitted-by: Dan Nelson


# c905e45d 20-Mar-2004 Peter Wemm <peter@FreeBSD.org>

Add initial support for compiling a special 32 bit version of
ld-elf.so.1 on 64 bit systems. Most of this involves using alternate
paths, environment variables and diagnostic messages.

The build glue is seperate.


# 6e918a4d 03-Feb-2004 Max Khon <fjoe@FreeBSD.org>

Fix "warning: value computed is not used".

Found by: gcc 2.95.4 [FreeBSD]


# 4402996d 13-Sep-2003 Matthew N. Dodd <mdodd@FreeBSD.org>

Change libmap.c:lm_init() to return a status value; 0 for success
(libmap available) and 1 for failure. Assign this return to the
global 'libmap_disable' variable in rtld.c.

This totally prevents any libmap functions from being called after
lm_init() if no config file is present.


# 7227105f 17-Jun-2003 Matthew N. Dodd <mdodd@FreeBSD.org>

Include libmap.h for prototypes.


# 1aac1ed6 31-May-2003 Matthew N. Dodd <mdodd@FreeBSD.org>

Provide function entry debugging messages.


# 1340fc10 29-May-2003 Matthew N. Dodd <mdodd@FreeBSD.org>

Don't post-increment pointers inside a loop conditional.

While I'm here:
- Let lm_add() call strdup() on its own behalf.
- Use a temporary pointer when parsing constraints; only set the
constraint pointer on a totally successful match.

PR: bin/52783
Submitted by: David P. Reese Jr. <daver@gomerbud.com>
Approved by: re (rwatson)


# 6d5d786f 29-May-2003 Alexander Kabaev <kan@FreeBSD.org>

Allow threading libraries to register their own locking
implementation in case default one provided by rtld is
not suitable.

Consolidate various identical MD lock implementation into
a single file using appropriate machine/atomic.h.

Approved by: re (scottl)


# 3467e8b8 19-May-2003 Matthew N. Dodd <mdodd@FreeBSD.org>

- Use xmalloc() and xstrdup() instead of malloc() and strdup().
- Add a global mapping if we have a successful constrained match.

Approved by: re


# 486089f0 30-Apr-2003 Alexander Kabaev <kan@FreeBSD.org>

Remove redundant strlen checks, do not check the same
symbol twice.


# 623b6bd2 09-Apr-2003 Matthew N. Dodd <mdodd@FreeBSD.org>

Code cleanups and sanity checking for config file parser.


# 29ade362 07-Apr-2003 Matthew N. Dodd <mdodd@FreeBSD.org>

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.