Commit Graph

111 Commits

Author SHA1 Message Date
Bill Paul a13bb127d2 Aw c'mon. I'm being driven mad by plenty of other things. I don't
need this.

Consider the following code:

	case 'O':
		output_filename = malloc(strlen(arg)+4);
		strcpy(output_filename, arg);
		strcat(output_filename, ".tmp");
		real_output_filename = arg;
		return;

The idea here is to malloc() a buffer big enough to hold the name of
a supplied file name, plus ".tmp". So we malloc() 'size of filename'
bytes plus 4, right? Wrong! ".tmp" is _FIVE_ bytes long! There's a
traling '\0' which strcat() gleefully tacks on _outside_ the bounds
of the buffer. Result: program corrupts own memory. Program SEGVs at
seemingly random times. Bill not like random SEGVs. Bill smash.

Know how I found this? I've been trying to bootstrap -current on my
2.1.0-RELEASE machine at work and I couldn't seem to get libc.a built
because the linker would intermittently blow chunks while executing
things like 'ld -O foo.o -X -r foo.o'. Since this is an initial
bootstrap version of ld, it was linked against the 2.1.0 libc, who's
malloc() behaves differently than that in -current.

Presumeably ld -O doesn't blow up in -current, otherwise someone would
have spotted this already. I don't know if this is a bug or a feature.

Anyway. I'm changing the strlen(arg)+4 to strlen(arg)+5. Bah.
1996-06-08 04:52:57 +00:00
Poul-Henning Kamp b5938566d8 Add an option -O <filename> to ld. From the manpage:
-O filename
             Specifies the name of the output file.  The file is created as
             filename.tmp and when output is complete renamed to filename.
This allows us to:
	ld -O ${.TARGET} -x -r ${.TARGET}
1996-05-28 16:17:48 +00:00
John Polstra 20c29c9fd8 Zero out an unused field in a structure that is written to the output
file.  The field formerly contained random garbage, leading to spurious
differences between otherwise identical executables and libraries.

Submitted by:	Bruce Evans <bde@freebsd.org>
1996-05-27 18:06:02 +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 55e214c197 When a local symbol that would normally be eliminated by "-x" or
"-X" must survive, because of references from relocations, don't
qualify the symbol name with the name of the input file.  This
saves some string space.  It makes libc_pic.a about 2.4% smaller.

Adapted from a suggestion by Bruce Evans.
1996-04-24 23:31:08 +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
Mike Pritchard edf0e5b3f8 Correct some man page xrefs, and some other minor changes to bring some
man pages up to mdoc guidelines and fix some minor formatting glitches.
Also fixed a number of man pages to not abuse the .Xr macro to
display functions and path names and a lot of other junk.
1996-04-08 04:18:31 +00:00
Paul Traina 0f6b2cb3f8 Bring in some of Paul K's fixes for ldconfig from NetBSD-current.
This solves the problem of being unable to use shared libraries with dots
in their names before the ".so.<version>" code.

This should be brought into -stable.

There are more changes from Paul that look like they should be included,
but they change the format of the hints file, so I'm not going to bring them
in now (but we should in the future).

Obtained from: pk@netbsd.org
1996-02-26 02:22:33 +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
Peter Wemm a5b996a7ec recording cvs-1.6 file death 1995-12-30 19:02:48 +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
Bruce Evans 7da87484df Fix checks for open() failing. open() may successfully return 0.
ld.c:
Fix a an error message that said that open() failed after fopen() failed.
1995-09-28 19:43:22 +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
Poul-Henning Kamp 0ad2ff70ee Stop using gnumalloc. 1995-09-22 14:14:32 +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
Joerg Wunsch 1c7895ac54 Reset the umask before creating the output file; otherwise running
ldconfig as root with a restrictive umask yielded ld.so.hints
unreadable by the world (and thus useless).
1995-08-16 06:31:50 +00:00
Rodney W. Grimes c7e5c6a843 Make ld's error messages consistent with gcc when no input files
are given on the command line.

Submitted by:	Thomas Graichen <graichen@omega.physik.fu-berlin.de>
1995-07-13 08:30:07 +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
Satoshi Asami f606c848fa Add an "-m" flag to merge instead of replace the entries. We can
now safely add a line like

ldconfig -m ${PREFIX}/lib

in ports' Makefiles and packing lists without throwing away some
directories the user may have added.

Submitted by:   Mostly by Paul Kranenburg <pk@cs.few.eur.nl>
1995-06-24 10:08:44 +00:00
Joerg Wunsch 5fbea18fbe Make `ld' properly honoring the umask setting when chmod'ing the
output file for the `x' bits.

This is a Posix requirement.
1995-06-14 06:25:09 +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 7e613ac7bd Back out my change to enforce command line linker order due to
underlying bugs which are caused by mixing static/shared libraries with
this change in place.

The shlib code is not capable of supporting this feature in it's present
state and will need significant modifications in order to do so.
1995-04-07 05:08:28 +00:00
Nate Williams 4979433a3c Modify the default behavior of the linker to no longer prefer static
members over shared library members.  This modification causes the linker
to use the first definition it sees for a symbol instead of having
priorities based on the library type.  This modification should allow
gdb to compile again.

Obtained from:
  Email conversation with Paul Kranenbury, but implemented completely by
  me.  If it doesn't work, it's my fault not his.
1995-03-22 19:38:07 +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
David Greenman 28b6ade77a Back out Poul's hack that forces static libgcc. This has been fixed via
gcc instead.
1995-03-10 19:41:50 +00:00
Poul-Henning Kamp 316f7f7725 Never again shall we link libgcc dynamic. It was a big mistake in the
first place and we were too long in finding out.  Now we know, and the
damage is hard to fix.  This is part one:  ld will not link gcc dynamic,
if specified as "-lgcc".

Suggested by:	dyson & davidg
1995-03-06 08:00:23 +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
Joerg Wunsch d5453ba5c4 Make ldconfig and ld.so not hashing the shared lib minor number. This
misfeature caused troubles when a program attempted to access a shlib
where one with a higher minor number has been hashed.  Ldconfig does
only include the highest-numbered shlib anyway, so this is in no way a
limitation of generality.

Caution: after installing the new programs, your /var/run/ld.so.hints
needs to be rebuiult; run ldconfig again as it's done from /etc/rc.
1995-01-12 19:12:29 +00:00
Steven Wallace e86257e166 Change to
#define STANDARD_SEARCH_DIRS    "/usr/lib", "/usr/X11R6/lib", "/usr/local/lib"
Like in 2.0R, except without /usr/X386.
1995-01-05 02:36:29 +00:00
Nate Williams 7edb8c9b99 New file from pk to aid new in developing the shlib code for new
architectures.

Obtained from: NetBSD
1994-12-23 22:56:08 +00:00
Nate Williams 61f9ce8d32 Updated to recent version of Paul K.'s shlib code. This code has better
warning handling and allows for link-time warnings with a modified
version of gas.

Note: Not all of the newer bits were updated such as some of the non-x86
machine-dependant code is relevant to FreeBSD right now.

Obtained from: NetBSD
1994-12-23 22:31:35 +00:00
Andreas Schulz 3b92fb1ec6 Changed one occurrence of LD 8 to LD 1 and the OS FreeBSD 1.1 to FreeBSD 2.0. 1994-12-11 21:39:31 +00:00
Steven Wallace 504e8b978b Add LDDESTDIR to ld command.
Add -I${DESTDIR}/usr/include to cpp command.
1994-09-18 19:41:38 +00:00
Bruce Evans dd8e0158cf Unmap hints file when finished with it, so that it can go away
completely when ldconfig unlinks it.  If init is shared, then the
referenced unlinked copy of the hints file created by running
ldconfig in /etc/rc caused the file system to be unclean after
every reboot.
1994-09-15 20:48:55 +00:00
Bruce Evans 2577a8acef Add dependencies on libraries to DPADD. Someday this should be done
automagically.  -lfoo has to be right to work, but ${LIBFO0} is too
easy to forget or misspell; nothing checks it and it should be
different for shared libraries.
1994-08-28 18:49:06 +00:00
Garrett Wollman e410457b74 Install ld.so immutable. 1994-08-26 19:11:14 +00:00
David Greenman e4e244ac16 Don't explicitly define __FreeBSD__ - this is no longer necessary. 1994-08-19 12:24:45 +00:00