Commit Graph

36 Commits

Author SHA1 Message Date
Rich Felker fd7015d0c2 fix broken copy relocations from dynamic linker cleanup
this issue affected programs which use global variables exported by
non-libc libraries.
2012-01-23 18:32:40 -05:00
Rich Felker e12fe65c92 dynamic linker support for PIE binaries (position-independent main program)
even with this change, PIE will not work yet due to deficiencies in
the crt1.o startup code.
2012-01-23 02:02:59 -05:00
Rich Felker c82f4a32ec cleanup dynamic linker, removing some code duplication 2012-01-23 00:57:38 -05:00
Rich Felker 0b6dc09744 fix dynamic linker not to depend on DYNAMIC ptr in 0th entry of GOT
this fixes an issue using gold instead of gnu ld for linking. it also
should eliminate the need of the startup code to even load/pass the
got address to the dynamic linker.

based on patch submitted by sh4rm4 with minor cosmetic changes.

further cleanup will follow.
2012-01-20 11:14:27 -05:00
Rich Felker 2adf2fb372 fix char signedness bug in dynlinker hash function
this only affects non-ascii symbol names, which are probably not in
use anyway..
2012-01-17 00:34:58 -05:00
Rich Felker 4f4bf0ad2e disable dynamic linking/loading code in static libc builds, for now
it does not work, but some configure scripts will falsely detect
support then generate programs that crash when they call dlopen.
2011-09-18 16:42:06 -04:00
Rich Felker cf8506ad94 ldso: move the suid/secure check code closer to env/auxv processing
this does not change behavior, but the idea is to avoid letting other
code build up between these two points, whereby the environment
variables might get used before security it checked.
2011-08-16 08:50:03 -04:00
Rich Felker a045883365 honor AT_SECURE aux vector flag 2011-08-16 07:46:42 -04:00
Rich Felker 623753ad64 RTLD_NEXT support
the asm wrapper is needed to get the return address without
compiler-specific extensions.
2011-08-16 00:42:13 -04:00
Rich Felker 2719cc8628 LD_PRELOAD support 2011-08-16 00:24:36 -04:00
Rich Felker e01ac67599 when resolving symbols with only weak defs, use first def, not last def 2011-07-25 09:22:05 -04:00
Rich Felker 427173b932 fix resolution of weak symbols (hopefully right now) and vdso 2011-07-24 02:19:47 -04:00
Rich Felker 6ab444d97a load vdso, if present, into the dso list 2011-07-24 00:54:55 -04:00
Rich Felker a53de812d2 simplify dynamic linker startup
instead of creating temp dso objects on the stack and moving them to
the heap if dlopen/dlsym are used, use static objects to begin with,
and just donate them to malloc if we no longer need them.
2011-07-24 00:26:12 -04:00
Rich Felker 2fdea17c3d fix dlopen UB due to longjmp/volatile rules violation 2011-07-01 22:40:00 -04:00
Rich Felker 191ebcac31 simple rpath support (no token expansion yet) for dynamic linker 2011-06-30 23:02:27 -04:00
Rich Felker 9f17413c75 textrel support, cheap and ugly 2011-06-29 00:29:08 -04:00
Rich Felker 6717e62ac0 reclaim the memory wasted by dynamic linking for use by malloc 2011-06-28 19:40:14 -04:00
Rich Felker bf30100ad7 use load address from elf header if possible
this is mostly useless for shared libs (though it could help for
prelink-like purposes); the intended use case is for adding support
for calling the dynamic linker directly to run a program, as in:
./libc.so ./a.out foo

this usage is not yet supported.
2011-06-28 14:20:41 -04:00
Rich Felker c7debe13ee make dynamic linker relocate the main program image last, after all libs
prior to this change, copy relocations for initialized pointer
variables would not reflect the relocated contents of the pointer.
2011-06-28 14:13:51 -04:00
Rich Felker 9e17b71fa6 fix stale pointer issue in dynamic linker with dlopen 2011-06-26 22:39:34 -04:00
Rich Felker 06933cc724 don't leave the lock held on dlopen failure.. 2011-06-26 22:09:32 -04:00
Rich Felker 97507bde47 add RTLD_DEFAULT support 2011-06-26 21:50:01 -04:00
Rich Felker 0e4dae3d77 in dlopen: don't use null pointer
deps can be null if a library has no dependencies (such as libc itself)
2011-06-26 21:36:44 -04:00
Rich Felker 92ab5d8d15 fix resolving symbols in objects loaded in RTLD_LOCAL mode
basically we temporarily make the library and all its dependencies
part of the global namespace but only for the duration of performing
relocations, then return them to their former state.
2011-06-26 21:21:04 -04:00
Rich Felker 59ab43f5f8 experimental dlopen/dlsym and dynlink changes needed to support them 2011-06-26 19:23:28 -04:00
Rich Felker 6b3d5e508f error handling in dynamic linking
some of the code is not yet used, and is in preparation for dlopen
which needs to be able to handle failure loading libraries without
terminating the program.
2011-06-26 17:39:17 -04:00
Rich Felker 32de61e81a fix some symbol resolution issues in dynamic linker
1. search was wrongly beginning with lib itself rather than dso head
2. inconsistent resolution of function pointers for functions in plt
2011-06-25 22:36:21 -04:00
Rich Felker 49388f3b7b handle library paths better (ignore empty path components, etc.) 2011-06-25 17:49:16 -04:00
Rich Felker 59633c736d fix possible (questionable) strict aliasing violations and ptr arith 2011-06-25 12:26:08 -04:00
Rich Felker 568b8075a4 proper path searching for dynamic linker
first, use $LD_LIBRARY_PATH unless suid. if that fails, read path from
/etc/ld-musl-$ARCH.path and fallback to a builtin default.
2011-06-25 01:56:34 -04:00
Rich Felker e8dbf00a78 discard dso descriptors after performing relocations
eventually (once dlopen exists) this behavior will be conditional on
dlopen/dlsym not being reachable.
2011-06-25 00:47:28 -04:00
Rich Felker 368ba4a0a9 keep track of which dsos have been relocated 2011-06-25 00:18:19 -04:00
Rich Felker b7f6e0c6f8 prepare support for LD_LIBRARY_PATH (checking suid/sgid safety)
the use of this test will be much stricter than glibc and other
typical implementations; the environment will not be honored
whatsoever unless the program is confirmed non-suid/sgid by the aux
vector the kernel passed in. no fallback to slow syscall-based
checking is used if the kernel fails to provide the information; we
simply assume the worst (suid) in this case and refuse to honor
environment.
2011-06-23 22:04:06 -04:00
Rich Felker 596d60c565 dynamic linker 64bit fix: hash table entries are always 32bit 2011-06-18 22:52:01 -04:00
Rich Felker 51e2d83102 experimental dynamic linker!
some notes:
- library search path is hard coded
- x86_64 code is untested and may not work
- dlopen/dlsym is not yet implemented
- relocations in read-only memory won't work
2011-06-18 19:48:42 -04:00