aboutsummaryrefslogtreecommitdiff
path: root/libexec/rtld-aout/rtld.c
Commit message (Collapse)AuthorAgeFilesLines
* Remove a.out runtime linker. It doesn't build and was removed from theTom Rhodes2005-01-111-2550/+0
| | | | | | | | | | | | | build over two years ago by peter. The binary a.out version of ld.so can be obtained from misc/compat22 or src/lib/compat/compat22. Discussed on: -arch Voted yes: jhb, ru, linimon, delphij Notes: svn path=/head/; revision=140038
* Correct typos, mostly s/ a / an / where appropriate. Some whitespace cleanup,Jens Schweikhardt2003-01-011-1/+1
| | | | | | | especially in troff files. Notes: svn path=/head/; revision=108533
* Assume __STDC__, remove non-__STDC__ code.Alfred Perlstein2002-05-281-23/+2
| | | | Notes: svn path=/head/; revision=97420
* Change brk's prototype from char *brk(const char *) to int brk(const void *)David Malone2002-01-241-1/+1
| | | | | | | | | | | | | | | | | | and sbrk's prototype from char *sbrk(int) to void *sbrk(intptr_t). This makes us more consistant with NetBSD and standards which include these functions. Bruce pointed out that ptrdiff_t would probably have been better than intptr_t, but this doesn't match other implimentations. Also remove local declarations of sbrk and unnecessary casting. PR: 32296 Tested by: Harti Brandt <brandt@fokus.gmd.de> MFC after: 1 month Notes: svn path=/head/; revision=89732
* Use STD{ERR,IN,OUT}_FILENO instead of their numeric values. TheSheldon Hearn2001-07-261-1/+1
| | | | | | | | | | definitions are more readable, and it's possible that they're more portable to pathalogical platforms. Submitted by: David Hill <david@phobia.ms> Notes: svn path=/head/; revision=80381
* Add `_PATH_DEVZERO'.David E. O'Brien2000-12-091-2/+3
| | | | | | | Use _PATH_* where where possible. Notes: svn path=/head/; revision=69793
* $Id$ -> $FreeBSD$Peter Wemm1999-08-281-1/+1
| | | | Notes: svn path=/head/; revision=50476
* Fix a bug in the handling of minor version numbers. Formerly, theJohn Polstra1998-11-071-13/+34
| | | | | | | | | | | | | | | | | | | rtld would accept the first shared library it found with the right major version number, even if the minor version number was too low. If a different version of the shared library with an adequate minor version number appeared later in the search path, it would not be found. Now the rtld searches all locations first looking for a library with a minor version that is high enough. Only if such a library is not found will it fall back to accepting a minor version number that is too low. As before, a warning comes out in that case. This solves some problems encountered when building an older world on a -current system. Notes: svn path=/head/; revision=40983
* Pass me the pointy hat with the extra sequins. Just a moment, while I getStephen McKay1998-08-221-6/+20
| | | | | | | | | | | | it to sit right... The __error() hack gave out the wrong address. It returned the address of errno in ld.so instead of the address of errno in the main program. Oops. The hack is now correct, just in time to be obsoleted by elf. Notes: svn path=/head/; revision=38480
* Since I got no objections to this patch, and no one has offered anyStephen McKay1998-06-211-1/+70
| | | | | | | | | | | | | | | alternative, I present .. ta! da! .. the __error() hack. This patch to the a.out dynamic loader provides old a.out binaries with __error() if they are linked with an older libc that lacks it, but are also linked against a library that needs it. There is a smaller, tricker hack that takes advantage of the fact that ld.so has __error() too, courtesy of the new libc, but this hack is the straightforward version. Notes: svn path=/head/; revision=37092
* Search for libraries in dlopen() when the specified pathBrian Somers1998-06-071-4/+9
| | | | | | | | | contains no ``/''s. Elf already searches it seems. Mostly submitted by: Mike Smith <mike@smith.net.au> Notes: svn path=/head/; revision=36717
* ELF preparation step 2:Søren Schmidt1998-05-261-2/+2
| | | | | | | | | | | | | | | | | Move a.out libraries to /usr/lib/aout to make space for ELF libs. Make rtld usr /usr/lib/aout as default library path. Make ldconfig reject /usr/lib as an a.out library path. Fix various Makefiles for LIBDIR!=/usr/lib breakage. This will after a make world & reboot give a system that no longer uses /usr/lib/*, infact one could remove all the old libraries there, they are not used anymore. We are getting close to an ELF make world, but I'll let this all settle for a week or two... Notes: svn path=/head/; revision=36397
* Implement dladdr.John Polstra1998-02-061-4/+94
| | | | Notes: svn path=/head/; revision=33137
* Make emacs work again. This is a workaround for the fact that theJohn Polstra1997-12-051-18/+33
| | | | | | | | | | | | | | | | | | | | | | | emacs a.out file, self-generated by emacs's "unexec" function in "unexsunos4.c", is invalid. In particular, its "_end" symbol has the wrong value. The dynamic linker was using the value of that symbol to initialize its sbrk break level. The workaround is to peek at the executable's a.out header in memory, and calculate what "_end" should be based on the segment sizes. I will work out a fix for emacs and send it to the FSF. This dynamic linker workaround is still worthwhile, if only to avoid forcing all emacs users to build a new version. Note: xemacs gives a bogus warning at startup, for related reasons. The warning is harmless and can safely be ignored. I will send a patch to the xemacs maintainers to get rid of it, and meanwhile add a patch file to our port. Notes: svn path=/head/; revision=31546
* Get rid of the dynamic linker's internal malloc package, and arrangeJohn Polstra1997-11-291-261/+469
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | things so that it uses the same malloc as is used by the program being executed. This has several advantages, the big one being that you can now debug core dumps from dynamically linked programs and get useful information out of them. Until now, that didn't work. The internal malloc package placed the tables describing the loaded shared libraries in a mapped region of high memory that was not written to core files. Thus the debugger had no way of determining what was loaded where in memory. Now that the dynamic linker uses the application's malloc package (normally, but not necessarily, the system malloc), its tables end up in the regular heap area where they will be included in core dumps. The debugger now works very well indeed, thank you very much. Also ... Bring the program a little closer to conformance with style(9). There is still a long way to go. Add minimal const correctness changes to get rid of compiler warnings caused by the recent const changes in <dlfcn.h> and <link.h>. Improve performance by eliminating redundant calculations of symbols' hash values. Notes: svn path=/head/; revision=31445
* Many places in the code NULL is used in integer context, wherePoul-Henning Kamp1997-09-181-2/+2
| | | | | | | | | | | | plain 0 should be used. This happens to work because we #define NULL to 0, but is stylistically wrong and can cause problems for people trying to port bits of code to other environments. PR: 2752 Submitted by: Arne Henrik Juul <arnej@imf.unit.no> Notes: svn path=/head/; revision=29574
* - In dlsym(), if the lookup fails using the original symbol, prepend anNate Williams1997-08-191-2/+30
| | | | | | | | | | underscore and try looking it up again. This is a non-issue if we switch to ELF. Reviewed by: sef, jdp Notes: svn path=/head/; revision=28434
* Implement dlsym(RTLD_NEXT, symbol).John Polstra1997-08-021-12/+64
| | | | Notes: svn path=/head/; revision=27838
* Revert $FreeBSD$ to $Id$Peter Wemm1997-02-221-1/+1
| | | | Notes: svn path=/head/; revision=22996
* Pay attention to the environment variable "LD_IGNORE_MISSING_OBJECTS".John Polstra1997-01-171-0/+11
| | | | | | | | | | | | 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. Notes: svn path=/head/; revision=21819
* If a library is found in the hints file, but the library doesn't exist,John Polstra1997-01-141-0/+4
| | | | | | | | | | | | 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 Notes: svn path=/head/; revision=21693
* Make the long-awaited change from $Id$ to $FreeBSD$Jordan K. Hubbard1997-01-141-1/+1
| | | | | | | | | | | 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. Notes: svn path=/head/; revision=21673
* Use the RTLD_NOW symbol, now that it is defined in <dlfcn.h>.John Polstra1997-01-121-4/+3
| | | | Notes: svn path=/head/; revision=21620
* Add support for the LD_BIND_NOW environment variable. If it is set to aJohn Polstra1997-01-121-16/+37
| | | | | | | | | | | | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=21577
* If errors occur during the loading of the shared libraries required byJohn Polstra1996-10-241-10/+30
| | | | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=19158
* Add the search directories from the hints file only the first time it isJohn Polstra1996-10-101-2/+5
| | | | | | | | | 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. Notes: svn path=/head/; revision=18862
* Fix a bug that caused a segmentation violation if dlsym() was calledJohn Polstra1996-10-101-2/+2
| | | | | | | with its first argument equal to NULL. Notes: svn path=/head/; revision=18849
* There's no need to 'unsetenv()' unsafe environment variables explicitlyNate Williams1996-10-011-6/+1
| | | | | | | | | 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. Notes: svn path=/head/; revision=18625
* Sigh, oh well, here's my obligigatory "oops" commit. I don't quite knowPeter Wemm1996-10-011-1/+13
| | | | | | | | | | 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> Notes: svn path=/head/; revision=18618
* Update to handle new version ld.so.hints and info in executable forPeter Wemm1996-10-011-54/+221
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=18599
* When checking to see whether a needed shared library has alreadyJohn Polstra1996-05-221-2/+36
| | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=15861
* Implement support for LD_PRELOAD in the dynamic linker. RemoveJohn Polstra1996-04-201-4/+102
| | | | | | | | | | 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> Notes: svn path=/head/; revision=15326
* This release is a moderate restructuring of the dynamic linker.John Polstra1996-01-131-590/+603
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=13406
* Changed the terminology for what used to be called the "memorizing"Nate Williams1995-11-021-184/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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> Notes: svn path=/head/; revision=12012
* Run-time linker speedups - Round OneNate Williams1995-10-251-3/+170
| | | | | | | | | | | | | | | | | | | | | | | 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" Notes: svn path=/head/; revision=11781
* Remove LD_NOSTD_PATH implementation, it isn't works andAndrey A. Chernov1995-10-241-4/+2
| | | | | | | | can cause some problems. Suggested-by: davidg Notes: svn path=/head/; revision=11766
* if uid != euid or gid != egid unsetenv("LD_NOSTD_PATH") tooAndrey A. Chernov1995-10-211-1/+2
| | | | Notes: svn path=/head/; revision=11617
* Make the error message more readable when 'ld.so' cannot locate a neededNate Williams1995-09-271-13/+11
| | | | | | | | | | | | | | | | | 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) Notes: svn path=/head/; revision=11041
* Fixup the "ld.so failed" message for the case when ld.so finds undefinedNate Williams1995-09-271-5/+5
| | | | | | | | | | | | | | 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) Notes: svn path=/head/; revision=11040
* Change ld.so to correctly load dependant libraries for dlopen and unload themDoug Rabson1995-06-271-66/+234
| | | | | | | | | | | | | | | | | | | | 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> Notes: svn path=/head/; revision=9335
* Remove trailing whitespace.Rodney W. Grimes1995-05-301-6/+6
| | | | Notes: svn path=/head/; revision=8858
* Sync. up bits with Paul K. Cascade support plus some cosmetic changes.Nate Williams1995-04-211-13/+60
| | | | | | | Obtained from: NetBSD Notes: svn path=/head/; revision=7971
* Weak symbol support from NetBSD. This should bring us in sync with theNate Williams1995-03-041-54/+56
| | | | | | | | | | | 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 Notes: svn path=/head/; revision=6887
* Support for more Sun compatible dlopen() and friends. Also added proper errorJordan K. Hubbard1995-02-071-86/+204
| | | | | | | | | handling. Reviewed by: gj Submitted by: Mark Diekhans <markd@grizzly.com> Notes: svn path=/head/; revision=6234
* Make ldconfig and ld.so not hashing the shared lib minor number. ThisJoerg Wunsch1995-01-121-6/+5
| | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=5551
* Updated to recent version of Paul K.'s shlib code. This code has betterNate Williams1994-12-231-28/+37
| | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=5205
* Unmap hints file when finished with it, so that it can go awayBruce Evans1994-09-151-1/+21
| | | | | | | | | | 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. Notes: svn path=/head/; revision=2812
* Changes from Paul Kranenburg which bring us into sync with his sources:Rich Murphey1994-06-151-55/+79
| | | | | | | | | | | | | | | | | handling of errors through the standard err() and warn() more fixes for Geoff Rehmet's NULL pointer bug. fixes NULL pointer bugs when linking mono and nested X servers. supports a `-nostdlib' option. accept object files without a symbol table don't attempt dynamic linking when `-A' is given a few variable names have chaged (desc -> fd), and the formatting has changed which should make it much easier to track his sources. I tested 'make world' for /usr/src and X twice with these changes. Notes: svn path=/head/; revision=1741
* Change the private declarations from dlopen,dlclose,dlsym,dlctlAndreas Schulz1994-04-131-10/+10
| | | | | | | | | to public. These functions are also used in /usr/include/link.h, so it looks, like they shouldn't be private. I will ask Paul about that, if this is correct. Notes: svn path=/head/; revision=1361
* This is Paul K's latest set of ld changes. A commit was necessary at thisJordan K. Hubbard1994-02-131-406/+606
| | | | | | | | | | | | | late stage due to the fact that link.h was copyright Sun Microsystems. This version of ld sync's us up with NetBSD's ld and supports compatablily with NetBSD's -[zZ] flags (which we had reversed). Compiling with this new ld will give you RRS warnings for libraries which do not contain .type infomation - these wsarnings are harmless and will go away as soon as you recompile your libraries (cd /usr/src; make libraries). Notes: svn path=/head/; revision=1153