Commit Graph

507 Commits

Author SHA1 Message Date
fvdl
c8ba6436ed If fstat info was passed, and from it it can be seen that the file size
is smaller than an ELF header, don't even bother to try to look at it.
Avoids coredumps with zero-sized files.
2003-02-06 12:38:17 +00:00
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