summaryrefslogtreecommitdiff
path: root/src/ldso
AgeCommit message (Collapse)AuthorLines
2012-10-04TLS (GNU/C11 thread-local storage) support for static-linked programsRich Felker-0/+10
the design for TLS in dynamic-linked programs is mostly complete too, but I have not yet implemented it. cost is nonzero but still low for programs which do not use TLS and/or do not use threads (a few hundred bytes of new code, plus dependency on memcpy). i believe it can be made smaller at some point by merging __init_tls and __init_security into __libc_start_main and avoiding duplicate auxv-parsing code. at the same time, I've also slightly changed the logic pthread_create uses to allocate guard pages to ensure that guard pages are not counted towards commit charge.
2012-09-29more close-on-exec fixes, mostly using new "e" flag to fopenRich Felker-1/+1
2012-09-29fix some more O_CLOEXEC/SOCK_CLOEXEC issuesRich Felker-2/+2
2012-09-29microblaze portRich Felker-0/+32
based on initial work by rdp, with heavy modifications. some features including threads are untested because qemu app-level emulation seems to be broken and I do not have a proper system image for testing.
2012-09-06use restrict everywhere it's required by c99 and/or posix 2008Rich Felker-4/+4
to deal with the fact that the public headers may be used with pre-c99 compilers, __restrict is used in place of restrict, and defined appropriately for any supported compiler. we also avoid the form [restrict] since older versions of gcc rejected it due to a bug in the original c99 standard, and instead use the form *restrict.
2012-08-27fix bug caused by main app & libc having map set; cannot free themRich Felker-1/+1
2012-08-26dladdr support for dynamic linker (nonstandard extension)Rich Felker-0/+95
based on patches submitted by boris brezillon. this commit also fixes the issue whereby the main application and libc don't have the address ranges of their mappings stored, which was theoretically a problem for RTLD_NEXT support in dlsym; it didn't actually matter because libc never calls dlsym, and it seemed to be doing the right thing (by chance) for symbols in the main program as well.
2012-08-25fix bug in gnu hash lookup on dlsym(handle, name) lookupsRich Felker-1/+1
wrong hash was being passed; just a copy/paste error. did not affect lookups in the global namespace; this is probably why it was not caught in testing.
2012-08-25clean up search_vec usage for vdsoRich Felker-2/+2
2012-08-25use new search_vec function to find vdso in dynamic linkerRich Felker-4/+2
2012-08-25ensure canary is setup if stack-prot libs are dlopen'd into non-ssp appRich Felker-1/+4
previously, this usage could lead to a crash if the thread pointer was still uninitialized, and otherwise would just cause the canary to be zero (less secure).
2012-08-25add gnu hash support in the dynamic linkerRich Felker-12/+85
based on the patches contributed by boris brezillon.
2012-08-18make dynamic linker report all failures before exitingRich Felker-2/+6
before, only the first library that failed to load or symbol that failed to resolve was reported, and then the dynamic linker immediately exited. when attempting to fix a library compatibility issue, this is about the worst possible behavior. now we print all errors as they occur and exit at the very end if errors were encountered.
2012-08-17fix bug computing argc when invoking ld-musl-mips.so.1 progname ...Rich Felker-3/+3
2012-08-07fix bug dlsym bug that slipped in during dynamic linker cleanupRich Felker-1/+1
2012-08-05dlsym RTLD_NEXT support for mipsRich Felker-0/+15
untested
2012-08-05more changes that were lost when committing mips dynamic linkerRich Felker-0/+4
2012-08-05fix change lost in the process of integrating mips dynamic linkerRich Felker-2/+2
2012-08-05mips dynamic linker supportRich Felker-0/+49
not heavily tested, but the basics are working. the basic concept is that the dynamic linker entry point code invokes a pure-PIC (no global accesses) C function in reloc.h to perform the early GOT relocations needed to make the dynamic linker itself functional, then invokes __dynlink like on other archs. since mips uses some ugly arch-specific hacks to optimize relocating the GOT (rather than just using the normal DT_REL[A] tables like on other archs), the dynamic linker has been modified slightly to support calling arch-specific relocation code in reloc.h. most of the actual mips-specific behavior was developed by reading the output of readelf on libc.so and simple executable files. i could not find good reference information on which relocation types need to be supported or their semantics, so it's possible that some legitimate usage cases will not work yet.
2012-08-05more cleanup of dynamic linker internalsRich Felker-8/+9
2012-08-05more dynamic linker internals cleanupRich Felker-6/+6
changing the string printed for the dso name is not a regression; the old code was simply using the wrong dso name (head rather than the dso currently being relocated). this will be fixed in a later commit.
2012-08-05dynamic linker internals cleanupRich Felker-5/+7
2012-07-13make dynamic linker tell the debugger its own pathnameRich Felker-0/+5
use the main program's PT_INTERP header if possible, since this is sure to be a correct (and hopefully absolute) pathname.
2012-07-11make dynamic linker depend on -DSHARED not -fPICRich Felker-1/+1
if libc.a is compiled PIC for use in static PIE code, this should not cause the dynamic linker (which still does not support static-linked main program) to be built into libc.a.
2012-07-11fix lots of breakage on dlopen, mostly with explicit pathnamesRich Felker-14/+21
most importantly, the name for such libs was being set from an uninitialized buffer. also, shortname always had an initial '/' character, making it useless for looking up already-loaded libraries by name, and thus causing repeated searches through the library path. major changes now: - shortname is the base name for library lookups with no explicit pathname. it's initially clear for libraries loaded with an explicit pathname (and for the main program), but will be set if the same library (detected via inodes match) is later found by a search. - exact name match is never used to identify libraries loaded with an explicit pathname. in this case, there's no explicit search, so we can just stat the file and check for inode match.
2012-07-07fix dlsym RTLD_NEXT supportRich Felker-1/+3
previously this was being handled the same as a library-specific, dependency-order lookup on the next library in the global chain, which is likely to be utterly meaningless. instead the lookup needs to be in the global namespace, but omitting the initial portion of the global library chain up through the calling library.
2012-06-09fix char signedness bug (arm-specific) in dynamic linkerRich Felker-1/+1
2012-06-06treat failure of mprotect in map_library as a fatal load failureRich Felker-9/+9
the error will propagate up and be printed to the user at program start time; at runtime, dlopen will just fail and leave a message for dlerror. previously, if mprotect failed, subsequent attempts to perform relocations would crash the program. this was resulting in an increasing number of false bug reports on grsec systems where rwx permission is not possible in cases where users were wrongly attempting to use non-PIC code in shared libraries. supporting that usage is in theory possible, but the x86_64 toolchain does not even support textrels, and the cost of keeping around the necessary information to handle textrels without rwx permissions is disproportionate to the benefit (which is essentially just supporting broken library setups on grsec machines). also, i unified the error-out code in map_library now that there are 3 places from which munmap might have to be called.
2012-05-27add ldd and main program loading support to dynamic linkerRich Felker-21/+89
2012-05-27cleanup dynamic linker start code cruftRich Felker-13/+6
two actual issues: one is that __dynlink no longer wants/needs a GOT pointer argument, so the code to generate that argument can be removed. the other issue was that in the i386 code, argc/argv were being loaded into registers that would be call-clobbered, then copied to preserved registers, rather than just being loaded into the proper call-preserved registers to begin with. this cleanup is in preparation for adding new dynamic linker functionality (ability to explicitly invoke the dynamic linker to run a program).
2012-05-04fix error reporting for dlsym with global symbolsRich Felker-1/+2
2012-05-03overhaul SSP support to use a real canaryRich Felker-4/+3
pthread structure has been adjusted to match the glibc/GCC abi for where the canary is stored on i386 and x86_64. it will need variants for other archs to provide the added security of the canary's entropy, but even without that it still works as well as the old "minimal" ssp support. eventually such changes will be made anyway, since they are also needed for GCC/C11 thread-local storage support (not yet implemented). care is taken not to attempt initializing the thread pointer unless the program actually uses SSP (by reference to __stack_chk_fail).
2012-04-25gdb shared library debugging supportRich Felker-5/+32
provide the minimal level of dynamic linker-to-debugger glue needed to let gdb find loaded libraries and load their symbols.
2012-04-24first attempt at enabling stack protector supportRich Felker-0/+7
the code is written to pre-init the thread pointer in static linked programs that pull in __stack_chk_fail or dynamic-linked programs that lookup the symbol. no explicit canary is set; the canary will be whatever happens to be in the thread structure at the offset gcc hard-coded. this can be improved later.
2012-04-23make dlerror produce informative resultsRich Felker-4/+15
note that dlerror is specified to be non-thread-safe, so no locking is performed on the error flag or message aside from the rwlock already held by dlopen or dlsym. if 2 invocations of dlsym are generating errors at the same time, they could clobber each other's results, but the resulting string, albeit corrupt, will still be null-terminated. any use of dlerror in such a situation could not be expected to give meaningful results anyway.
2012-03-23make dlerror conform to posixRich Felker-6/+16
the error status is required to be sticky after failure of dlopen or dlsym until cleared by dlerror. applications and especially libraries should never rely on this since it is not thread-safe and subject to race conditions, but glib does anyway.
2012-02-07protect against cancellation in dlopenRich Felker-2/+5
i'm not sure that it's "correct" for dlopen to block cancellation when calling constructors for libraries it loads, but it sure seems like the right thing. in any case, dlopen itself needs cancellation blocked.
2012-02-07reduce some wasted space in dso structureRich Felker-3/+3
2012-02-06run ctors/dtors for shared objects loaded with dlopenRich Felker-0/+1
2012-02-06add support for init/finit (constructors and destructors)Rich Felker-0/+19
this is mainly in hopes of supporting c++ (not yet possible for other reasons) but will also help applications/libraries which use (and more often, abuse) the gcc __attribute__((__constructor__)) feature in "C" code. x86_64 and arm versions of the new startup asm are untested and may have minor problems.
2012-02-03include dummied-out dlopen and dlsym functions for static binariesRich Felker-1/+10
these don't work (or do anything at all) but at least make it possible to static link programs that insist on "having" dynamic loading support...as long as they don't actually need to use it. adding real support for dlopen/dlsym with static linking is going to be significantly more difficult...
2012-01-23fix broken copy relocations from dynamic linker cleanupRich Felker-1/+4
this issue affected programs which use global variables exported by non-libc libraries.
2012-01-23dynamic linker support for PIE binaries (position-independent main program)Rich Felker-3/+6
even with this change, PIE will not work yet due to deficiencies in the crt1.o startup code.
2012-01-23cleanup dynamic linker, removing some code duplicationRich Felker-80/+66
2012-01-20fix dynamic linker not to depend on DYNAMIC ptr in 0th entry of GOTRich Felker-3/+12
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-17fix char signedness bug in dynlinker hash functionRich Felker-1/+2
this only affects non-ascii symbol names, which are probably not in use anyway..
2011-10-01dlsym entry point for armRich Felker-0/+6
2011-10-01dynamic linker entry point for armRich Felker-0/+14
mildly tested, seems to work
2011-09-18disable dynamic linking/loading code in static libc builds, for nowRich Felker-0/+2
it does not work, but some configure scripts will falsely detect support then generate programs that crash when they call dlopen.
2011-09-03fix RTLD_NEXT on x86_64Rich Felker-1/+1
the return address was being truncated to 32 bits, preventing the dlsym code from determining which module contains the calling code.