Commit Graph

84 Commits

Author SHA1 Message Date
John Polstra
7e7344e2f4 Implement dlsym(RTLD_NEXT, symbol). 1997-08-02 04:56:44 +00:00
Masafumi Max NAKANE
d5fb0dffb4 Typo fix.
PR:		3693
Submitted by:	Kazuo Horikawa <k-horik@yk.rim.or.jp>
1997-05-27 13:46:40 +00:00
Doug Rabson
3c0a9567e5 Changes to support the kernel linker:
Add a -Bforcedynamic option which generates a dynamic object even
	if no shared libraries were given in the link.

	Make RRS in text section warnings conditional on "-assert pure-text"
	so that I can link non-PIC kernel modules without tons of link
	errors.  Changes to bsd.lib.mk to follow.

	Fix a couple of bugs exposed by the fact that the kernel is not
	linked at zero.

Reviewed by:	jdp
1997-05-13 10:23:47 +00:00
John Polstra
aafb797228 Fix a bug that caused the relocs for linker set members in shared
libraries to come out as 1-byte relocations instead of 4-byte
relocations.

Submitted by:	Doug Rabson <dfr@nlsystems.com>
1997-04-30 05:18:08 +00:00
Bruce Evans
9453d60b10 Fixed `make depend' and related bogons. LDFLAGS was used for
ld-specific flags.  LDFLAGS is really for ld-related flags for cc,
not for ld, and some flags, e.g., -Bshareable, mean completely
different things to cc and ld.  Having the wrong things in LDFLAGS
also broke the standard ${PROG} target.  This was kludged around
by using a special rule that depended on LDFLAGS being bogus.
Fixing `make depend' broke the special rule but fixed the standard
rule (except in the DESTDIR case, which was handled more strictly
here than elsewhere).
1997-04-16 11:31:32 +00:00
Peter Wemm
fce15c9ab3 Revert $FreeBSD$ to $Id$ 1997-02-22 15:48:31 +00:00
John Polstra
18be4a71df Use xmalloc instead of malloc in two places, so that out-of-memory
conditions will be detected.

Submitted by:	Philippe Charnier <charnier@xp11.frmug.org>
1997-01-24 00:07:03 +00:00
John Polstra
ac6c268b3d Pay attention to the environment variable "LD_IGNORE_MISSING_OBJECTS".
If it is set to a nonempty string, then simply skip any missing
shared libraries.  This came up in a discussion long ago as a
potentially useful feature at sysinstall time.  For example, an
X11 utility could be used without the X libraries being present,
provided the utility had a mode in which no X functions were actually
called.
1997-01-17 20:22:18 +00:00
John Polstra
20995a4fcc If a library is found in the hints file, but the library doesn't exist,
ignore the hint.

This is a straightforward fix, and it should go into 2.2 after a burn-in
period of a few days.

Noticed by:	bde
1997-01-14 17:53:55 +00:00
Jordan K. Hubbard
1130b656e5 Make the long-awaited change from $Id$ to $FreeBSD$
This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore.  This update would have been
insane otherwise.
1997-01-14 07:20:47 +00:00
Wolfram Schneider
af20215665 Sort cross references. 1997-01-13 00:25:51 +00:00
John Polstra
d956f8a388 Use the RTLD_NOW symbol, now that it is defined in <dlfcn.h>. 1997-01-12 19:59:26 +00:00
John Polstra
aeea55e459 Correct typos and spelling errors. 1997-01-12 00:19:14 +00:00
John Polstra
0db65949ae Add support for the LD_BIND_NOW environment variable. If it is set to a
nonempty string, then function calls are relocated at program start-up
rather than lazily.  This variable is standard on Sun and SVR4 systems.

The dlopen() function now supports both lazy and immediate binding, as
determined by its "mode" argument, which can be either 1 (RTLD_LAZY) or
2 (RTLD_NOW).  I will add defines of these symbols to <dlfcn.h> as soon
as I've done a little more checking to make sure they won't cause
collisions or bootstrapping problems that would break "make world".

The "LD_*" environment variables which alter dynamic linker behavior are
now treated as unset if they are set to the empty string.  This agrees
with the standard SVR4 conventions for the dynamic linker.

Add a work-around for programs compiled with certain buggy versions of
crt0.o.  The buggy versions failed to set the "crt_ldso" member of the
interface structure.  This caused certain error messages from the
dynamic linker to begin with "(null)" instead of the pathname of the
dynamic linker.
1997-01-12 00:16:36 +00:00
John Polstra
d3c677c7e0 Add support for the LD_BIND_NOW environment variable. If it is set to a
nonempty string, then function calls are relocated at program start-up
rather than lazily.  This variable is standard on Sun and SVR4 systems.

The dlopen() function now supports both lazy and immediate binding, as
determined by its "mode" argument, which can be either 1 (RTLD_LAZY) or
2 (RTLD_NOW).  I will add defines of these symbols to <dlfcn.h> as soon
as I've done a little more checking to make sure they won't cause
collisions or bootstrapping problems that would break "make world".
1997-01-12 00:09:11 +00:00
Steven Wallace
43d7fd0390 Fix spelling error in manpage. 1996-12-26 21:51:09 +00:00
John Polstra
ab6c6377b3 If errors occur during the loading of the shared libraries required by
the main program, report them directly from the dynamic linker and die
there, rather than returning an error message to crt0.o.  This enables
the printing of error messages even for old executables, whose version
of crt0.o is not able to print them.

This fix closes PR bin/1869.

The code in crt0.o for printing error messages from the dynamic linker
is no longer used, because of this change.  But it must remain, for
backward compatibility with older dynamic linkers.
1996-10-24 16:24:19 +00:00
John Polstra
16804804df Fix two minor typos in the manual page. 1996-10-18 04:49:43 +00:00
John Polstra
e5bbb2e4b5 Add the search directories from the hints file only the first time it is
opened.  After that, the directories are already present, and there is
no point in adding them again.  This doesn't fix any bugs; it's just for
efficiency.
1996-10-10 23:16:50 +00:00
John Polstra
9151bb8d2d Fix a bug that caused a segmentation violation if dlsym() was called
with its first argument equal to NULL.
1996-10-10 04:10:32 +00:00
Nate Williams
9ac501e21b There's no need to 'unsetenv()' unsafe environment variables explicitly
since rt_readenv() already takes care of not setting unsafe variables.
This was part of the changes I submitted to Peter and John during the
review which must have gotten missed.
1996-10-01 16:09:18 +00:00
Peter Wemm
3e17261bac Sigh, oh well, here's my obligigatory "oops" commit. I don't quite know
how I managed to get this out of sync, but I did.  I guess that's what I
get for directly committing from different machines that I was testing on.

Pointed out by: Paul Traina <pst@freebsd.org>
1996-10-01 11:54:38 +00:00
Peter Wemm
5584286a91 Update to handle new version ld.so.hints and info in executable for
configurable fallback search paths, as well as new crt interface version.

Also:
 - even faster getenv(), get all environment variable settings in a single
   pass.
 - ldd printf-like format specifications
 - minor code cleanups, one vsprintf -> vsnprintf (harmless)

The library search sequence is a little more complete now. Before,
it'd search $LD_LIBRARY_PATH (by opendir/readdir/closedir), then read
the hints file, then read /usr/lib (again by scanning thr directory).  It
would then fail if there was no "found" library.

Now, it does LD_LIBRARY_PATH and the hints file the same, but then uses
a longer fallback path.  The -R path is fetched from the executable if
specified at build time, the ldconfig path is appended, and /usr/lib is
appended to that. Duplicates are suppressed.  This means that simply
placing a new library in /usr/local/lib will work (the same as it did in
/usr/lib) without needing ldconfig -m.  It will find it quicker if the
ldconfig is run though.

Similar changes have been made to the NetBSD ld.so, but ours is rather
different now due to John Polstra's speedups and fixes from a while back.

The ldd printf-like format support came direct from NetBSD.

Reviewed by: nate, jdp
1996-10-01 01:52:03 +00:00
Peter Wemm
b186571cf6 Update the backends to go with the top-level ld changes. The non-i386
changes are for completeness, I don't think they work.  There are changes
to deal with the new include files.

Obtained from: NetBSD (mostly)
1996-10-01 01:28:10 +00:00
Peter Wemm
d0a184df5d Support for .weak (in addition to the N_INDR stab) for gcc/g++. Also deal
with the -R option and store the path in the dynamic header when specified.
The $LD_RUN_PATH environment variable is not checked yet.

While here, split up the code a bit more to enable more selective replacing
of GPL'ed components that are linked with ld.so with others.

Obtained from: NetBSD (mostly, the breakup is my fault)
1996-10-01 01:22:51 +00:00
Wolfram Schneider
e0e5145ce6 add missing comma(s) in .Xr macros 1996-09-23 22:24:39 +00:00
Bruce Evans
87d0dcafca Use `install -C' instead of lots of shell commands to install ld.so
as atomically as possible.

(Immutable targets can't be renamed without opening a window when
neither the source nor the target is immutable.  Perhaps there
should be a rename_immutable syscall to do this if unsetting the
immutable flags would work.)
1996-09-12 03:42:54 +00:00
John Polstra
1dd43c183e When checking to see whether a needed shared library has already
been loaded, look for a match by device and inode number if the
traditional pathname comparisons don't find a match.  This detects
the case in which a library is requested using two different names
which are really links to the same file, and avoids loading it
twice.

Requested by:	peter@freebsd.org
Reviewed by:	peter@freebsd.org
1996-05-22 06:34:12 +00:00
Wolfram Schneider
9fb933075e `mv'' -> `mv -f''
``rm'' -> ``rm -f''
so mv/rm may not ask for confirmation if you are not root
1996-05-07 23:19:49 +00:00
John Polstra
dd2b076850 Implement support for LD_PRELOAD in the dynamic linker. Remove
descriptions of LD_NO_INTERN_SEARCH and LD_NOSTD_PATH from the manual
page, since they are not supported.

Submitted by:	Doug Ambrisko <ambrisko@ambrisko.roble.com>
1996-04-20 18:29:50 +00:00
John Polstra
c049096e82 Implement support for LD_PRELOAD in the dynamic linker.
Submitted by:	Doug Ambrisko <ambrisko@ambrisko.roble.com>
1996-04-20 18:27:56 +00:00
John Polstra
5a81ed9667 This release is a moderate restructuring of the dynamic linker.
It addresses a number of problems that were present in earlier
versions.

The calls to the "init" and "fini" functions of shared libraries
have been reordered, so that they are called in a strictly nested
fashion, as is required for C++ constructors and destructors.  In
addition, the "init" functions are called in better order relative
to each other.  That makes the system more tolerant of C++ programs
which depend on a library's being initialized before its clients.

The dynamic linker is now more tolerant of shared libraries in
which dependencies on other shared libraries are incompletely
recorded.

Cleanup in the event of errors has been improved throughout the
dynamic linker.  A number of memory leaks were eliminated.

The warning message for a shared library whose minor version number
is too old has been clarified.

The code dealing with the "ld.so.hints" file has been cleaned up.
A bug that caused the hints file to be unmapped incompletely has
been fixed.  A different bug that could potentially cause the hints
file to be mapped on top of a loaded object has been fixed.

The code that searches for shared libraries has been cleaned up.
The searching is now more compatible with that done by SunOS and
SVR4.  Also, some unnecessary and useless searches of both the
hints file and library directories have been eliminated.

Reviewed by:	nate@freebsd.org
1996-01-13 00:15:25 +00:00
John Polstra
eb4a4eeb45 Split up the code so that a single directory can be searched, to
support some changes in the dynamic linker.  (This code is shared
by the dynamic linker.)

Reviewed by:	nate@freebsd.org
1996-01-13 00:14:53 +00:00
Poul-Henning Kamp
bbb1dc53a4 Another '-' needed for make release. 1996-01-11 17:49:55 +00:00
Poul-Henning Kamp
5a39b83123 Make the new realinstall target a little less draconian so that make release
doesn't fall over.
1996-01-11 17:27:16 +00:00
John Polstra
b25d7c2bbc Install ld.so in a way that is safe even on a running system. 1996-01-11 03:45:55 +00:00
Nate Williams
1e37fc9d59 Changed the terminology for what used to be called the "memorizing"
vector.  Now it is called the "symbol caching" vector.  This was made
possible and unconfusing by other changes that allowed me to localize
everything having to do with the caching vector in the function
reloc_map().

Switched to alloca() for allocating the caching vector, and eliminated
the special mmap-based allocation routines.  Although this was motivated
by performance reasons, it led to significant simplification of the
code, and made it possible to confine the symbol caching code to the
single function reloc_map().

Got rid of the unnecessary and inefficient division loop at the
beginning of rtld().

Reduced the number of calls to getenv("LD_LIBRARY_PATH") to just 1, on
suggestion from <davidg@root.com>.

Added breaks out of the relocation loops when the relocation address is
found to be 0.  A relocation address of 0 is caused by an unused
relocation entry.  Unused relocation entries are caused by linking a
shared object with the "-Bsymbolic" switch.  The runtime linker itself
is linked that way, and the last 40% of its relocation entries are
unused.  Thus, breaking out of the loop on the first such entry is a
performance win when ld.so relocates itself.  As a side benefit, it
permits removing a test from md_relocate_simple() in
../i386/md-static-funcs.c.

Unused relocation entries in other shared objects (linked with
"-Bsymbolic") caused even bigger problems in previous versions of the
runtime linker. The runtime linker interpreted the unused entries as if
they were valid. That caused it to perform repeated relocations of the
first byte of the shared object.  In order to do that, it had to remap
the text segment writable.  Breaking out of the loop on the first unused
relocation entry solves that.

Submitted by:	John Polstra <jdp@polstra.com>
1995-11-02 18:48:15 +00:00
Nate Williams
468f82b316 Run-time linker speedups - Round One
Implemented symbol memorizing to reduce the number of calls to lookup(),
making relocation go faster.  While relocating a given shared object,
the dynamic linker maintains a memorizing vector that is directly
indexed by the symbol number in the relocation entry.  The first time a
given symbol is looked up, the memorizing vector is filled in with a
pointer to the symbol table entry, and a pointer to the so_map of the
shared object in which the symbol was defined.  On subsequent uses of
the same symbol, that information is retrieved directly from the
memorizing vector, without calling lookup() again.

A symbol that is referenced in a relocation entry is typically
referenced in many relocation entries, so this memorizing reduces the
number of calls to lookup() dramatically.  The overall improvement in
the speed of dynamic linking is also dramatic -- as much as a factor of
three for programs that use many shared libaries.

Submitted by:	jdp@polstra.com "John Polstra"
1995-10-25 16:16:35 +00:00
Andrey A. Chernov
a4057ed8d3 Remove LD_NOSTD_PATH implementation, it isn't works and
can cause some problems.
Suggested-by: davidg
1995-10-24 06:48:16 +00:00
Andrey A. Chernov
b2105a0990 if uid != euid or gid != egid unsetenv("LD_NOSTD_PATH") too 1995-10-21 14:52:48 +00:00
Nate Williams
c68c38c86b This is a FreeBSD manpage, not a NetBSD manpage. :) 1995-10-05 05:16:52 +00:00
Nate Williams
6f5457454c Make the error message more readable when 'ld.so' cannot locate a needed
shared library.  Formerly, the message looked like this:

    ld.so: run: libjdp1.so.1.0: Undefined error: 0

The new message looks like this:

    ld.so: run: Can't find shared library "libjdp1.so.1.0"

(Where "run" is the name of the program being executed.)

Submitted by:	jdp@polstra.com (John Polstra)
1995-09-27 23:17:33 +00:00
Nate Williams
e1ec3d8b3c Fixup the "ld.so failed" message for the case when ld.so finds undefined
symbols.

An easy example to see this is to develop an X program which links
against Xt, but doesn't add -lX11 to the link line.  It will link fine,
but cause run-time errors by ld.so because of missing symbols used by Xt
defined in X11.  This patch makes the errors more readable.

Submitted by:   jdp@polstra.com (John Polstra)
1995-09-27 23:14:08 +00:00
Joerg Wunsch
19d57e6d9d Import Paul Kranenburg's man page for ld.so (aka. rtld).
Obtained from:	NetBSD
1995-08-26 13:17:39 +00:00
Doug Rabson
82aaeb09ad Change ld.so to correctly load dependant libraries for dlopen and unload them
on dlclose.  Also correctly call constructors and destructors for libraries
linked with /usr/lib/c++rt0.o.
Change interpretation of dlopen manpage to call _init() rather than init()
for dlopened objects.
Change c++rt0.o to avoid using atexit to call destructors, allowing dlclose to
call destructors when an object is unloaded.
Change interface between crt0 and ld.so to allow crt0 to call a function on
exit to call destructors for shared libraries explicitly.

These changes are backwards compatible.  Old binaries will work with the new
ld.so and new binaries will work with the old ld.so.  A version number has
been introduced in the crt0-ld.so interface to allow for future changes.

Reviewed by:	GAWollman, Craig Struble <cstruble@singularity.bevc.blacksburg.va.us>
1995-06-27 09:53:27 +00:00
Rodney W. Grimes
4399be3cbd Remove trailing whitespace. 1995-05-30 05:05:38 +00:00
Nate Williams
110aea11f2 Sync. up bits with Paul K. Cascade support plus some cosmetic changes.
Obtained from: NetBSD
1995-04-21 04:57:50 +00:00
Nate Williams
8af57ca9dd Removed /usr/local/lib from the standard library search path to be
consistant.  Programs shouldn't rely on non-standard paths for bringing
in default libraries.

Suggested by:	Andreas Schulz <ats@freebsd.first.gmd.de>
1995-03-19 21:20:09 +00:00
Nate Williams
c79eac4c4c Weak symbol support from NetBSD. This should bring us in sync with the
NetBSD ld code except for local changes for dlopen() and friends and
the hashing on the minor value of the shlibs.  We should be binary
compatible now with all their libraries.

Obtained from: NetBSD
1995-03-04 17:49:20 +00:00
Jordan K. Hubbard
19c408ae08 Support for more Sun compatible dlopen() and friends. Also added proper error
handling.
Reviewed by:	gj
Submitted by:	Mark Diekhans <markd@grizzly.com>
1995-02-07 13:33:42 +00:00