Commit Graph

656 Commits

Author SHA1 Message Date
matt
0655a07988 Fix bug where only 2/3 of the PLT was being synched with the icache.
PLT entries are 12 bytes.  Add a #define for that and replace the
explicit values with the PLT_ENTRY_SIZE.  This bug can cause random
SIGILL signals to happen.
2003-01-11 01:33:56 +00:00
junyoung
8707cd2a36 Gracefully exit when invoked directly. Use of assert() here caused a segfault.
Address PR#11785.
2002-12-14 15:37:57 +00:00
junyoung
9e11602ee9 Remove comment which is not true any more. alpha and i386 support
R_xxx_COPY relocations.
2002-12-14 09:13:00 +00:00
junyoung
fd1f5e8f1b A bit speedup: in _rtld_load_object(), save the number of calls to
strcmp() by performing path name length comparison first. In the test
with Mozilla, the number was reduced to 1068 from 7182 (yes, we saved
6114 strcmp()!).
2002-12-05 04:56:56 +00:00
thorpej
044aeabaad Bintuils-current initializes the GOT entries to 0 (instead of the
base-relative offsets that were placed there previously), so we
must use a different mechanism to compute our reloc base.

Patch from Charles Hannum.
2002-12-04 01:19:37 +00:00
mycroft
be3692c5a7 Back out the last two changes. They were misguided, and the code worked
correctly before.
2002-11-25 19:49:25 +00:00
fvdl
100e201ec6 Replace return -1 in rtld_bind with _rtld_die() call. 2002-11-24 18:19:23 +00:00
fvdl
d93db1cfce Implement self-relocation as is required now. 2002-11-24 18:16:45 +00:00
fvdl
5505734fa9 For the debug case, print relocbase as well at the start of _rtld(). 2002-11-24 18:13:30 +00:00
junyoung
2cc0cde8f5 Now _rtld_relocate_objects() returns with error as soon as any of
subsequent calls in it fails.

Spotted by wiz and enami.
2002-11-22 04:39:37 +00:00
junyoung
b5ffe4c33c Simplify code a bit. 2002-11-21 19:09:56 +00:00
nathanw
15f633fbd3 In _rtld_load_library(), ensure that the old _rtld_error state (a message from
a previous error, or NULL) is preserved if the search eventually succeeds.

Addresses the problem pointed out in PR pkg/19024.
2002-11-14 21:07:46 +00:00
nathanw
6c24ccfd1f Remove "extern const chat *_rtld_error_message;". There is no such
variable, and never has been.
2002-11-14 20:11:48 +00:00
matt
01ba93bc3c Convert to register prefixes. 2002-10-31 20:23:25 +00:00
thorpej
b777dba640 _rtld_bind(): Don't use "rela" until after we've (potentially) adjusted
it.
2002-10-18 20:35:25 +00:00
junyoung
d0c512001c Embedded whitespace in dirname is supported again. 2002-10-06 01:36:36 +00:00
junyoung
2036ad0c3f A line whose length is 0 always begins with '#'. 2002-10-05 16:26:37 +00:00
junyoung
e4d4608a8b Minor cleanup. 2002-10-05 16:13:31 +00:00
junyoung
1b5e50eb7b Disable DEBUG again. 2002-10-05 15:52:15 +00:00
junyoung
2e85345237 Better fix of parser bug. 2002-10-05 15:43:56 +00:00
junyoung
89342b95bb Don't call _rtld_process_mapping() with null string. 2002-10-05 15:04:49 +00:00
mycroft
80b0665a93 Simplify the hint file parser a bit. 2002-10-05 12:23:39 +00:00
mycroft
ad8ccd6290 Minor cleanup. 2002-10-05 11:59:03 +00:00
mycroft
5d4bc1adf5 Make this work for ldd again. 2002-10-05 00:13:27 +00:00
mycroft
2a88686d7a Recode _rtld_elf_hash() so it compiles better (at least on i386 and arm).
Still could be better on i386, but only written in assembler...
2002-10-04 20:34:10 +00:00
mycroft
6f56cdc91f Rearrange _rtld_map_object() a little, so that we don't have to have the first
page of the object double-mapped.  Not that it matters much, but someone was
whinging about it.
While I'm at it, nuke obj->phdr and obj->phsize; they're unused.
2002-10-04 18:50:43 +00:00
mycroft
0a519951b5 Pull out some objlist functions in ldd. 2002-10-04 04:04:26 +00:00
mycroft
3c57a33db5 Don't actually bother maintaining _rtld_list_main and _rtld_list_global in
ldd.
2002-10-04 04:01:13 +00:00
mycroft
dfaba15604 Move the definition of _rtld_list_main so ldd builds again. 2002-10-04 03:59:40 +00:00
mycroft
4172074119 Skip the lazy PLT relocation if relocbase==0 (useful if libraries are loaded
at their VMA address).
2002-10-03 20:39:22 +00:00
mycroft
7a48cdb883 As seen on tech-userlevel...
There are several optimizations here:

1) Objects on _rtld_list_main do not participate in the DAG structures
   at all.  This is okay because all symbols must be resolvable at
   link/load time, and _rtld_list_main is always searched first, so
   any references from those objects must necessarily be resolved to
   other objects on _rtld_list_main.

   (Making this work completely required setting obj->main a bit
   earlier; hence the RTLD_MAIN hack.)

2) Objects on _rtld_list_main are not put on _rtld_list_global,
   preventing an extra search.

3) A bit is used to keep track of whether an object is on
   _rtld_list_global, so we don't have to do a silly linear search.

4) A small attempt is made to prevent objects being put on the DAG
   lists multiple times (using a silly linear search).

The sum of this appears to be a ~10% (.3s) reduction in Mozilla's
startup time on my 800MHz box.

Also, make sure _rtld_objmain->path is always set, just to make the
debug output nicer.
2002-10-03 20:35:19 +00:00
mycroft
f66c66a92c Do not put objects on _rtld_list_main on any DAG member list -- any symbol we
will have already been found during the _rtld_list_main walk, so there's no
point in doing it again.
2002-10-03 01:09:21 +00:00
junyoung
a189aa3eba Store pathnames of shared objects not found in search paths in cache
and utilize it. This greatly reduces the number of calls to open(2) and
malloc(3) for programs like mozilla that depend on many shared objects
while it doesn't affect performance of small programs.
2002-10-01 14:16:53 +00:00
wiz
d6285bbf1d Begin new sentences on new lines.
Patch from Robert Elz (kre at munnari oz au).
2002-09-29 14:05:52 +00:00
junyoung
b615e15549 Call NEW() rather than CNEW(). 2002-09-28 05:00:27 +00:00
thorpej
09a0767aa9 Only use the MKDYNAMICROOT semantics (i.e. -rpath=/lib,/usr/lib and
-dynamic-linker=/libexec/ld.elf_so) if the BINDIR of the program being
built is /bin or /sbin.

The reason we do this is because now all programs *except* those in
/bin and /sbin (i.e. the "special cases") match the default the compiler
uses, which is what is used for things in e.g. xsrc, pkgsrc, and other
random 3rd party programs.

This is done by decoupling where a shlib is installed from how it
is located.  Two new variables, SHLIBINSTALLDIR and SHLINKINSTALLDIR,
contain the former information, and key off MKDYNAMICROOT only.  SHLIBDIR
and SHLINKDIR contain the latter, and key off MKDYNAMICROOT and BINDIR.

The SHLIBINSTALLDIR, SHLIBDIR, _LIBSODIR, SHLINKINSTALLDIR, and
SHLINKDIR parameters are moved to a new <bsd.shlib.mk>; see bsd.README
for usage details.
2002-09-27 21:37:50 +00:00
mycroft
c5739d43db Change the munmap() of the text-data gap to mprotect(PROT_NONE). This avoids
having scattered little mappings, although it's probably not the best way...
2002-09-27 19:48:24 +00:00
mycroft
0a20e1e977 We don't need to save r7, either... 2002-09-27 03:46:12 +00:00
mycroft
b95736d94a Put back the short-circuiting code -- Matt claims there are functions that rely
on it.
OTOH, don't bother saving r6 a second time.
2002-09-27 03:34:22 +00:00
mycroft
6d8d08304c 1) There is no reason to flush the I$ here, given that we do not modify any
instructions.  Function calls use GOT indirection, and we only patch the
   GOT.
2) The mask-comparison optimization always fails, because the saved mask
   always has 0x2000 set, and the PLT stub mask never does.  So, remove it.
2002-09-27 02:46:05 +00:00
mycroft
42fb5b53c2 Save one more instruction. 2002-09-27 02:14:38 +00:00
mycroft
06f9fa98b0 Save relocbase in %r10, not %r1.
Also, save one instruction.
2002-09-26 23:28:52 +00:00
mycroft
d437f6520b Implement a self-relocate function for the VAX. 2002-09-26 22:26:26 +00:00
mycroft
1c495430dd Remove the `self' args to _rtld_relocate_objects() and
_rtld_relocate_nonplt_objects().
2002-09-26 20:42:10 +00:00
mycroft
7d4bbc7f4e Add an iffy heuristic that allows us to do lazy binding with new objects, but
detect old objects and deal with them.
2002-09-26 20:41:34 +00:00
mycroft
73a80999b7 Clean up _rtld_init() -- there is no need to avoid globals.
Remove the call to _rtld_relocate_objects() completely -- except on VAX, where
we TEMPORARILY call _rtld_relocate_nonplt_objects() directly.
Also add more assertions -- ld.elf_so should never have PLT relocations.
2002-09-26 20:35:56 +00:00
mycroft
5f24ee89f3 Don't bogusly set obj->pltrela{,lim} if there is no DT_PLTREL. 2002-09-26 20:27:50 +00:00
mycroft
a217e118cd *poof*
-fomit-frame-pointer works on 68k.
2002-09-26 14:30:47 +00:00
mycroft
3e9c6b1044 -vomit-frame-pointer is buggy on 68k. *sigh* 2002-09-26 13:56:01 +00:00
mycroft
273d2b19b4 Hm, the const isn't going to work. 2002-09-26 13:43:52 +00:00
mycroft
00088c228c Do not attempt to free(_rtld_objself.path) -- it's a pointer into our data
segment.
2002-09-26 13:42:05 +00:00
mycroft
f4f740de3a By default, compile without DEBUG, and with -fomit-frame-pointer. 2002-09-26 12:59:29 +00:00
mycroft
15025431b4 Update a comment. 2002-09-26 03:25:29 +00:00
mycroft
fd7e0d92f3 Add a rdbg() in _rtld_bind(). 2002-09-26 02:52:05 +00:00
mycroft
723a5f8a50 Remove a meaningless bit from a rdbg(). 2002-09-26 02:51:27 +00:00
mycroft
ee398b4d07 Remove vestigal comments about _rtld_bind_start_0() -- it works now. 2002-09-26 02:25:57 +00:00
mycroft
26043b23b0 Make room for the argument save area in _rtld_start(). The PLT stub already
made room from _rtld_bind_start(), but add a comment explaining the instruction
it uses.
2002-09-26 02:14:10 +00:00
mycroft
f1c792d648 Make the stack frame 96 bytes, like GCC does. 2002-09-26 02:05:41 +00:00
mycroft
bde7a965da Tweak the save instruction in the PLT stub rather than adding an instruction
to the binder entry stub...
2002-09-26 01:59:16 +00:00
mycroft
d314d82b47 Allocate space for the argument space area in both _rtld_start() and
_rtld_bind_start().  Not needed normally, but if we compile ld.elf_so with
-g, it blows up without this.
2002-09-26 01:54:52 +00:00
mycroft
6bff9ffc3d For consistency, use Elf_Word* to point to code, not Elf_Addr*. 2002-09-25 22:33:54 +00:00
mycroft
0079455251 Add a comment explaining some of the magick. 2002-09-25 22:29:12 +00:00
mycroft
f6db390b5a Fix a bug that caused PLT entries to effectively not be patched.
Also, fix more bugs in the large-PLT case -- my test program works now.
2002-09-25 22:25:11 +00:00
mycroft
2997d64776 Make this work with PLTs larger than 8192 entries (64KB). Not tested
exhaustively, but it works in some simple cases.
2002-09-25 21:11:18 +00:00
mycroft
d4e6f3ff08 Swap registers %o0 and %o1 in the binder stub to say one instruction.
Fix an obvious bug in the 64-bit PLT fixup: the SLLX was by 12 bits, when it
should be 32.

Fix what *appear* to be two bugs in the >32768 PLT entry stub:
* One division was wrong (/14 rather than /24).
* We need to subtract 1048576 (to make the offset relative to the beginning of
  the upper section), not add it.
This path is still untested, and buggy.
2002-09-25 16:35:08 +00:00
mycroft
9e31b44846 There is no need to save and restore a second register window in the binder
stub.
2002-09-25 14:38:51 +00:00
mycroft
afb1082706 _rtld_bind_start_0_stub() is not actually used. 2002-09-25 14:36:37 +00:00
mycroft
028dd5150a Push a multiple from _rtld_bind_start_[01]() to _rtld_bind(). 2002-09-25 14:35:39 +00:00
mycroft
23b2275ee8 Partly fix this port -- still needs a self-reloc function. 2002-09-25 08:37:57 +00:00
mycroft
a9c999925c We don't need to save quite as many registers in the stub. 2002-09-25 08:00:26 +00:00
mycroft
729925dfb9 Push the _rtld_bind() interface into MD code -- it's just a trivial wrapper
anyway.
2002-09-25 07:27:49 +00:00
mycroft
305b0ffce5 #if defined -> #ifdef 2002-09-25 06:43:46 +00:00
mycroft
896795d8a3 Minor cleanup, for clarity. 2002-09-25 03:57:15 +00:00
mycroft
a3c903f7cb Resolve the GOT before doing relocations. Then, when doing relocations, for
symbols in the global part of the symbol table, use the updated GOT entry
rather than doing a lookup.  (This provides the same effect as `-z combreloc'
on other platforms -- at most one lookup is done per symbol.)

Unfortunately, it is necessary to turn off lazy binding on MIPS.  As the
comment says:

                         * XXX DANGER WILL ROBINSON!
                         * You might think this is stupid, as it intentionally
                         * defeats lazy binding -- and you'd be right.
                         * Unfortunately, for lazy binding to work right, we
                         * need to a way to force the GOT slots used for
                         * function pointers to be resolved immediately.  This
                         * is supposed to be done automatically by the linker,
                         * by not outputting a PLT slot and setting st_value
                         * to 0, but GNU ld does not do so reliably.
2002-09-25 03:52:06 +00:00
mycroft
646628d7fa DOH! Adjust all the stack slots in _rtld_bind_start() so that the saved $a0
is not in _rtld_bind_mips()'s $a3 argument save area.
2002-09-24 21:57:20 +00:00
mycroft
fb3dfbb81b Add a comment about the function pointer nonsense. 2002-09-24 20:27:07 +00:00
mycroft
216a20fcc4 Put back the `in_plt' nonsense for now.
It turns out there is some deep-seated wackiness WRT function pointer
comparisons...
2002-09-24 20:23:11 +00:00
mycroft
9d1d2c30c8 Reverse the previous patch, but make the dbg()s more informative. 2002-09-24 18:28:42 +00:00
mycroft
8510028476 Touch up a little more -- some of the dbg()s never actually printed anything. 2002-09-24 18:25:54 +00:00
mycroft
1ad20cb78f Previous change was done wrong. 2002-09-24 18:23:14 +00:00
junyoung
d0e76e42b6 G/c dbg()'s. 2002-09-24 18:03:46 +00:00
junyoung
5afbf1cbce Make sure that dbg() is disabled if LD_DEBUG is not defined. Now
debugging is easier with RTLD_DEBUG_RELOC.
2002-09-24 17:51:11 +00:00
mycroft
64d3d6215a Ignore JMP_SLOT relocs when doing non-PLT relocations. The relalim trimming
hack doesn't always work, because ld(1) sometimes puts the sections in the
wrong order.
2002-09-24 15:04:48 +00:00
mycroft
bddb0d021d Similarly, remove support for short arguments. 2002-09-24 14:09:43 +00:00
mycroft
fa344ccc4b Remove quad support. We don't need it, and it wastes a lot of space. (It
pulls in {,u}{div,mod}di3() and qdivrem().)
2002-09-24 14:05:33 +00:00
mycroft
56288dc0e5 %ld -> %p 2002-09-24 13:59:31 +00:00
mycroft
fa5df29420 Include xassert() only if DEBUG, like the real assert().
Also, xassert() calls abort(), so there's no need to do it in all of the
callers.
2002-09-24 13:06:07 +00:00
mycroft
7f44855294 Remove the SVR4_LIBDIR madness. 2002-09-24 12:52:20 +00:00
mycroft
3c16ffb1dd Woops, unmap the first page in the `win' case, too.
Tidy up a bit.
2002-09-24 12:44:58 +00:00
mycroft
72b0e512c3 Change the comment about l_offs. 2002-09-24 12:18:32 +00:00
mycroft
9d8c69b929 Remove vestiges of VARPSZ. 2002-09-24 12:12:07 +00:00
junyoung
175c20cbcf Nuke PAGESIZE. 2002-09-24 09:45:59 +00:00
junyoung
4b4a707c66 Use _rtld_pagesz instead of PAGESIZE. 2002-09-24 09:35:13 +00:00
junyoung
d190613fbb space -> tab. 2002-09-24 09:26:43 +00:00
junyoung
93f2d9023a Don't need to use union any longer. 2002-09-24 09:22:51 +00:00
junyoung
272e959468 Remove '\n' at the end of dbg strings. 2002-09-24 08:56:30 +00:00
junyoung
61e1361da6 END_SYM is no longer used. 2002-09-24 06:43:14 +00:00
mycroft
97aed9957d -I${.CURDIR} is done at the top-level, so there's no need to do it here. 2002-09-24 01:59:44 +00:00
mycroft
b59c269424 Nuke reference to RTLD_RELOCATE_SELF. 2002-09-24 01:58:44 +00:00
mycroft
c3ece2a45f Use/require AT_PAGESZ on all platforms. (The kernel has exported it for ~3
years now.)  Use _rtld_pagesz instead of getpagesize() to determine the page
size in our local malloc().  Saves a system call.

Also, since we're now relocated early, we don't need to be careful to avoid
globals, so most of the VARPSZ hacks are eliminated.
2002-09-24 01:24:44 +00:00
mycroft
d1351c627c Um, a little bit of sanity here:
l_addr is always supposed to be obj->relocbase -- or so says the GDB code that
uses it.  So, set it to this on all platforms.  It already was on VAX
explicitly, and on everything else except MIPS implicitly (because
mapbase==relocbase for all existing shlibs).  For some silly/stupid reason, a
new field was created that the MIPS GDB currently uses.
Another MD #ifdef bites it.
2002-09-24 00:33:39 +00:00
mycroft
f1184d192e Very minor cleanup of the previous. 2002-09-24 00:02:46 +00:00
mycroft
86103e2f0e Several small changes that shave 7-8% off the simple-exec-loop test:
* Rename _rtld_find_library() to _rtld_load_library().  It now calls
  _rtld_load_object() if necessary to actually load the object, rather
  than having the caller do it.  To do this, it also takes the `mode'
  argument that gets passed to _rtld_load_object().

* On a related note, remove _rtld_check_library(), and instead call
  _rtld_load_object() to instead try actually loading the object.  We
  save two extra namei's and a bunch of redundant work (almost
  literally the same code) this way.

* In _rtld_map_object(), mmap(2) the first page read-only, rather than
  read(2)ing it.

* In _rtld_symlook_obj(), compare the *second* character of the symbol
  name before calling strcmp().  (This first character is too
  frequently `_', and turns out to not be helpful, in libc.)

* Also in _rtld_symlook_obj(), remove the bogus STT_FUNC special case
  -- this also allows removing the `in_plt' argument to
  _rtld_symlook_list() and _rtld_symlook_obj().

Also:

* In _rtld_obj_from_addr(), rather than trying to look up `_end' in
  the each object, instead use obj->mapsize as the upper bound.
2002-09-23 23:56:46 +00:00
mycroft
c3a2d8b7ba Add combreloc code here too. 2002-09-21 17:51:44 +00:00
junyoung
930998f892 Print the name of dynamic linker actually loaded. 2002-09-21 05:24:17 +00:00
junyoung
48910dcfc1 Cosmetic changes (long lines). 2002-09-20 03:39:22 +00:00
junyoung
18139870a5 Cosmetic changes. 2002-09-19 14:05:37 +00:00
christos
6d0f752a65 don't core dump setting progname if argv[0] == NULL. From xs@kittenz.org 2002-09-19 13:59:46 +00:00
junyoung
a5390eb121 _rtld_setup_pltgot() belongs to reloc.c. 2002-09-18 07:35:40 +00:00
junyoung
9754fa4d8e Make immediate binding work again by actually implementing
_rtld_relocate_plt_objects(). Note that this is for i386 only;
any efforts to make it work on other platforms are left to
those who are using them...
2002-09-17 07:29:46 +00:00
thorpej
7e6d181789 No PC24 relocs will ever be unaligned. Pointed out by mycroft. 2002-09-15 01:08:04 +00:00
thorpej
672853f217 It is possible for reloc entries to point to unaligned locations; handle
this.
2002-09-15 00:52:08 +00:00
thorpej
a2130a3a09 It is possible for reloc entries to point to unaligned locations; handle
this.
2002-09-14 23:53:21 +00:00
thorpej
b01748bb26 It is possible for reloc entries to point to unaligned locations; handle
this.
2002-09-14 23:21:13 +00:00
mycroft
a95d62a38e In _rtld_bind_mips(), if the symbol is undefined, die. 2002-09-13 20:32:24 +00:00
mycroft
712b838f43 Kill the extra newline in assert messages. 2002-09-13 19:50:00 +00:00
mycroft
cc2b1e9844 Add an explanatory comment. 2002-09-13 19:27:19 +00:00
mycroft
e3db70741f Turn DEBUG back on by default. It doesn't take much space. 2002-09-13 18:28:58 +00:00
mycroft
60330f4a69 The sense of the SHN_ABS test has always been reversed. Fortunately nobody
ever tried to reference stuff like _DYNAMIC_LINK and _gp_disp in C code...
2002-09-13 17:36:00 +00:00
mycroft
8f7fa0cfde Put back the lazy binding. For some bizarre reason, the linker occasionally
does not create a PLT entry for a symbol, so we test st_value!=0 to see
whether we can do a PLT fixup.
2002-09-13 17:07:12 +00:00
mycroft
a8dd8878cf Er, turn off lazy binding for the moment. It doesn't seem to be fully working. 2002-09-13 16:54:14 +00:00
mycroft
c1cf8538ec Simplify the GOT relocation code somewhat. 2002-09-13 16:31:28 +00:00
mycroft
e8b2fe1d2a Actually do lazy binding on this platform. 2002-09-13 16:03:20 +00:00
mycroft
89a39bb54e The textrel special case is only needed for MIPS (due to a bug in BFD). 2002-09-13 15:27:30 +00:00
mycroft
7a962f974a Kill the sparc64 argc conversion hack. 2002-09-13 14:23:07 +00:00
mycroft
a18c524897 Figure out obj->pltrel(a) after the dynamic section is parsed, so the relative
order of DT_PLTREL and DT_JMPREL is irrelevant.  Removes the need for yet
another weird #ifdef.
Also, be slightly more careful with the rel(a)lim trimming.
2002-09-13 13:28:43 +00:00
mycroft
c74fdd7069 Use the addend on GLOB_DAT relocs (same as ABS32). 2002-09-13 05:45:46 +00:00
mycroft
c65330320a Do not use the implicit addend on REFQUAD relocs (same as GLOB_DAT). 2002-09-13 05:45:13 +00:00
mycroft
daf8118731 Remove an old comment. 2002-09-13 04:09:49 +00:00
mycroft
2f59687514 Almost all of the items in here are done. 2002-09-13 04:05:00 +00:00
mycroft
777a2b8bb0 If we match a symbol name, but it's undefined, do not continue searching the
hash chain.
2002-09-13 03:40:40 +00:00
mycroft
bbe45a0623 Remove a dumb #ifdef -- if VARPSZ is not defined on sparc, the build will
bomb anyway.
2002-09-13 03:22:08 +00:00
mycroft
4de09f873b Nuke an unneeded hack for the Alpha. 2002-09-13 03:17:21 +00:00
mycroft
807a6ace45 Nuke two frivolous assert()s. 2002-09-13 03:12:40 +00:00
mycroft
4b55da479c _rtld_bind() is not used on MIPS. Should probably move it to MD code. 2002-09-13 03:09:38 +00:00
mycroft
f64e457cee Remove one more `dodebug' argument. 2002-09-12 23:11:37 +00:00
mycroft
a3b892d178 Nuke -DRTLD_RELOCATE_SELF and `dodebug' from orbit. 2002-09-12 22:56:28 +00:00
mycroft
f13bdd9850 Add some consts. 2002-09-12 21:06:38 +00:00
mycroft
5ad776fbd2 Move another declaration that doesn't belong in MI source. 2002-09-12 20:27:34 +00:00
mycroft
de4565ee93 Prototype different functions. 2002-09-12 20:24:03 +00:00
mycroft
547bc13b97 _rtld_bind_start() is not used in MI code, so declare it in the MD code. 2002-09-12 20:20:58 +00:00
mycroft
bf04efbfda ld.elf_so has no textrels on arm, i386 or vax -- and shouldn't on any platform,
but that's beside the point.
2002-09-12 19:43:03 +00:00
mycroft
6530c89689 Slight tweak. 2002-09-12 18:43:17 +00:00
mycroft
326f270bfb The GOT is Elf_Addr[], not Elf_Word[]... 2002-09-12 18:36:43 +00:00
mycroft
6f0bda739f This ld script is now unnecessary. 2002-09-12 18:33:39 +00:00
mycroft
1165ce6f38 Clean up a little. 2002-09-12 18:28:53 +00:00
mycroft
2346aaad04 Move GOT relocation code from _rtld_setup_pltgot() to
_rtld_relocate_nonplt_objects().  Add GOT self-relocation in
_rtld_relocate_nonplt_self().
MIPS ld.elf_so can now relocate itself.
2002-09-12 18:21:18 +00:00
mycroft
2b2534febf Add a `relocbase' argument to _rtld() and _rtld_init(), which is passed in
from the glue code in _rtld_start().  This is used to set objself.relocbase,
rather than assuming that it's the same as objself.mapbase (or 0 on MIPS).
Now -- with a bug fix to the kernel -- ld.elf_so can be linked at any VMA.
2002-09-12 17:45:41 +00:00
mycroft
d04429c6a7 Figure out the relocation offset and pass it to _rtld(). 2002-09-12 17:43:30 +00:00
mycroft
ebf50cdfbc Update comments. 2002-09-12 17:18:37 +00:00
mycroft
ac81e3266b Snapshot of work to make MIPS ld.elf_so relocatable. 2002-09-12 17:08:32 +00:00
mycroft
5ee0e5e1c4 Pass the calculated relocation offset down to _rtld(). 2002-09-12 17:07:25 +00:00
bjh21
3cc5ae01bc Correct somewhere where, in rev 1.3, two new sentences had been dropped
into the middle of an existing sentence, and put them after it instead.
2002-09-11 23:11:41 +00:00
mycroft
1da1ca49f2 Do the _rtld_relocate_nonplt_self() thing here, and nuke the ld script. 2002-09-11 22:28:32 +00:00
mycroft
fb69b8bec4 Implement _rtld_relocate_nonplt_self() here. 2002-09-11 21:14:08 +00:00
mycroft
a57ae642a3 We don't use _GLOBAL_OFFSET_TABLE_ any more, so don't .global it. 2002-09-11 20:56:09 +00:00
mycroft
fa0b5c37b2 This is a gratuitous null commit to force rtld.o to be rebuilt. 2002-09-11 20:48:21 +00:00
mycroft
f1725abea5 Add a _rtld_relocate_nonplt_self() here too. 2002-09-11 20:45:52 +00:00
mycroft
403e42f619 Do self-relocation similar to sparc. 2002-09-11 19:46:40 +00:00
mycroft
e46eb805f1 This ld script is no longer necessary. 2002-09-11 19:46:04 +00:00
mycroft
aa1330ce71 Do the _rtld_relocate_nonplt_self() thing for SPARC. 2002-09-11 19:11:05 +00:00
mycroft
82148aec74 The ld script is no longer necessary. 2002-09-11 18:20:47 +00:00
mycroft
d603bed369 Implement _rtld_relocate_nonplt_self() on Alpha. 2002-09-11 18:18:37 +00:00
mycroft
735f9f38c0 Split the `self' case out of _rtld_relocate_nonplt_objects, into a new function
_rtld_relocate_nonplt_self(), which is called from _rtld_start.
Now we're completely relocated before main() is called.
We also no longer need _GOT_END_, so junk the ld script.

This code assumes that ld.elf_so only contains RELATIVE relocs, but that's
supposed to be the case for -Bsymbolic anyway.
2002-09-11 17:23:23 +00:00
junyoung
b240241362 Add $NetBSD$. 2002-09-11 14:19:30 +00:00
mycroft
db439ed878 Only one linker script is needed. 2002-09-10 14:19:18 +00:00
mycroft
289d4ac1a5 Remove unneeded cruft from _rtld_start. 2002-09-10 02:52:33 +00:00
mycroft
d048e19122 Shorten the startup sequence by a few instructions. 2002-09-10 02:24:51 +00:00
mycroft
9f0e145106 Nuke RTLD_RELOCATE_SELF on ARM. 2002-09-09 19:28:36 +00:00
mycroft
d22977bb61 Indent branch delay instructions. 2002-09-09 19:01:52 +00:00
mycroft
c127ff08fb Nuke RTLD_RELOCATE_SELF for SPARC. 2002-09-09 18:10:20 +00:00
mycroft
89520a5f6e Sync with current binutils. 2002-09-09 14:41:25 +00:00
mycroft
ae0c8dfbc2 Get rid of RTLD_RELOCATE_SELF on i386.
* Add a ld.so.script that exports _GOT_END_.
* Prebind the GOT in _rtld_start.
* Skip over GOT relocs in _rtld_relocate_nonplt_objects().
This makes debugging work better at least.
2002-09-09 14:08:07 +00:00
wiz
221d594f18 Mention that -DDEBUG compilation is needed to get LD_DEBUG support.
Noted by Julio Merino in misc/18231.
2002-09-08 23:44:09 +00:00
thorpej
6a37882ec7 Fix a serious performance problem for large programs on the Alpha.
Large programs need multiple GOTs.  The lazy binding stub in the PLT
can be reached from any of these GOTs, but the dynamic linker only
has enough information to fix up the first GOT entry.  Thus, calls
through the other GOTs went through the time-consuming lazy binding
process on every call.

This fix rewrites the PLT entries themselves to bypass the lazy binding
for those GOT entries that the dynamic linker can't fixup.

Fix from FreeBSD.

Note that now that we patch up the PLT, we need to put back the "imb"
that was removed from the binder exit path.
2002-09-08 02:48:28 +00:00
mycroft
492895a9f9 Expand the comment about the R_TYPE(RELATIVE) special-case, as it's not quite
obvious from the code.  Also, just do it all the time, as an optimization.
2002-09-06 15:51:23 +00:00
mycroft
3eee01c5b9 Make the reloc tables const. 2002-09-06 15:32:56 +00:00
mycroft
6f0fac5efa Pass down an additional flag to _rtld_relocate_nonplt_objects() which
indicates whether we're relocating ld.elf_so itself.  Use this in some places
rather than hackish tests on `dodebug'.  (The Alpha and HPPA `dodebug' tests
were actually noops, because RTLD_RELOCATE_SELF is not set, and therefore
dodebug is always true.)
2002-09-06 15:17:53 +00:00
junyoung
3ffe941c3a Remove typedef which was never used. Meaningless comment as well. 2002-09-06 13:27:48 +00:00
mycroft
0df8d18100 Introduce a new flag, `isdynamic', which is used to remember whether the
executable was of type ET_DYN.  Use this instead of `mainprog' to determine
whether we need to do base-relative fixups of the PLT.  (This allows loading
non-relocatable objects, should we desire to do that at some point...)
2002-09-06 13:20:29 +00:00
mycroft
69b9a24021 More const poisoning. Now the entire _rtld_bind() path useds a const Obj_Entry. 2002-09-06 12:00:40 +00:00
mycroft
b97e4047b7 Re-poison a lot of consts, now that the mark shite is gone. 2002-09-06 03:12:04 +00:00
mycroft
a04012e731 Split _rtld_relocate_plt_object() into two MD functions:
* _rtld_relocate_plt_lazy() fixes up all the relocs pointing to the PLT.  (On
  most platforms it just does a simple base-relative fixup; on SPARC it does
  nothing.)
* _rtld_relocate_plt_object() does immediate binding for a PLT entry.
The basic gist is that this saves a bit of time on SPARC (where the iteration
through the pltrela table was gratuitous), and a little less time on all other
platforms.  A whole lot of #ifdef'ed crap is moved out of reloc.c, too.

NOT tested on: hppa sh x86_64
2002-09-06 03:05:35 +00:00
mycroft
5f016a11ef Repair a slight biff I made earlier -- do not exit the loop in
_rtld_relocate_nonplt_objects() early.
2002-09-06 02:01:39 +00:00
mycroft
c59ffb0cc4 Remove all of the mark' code. This is responsible for the undefined PLT
symbol' errors, probably because the increment gets interrupted occasionally by
a signal.  In general, _rtld_bind() should not modify ANY internal state.
2002-09-05 21:57:09 +00:00
mycroft
ac191986f3 Partially fix up some debug printf()s that don't need to use defobj. 2002-09-05 21:31:30 +00:00
mycroft
bdc2ac1520 A few things:
* Pass a symbol number to _rtld_find_symdef(), not a r_info.
* Don't try to do a symbol lookup when we find an unsupported relocation;
  instead get the symbol name from the referencing object's strtab.
* Add preliminary support for `-z combreloc'-style startup optimization on
  i386, `#ifdef COMBRELOC'.
2002-09-05 21:21:06 +00:00
mycroft
1fa950d044 Fix one indentation error. 2002-09-05 20:12:43 +00:00
mycroft
74444a2ddb Rename _rtld_relocate_nonplt_object() to _rtld_relocate_nonplt_objects(),
and push the outer loop into it.  This actually shaves a couple % off startup
time at least on PCs.
2002-09-05 20:08:14 +00:00
mycroft
00c3ad1f56 Split _rtld_relocate_nonplt_object() into separate MD files. 2002-09-05 18:25:45 +00:00
mycroft
b4a8cd2dbf Split MIPS relocation goo into mips_reloc.c. 2002-09-05 17:58:02 +00:00
mycroft
ae16986458 Simplify a couple of tests to !__mips__. 2002-09-05 17:06:11 +00:00
mycroft
9e3442dc47 Combine the code that skips COPY relocs on most platforms (other than MIPS).
Remove the code that skips JMP_SLOT relocs (thus making ld.elf_so bomb if it
hits one in the non-PLT relocation table).
2002-09-05 17:01:13 +00:00
mycroft
cf2d41da85 If REL(A)SZ extends into .rel(a).plt, trim rel(a)lim. This is actually due to
what is arguably a bug in BFD on some platforms (at least PPC and SPARC), but
I can't fix old binaries.
2002-09-05 16:58:16 +00:00
junyoung
515622e6db Remove unused arguments of _rtld_find_symdef(). 2002-09-05 16:33:57 +00:00
mycroft
1ea7e8253b Remove support for PowerPC static relocations, which are not present in shared
objects, and in any case are implemented WRONG.  (They're symbol-relative, not
base-relative.)
2002-09-05 15:47:52 +00:00
mycroft
f4cbd3d6e2 Remove unused prototypes (including one for a non-existant function!). 2002-09-05 15:45:54 +00:00
mycroft
2635aa544a Make _rtld_setup_pltgot() a consistent interface on all platforms. 2002-09-05 15:38:22 +00:00
mycroft
1e06edb63b There is no need to do an imb after each call to the binder, because we only
patch the GOT, not the PLT.  However, do an imb when setting up the PLT thunk,
just in case.
2002-09-04 19:13:00 +00:00
mycroft
1b6aaa02a2 Turn off DEBUG by default, and compile with -O3. (Tested on Alpha, ARM,
x86 and PowerPC.)
2002-08-31 18:18:14 +00:00
lukem
3b473ec283 xerrx() needs to output a trailing newline as well 2002-08-27 10:37:33 +00:00
christos
23c8380404 save 4 system calls by using AT_{R,E}{U,G}ID. 2002-08-26 21:09:55 +00:00
lukem
f794aa60bb Use ${NETBSDSRCDIR}/some/path instead of ${.CURDIR}/../../some/path 2002-08-19 13:54:34 +00:00
thorpej
9c104401d1 Build for "armeb". 2002-08-10 01:59:33 +00:00
soren
642c31b4a3 Remove extraneous \n's in {err,warn}{,x}. 2002-08-09 10:01:53 +00:00
abs
c2fcad8607 If /etc/ld.so.conf contains an invalid sysctl name any dynamically
executable that uses the library on that line has the rather cryptic
"sysctl" printed when it starts executing.

Switch to (_PATH_LD_HINTS": unknown sysctl for %s", name);

Discovered after someone copied /etc from an i386 to a sparc64 box.
2002-07-18 14:46:11 +00:00
fredette
e4526bd9fa Add support for dynamic linking on HP PA-RISC. 2002-07-10 15:12:33 +00:00
lukem
06de426449 SIMPLEQ rototill:
- implement SIMPLEQ_REMOVE(head, elm, type, field).  whilst it's O(n),
  this mirrors the functionality of SLIST_REMOVE() (the other
  singly-linked list type) and FreeBSD's STAILQ_REMOVE()
- remove the unnecessary elm arg from SIMPLEQ_REMOVE_HEAD().
  this mirrors the functionality of SLIST_REMOVE_HEAD() (the other
  singly-linked list type) and FreeBSD's STAILQ_REMOVE_HEAD()
- remove notes about SIMPLEQ not supporting arbitrary element removal
- use SIMPLEQ_FOREACH() instead of home-grown for loops
- use SIMPLEQ_EMPTY() appropriately
- use SIMPLEQ_*() instead of accessing sqh_first,sqh_last,sqe_next directly
- reorder manual page; be consistent about how the types are listed
- other minor cleanups
2002-06-01 23:50:52 +00:00
wiz
bf840df2cd __STDC__ is always defined on NetBSD. 2002-05-26 00:02:06 +00:00
thorpej
0eaaac19bf Add .register directives to appease newer gas. 2002-05-06 18:53:30 +00:00
tv
7cfc131b50 Don't bomb if the ${DPADD} files are missing -- we want at least one of
them, where the other may not exist, and the linker will fail for us if
both don't exist.
2002-03-01 20:15:16 +00:00
matt
0ce5ca145f Change to use a register prefix. 2002-02-24 01:06:18 +00:00
ross
dc5571b22e Generate <>& symbolically. I'm avoiding .../dist/... directories for now. 2002-02-08 01:21:55 +00:00
thorpej
cb2e377d4c Whitespace cleanup. 2002-02-04 18:18:51 +00:00
thorpej
2685463c0e Use ${MACHINE_CPU} to assign ARCHSUBDIR. 2002-02-04 00:24:14 +00:00
thorpej
67b1884571 Add support for dynamic linking on the SuperH. From Marcus Comstedt,
with some bug fixes (namely, don't forget to consider the addend when
processing relocations) from me.
2002-02-03 23:34:42 +00:00
skrll
04206c0a21 Install the man page on a.out systems as well so that the man set is the
same for all.
2002-01-23 15:10:24 +00:00
eeh
0edae4622b Do not attempt to relocate any pltrela entries that are not JMP_SLOT on sparc64. 2002-01-06 03:54:42 +00:00
tv
f8e3b0e1e5 Revert rev. 1.30 (partly). If MKPICINSTALL=no in mk.conf, libc_pic.a will
NOT be installed by the time we build here.

However, allow the link to look in both src/lib/libc and $DESTDIR/usr/lib.
2002-01-04 19:08:04 +00:00
lukem
dc75a614e2 - Allow RTLD_DEFAULT_LIBRARY_PATH to be overridden.
- If ${SHLIBDIR} != ${LIBDIR}, then set RTLD_DEFAULT_LIBRARY_PATH to
  ${SHLIBDIR}:${LIBDIR}
2001-12-28 05:44:22 +00:00
lukem
a5d8d0231c if SHLINKDIR != /usr/libexec, install compat symlink 2001-12-28 05:30:24 +00:00
lukem
efcc9a4c9d * Add user-controlled mk.conf variables
- SHLIBDIR	Location to install shared libraries if ${USE_SHLIBDIR}
			is "yes".  Defaults to "/usr/lib".

	- USE_SHLIBDIR	If "yes", install shared libraries in ${SHLIBDIR}
			instead of ${LIBDIR}.  Defaults to "no".
			Sets ${_LIBSODIR} to the appropriate value.
			This may be set by individual Makefiles as well.

	- SHLINKDIR	Location of shared linker.  Defaults to "/usr/libexec".
			If != "/usr/libexec", change the dynamic-linker
			encoded in shared programs

* Set USE_SHLIBDIR for libraries used by /bin and /sbin:
	libc libcrypt libcrypto libedit libipsec libkvm libm libmi387
	libtermcap libutil libz

* If ${_LIBSODIR} != ${LIBDIR}, add symlinks from ${LIBDIR}/${LIB}.so*
  to ${_LIBSODIR}/${LIB}.so* for compatibility.

* Always install /sbin/init statically (for now)


The net effect of these changes depends on how the variables are set:

  1.)	If nothing is set or changed, there is no change from the
	current behaviour:
		- Static /bin, /sbin, and bits of /usr/*
		- Dynamic rest
		- Shared linker is /usr/libexec/ld*so

  2.)	If the following make variables are set:
		LDSTATIC=
		SHLINKDIR=/lib
		SHLIBDIR=/lib
	Then the behaviour becomes:
		- Dynamic tools
		- .so libraries used by /bin and /sbin are installed to /lib,
		  with symlinks from /usr/lib/lib*so to -> /lib/lib*so
		  where appropriate
		- Shared linker is /lib/ld*so

  3.)	As per 2.), but add the following variable:
		USE_SHLIBDIR=yes
	This forces all .so's to be instaleld in /lib (with compat
	symlinks), not just those tagged by their Makefiles to be.
	Again, compat symlinks are installed
2001-12-28 01:32:37 +00:00
thorpej
b3827960df Grumble. Put compiler options back into CPPFLAGS for now, since
they're needed to build .S files with the correct PIC options.

XXX Really needs cleanup in <bsd.*.mk> to do this properly.
2001-12-20 19:20:02 +00:00
thorpej
8438068b4a Small whitespace fix. 2001-12-20 06:54:25 +00:00
thorpej
7b26e004dc Update README. Still not complete. 2001-12-20 06:49:03 +00:00
thorpej
04eaa333b6 Upon further investigation, do NOT include an addend in RELATIVE
relations (the addend should always be zero, but this is safer).
2001-12-20 02:32:49 +00:00
thorpej
fe822e84da Include the addend in GLOB_DAT relocations (!!). 2001-12-20 02:23:24 +00:00
thorpej
240ebfc364 * Move The Alpha R(RELATIVE) handling into an Alpha-specific code block,
thus isolating the "iffy hueristic" from the rest of the relocation code.
* In the "iffy hueristic", use _GOT_END_, not _DYNAMIC.
* Include the addend in Alpha R(RELATIVE) relocations.
2001-12-16 08:23:25 +00:00
thorpej
7dcc71da1d Don't put compiler options into CPPFLAGS. 2001-12-14 22:21:45 +00:00
thorpej
151a90b5ce ...and the other other missing notice. 2001-12-14 22:11:47 +00:00
thorpej
d63d6c6cea Add other missing copyright notice. 2001-12-14 22:07:23 +00:00
fvdl
02f3677f38 Add missing copyright notice. 2001-12-14 21:33:59 +00:00
thorpej
6d9f5579ab Garbage-collect the OLD_GOT stuff. 2001-12-14 21:25:22 +00:00
thorpej
c7e9af3ef0 binutils-current ld emits DT_TEXTREL into _DYNAMIC on arm-elf. Handle
this.
2001-12-14 21:21:27 +00:00
thorpej
6e94624a62 Add code to peek into the PLT and determine which PLT entry format
is being used.
2001-12-14 00:53:06 +00:00
thorpej
67925dcb0d Supply two lazy binding routines for Alpha: one that works with the
old PLT format, and one that works with the new.

XXX We currently always use _rtld_bind_start_old() in
_rtld_setup_alpha_pltgot().  We need to add code to peek
into one of the PLT entries to see which format it's in
and pick the correct binding routine.
2001-12-13 22:34:51 +00:00
rafal
b8f0be7074 Check in workaround for BFD ABI change on MIPS: the new MIPS BFD generates
relocs for local symbols as section-relative REL32 relocs with values based
at 0, whereas previously BFD generated those relocs with values based at the
start address of the section.

This code adjusts all STT_SECTION REL32 relocs which have values less than
the start of the section by adding in the base address of the section.  This
may limit section sizes to 2GB, but that shouldn't be a problem for now.

XXX: Needs to be followed-up with binutils list to get closure on which
interpretation is correct (the new ABI or the old one), I just haven't
yet had the time to chase that.
2001-12-13 21:41:58 +00:00
thorpej
cbadc6e3d3 Use numeric labels. 2001-12-13 21:34:04 +00:00
thorpej
23abd45cd4 Add RCS ID. 2001-12-13 20:31:31 +00:00
thorpej
bbb7ad0534 * Add a linker script which provides a _GOT_END_ symbol that we can
use to find the end of the GOT, rather than relying on _DYNAMIC
  to immediately follow the GOT.  (A change in current binutils
  moved _DYNAMIC, and thus would have broken our Alpha ld.elf_so).
* Add #ifdef'd out code to deal with the new PLT format.
2001-12-13 20:30:48 +00:00
rafal
24ed46ea21 Fix bug found by Izumi Tsutsui -- if _rtld_find_symdef returned NULL, the
runtime linker would crash.  Restore behavior similar to version 1.3, where
the runtime linker continues on, ignoring the symbol.
2001-11-24 18:07:04 +00:00
skrll
aabfabf3e7 Allow both space and colon as a separator in LD_PRELOAD. Document this and
the fact that space may be retired in the future.

Closes misc/11961

Reviewed by christos
2001-11-02 15:28:36 +00:00
wiz
27bebba05c Sort SEE ALSO, drop some unnecessary .Pp's, whitespace and misc fixes. 2001-11-01 01:10:59 +00:00
skrll
0a9eeb6303 Add a man page for ld.elf_so. 2001-10-31 18:26:23 +00:00
rafal
2576af45bb Fix how underfined weak symbols are treated -- before, ld.so would do nothing
with them, rather than defaulting them to zero.  This caused breakage with
the drawf EH stuff and init/fini code when they weren't used by the caller
(and hence the appropriate handlers were left undefined).  Also fix an un-
initialized variable in symbol.c that only MIPS MD code tripped over.
2001-10-14 23:13:21 +00:00
mycroft
cf4aca11b5 In the `I can't believe it's been broken all this time' department:
_rtld_bind_start must save and restore the condition codes.  Varargs functions
(like, say, printf()) depend on the state of cr1 to determine whether they need
to store floating point registers in the save area.  Without this, the first
call to any particular varargs function will fail if floating point values were
passed.
2001-09-26 04:06:43 +00:00
mycroft
7ff3aa31e8 Reorganize PowerPC cold a little. The return value from _rtld_bind_pltgot()
was ambiguous in the case of a weak symbol that was not defined.  This caused
RTLD_NOW to fail badly with shared libraries linked against the new crtbegin.o.
2001-09-10 06:09:41 +00:00
eeh
192ea0d41e Correct some comments. 2001-08-14 22:17:48 +00:00
eeh
c9550f39ed Workaround for binutils 2.11 behavior. 2001-08-14 20:17:25 +00:00
eeh
2e3cc27a62 Get rid of some debug code that should no longer be needed. 2001-08-14 20:16:38 +00:00