| Commit message (Expand) | Author | Age | Files | Lines |
| * | fix dynamic loader library mapping for nommu systems•••on linux/nommu, non-writable private mappings of files may actually
use memory shared with other processes or the fs cache. the old nommu
loader code (used when mmap with MAP_FIXED fails) simply wrote over
top of the original file mapping, possibly clobbering this shared
memory. no such breakage was observed in practice, but it should have
been possible.
the new code starts by mapping anonymous writable memory on archs that
might support nommu, then maps load segments over top of it, falling
back to read if MAP_FIXED fails. we use an anonymous map rather than a
writable file map to avoid reading more data from disk than needed.
since pages cannot be loaded lazily on fault, in case of large
data/bss, mapping the full file may read a lot of data that will
subsequently be thrown away when processing additional LOAD segments.
as a result, we cannot skip the first LOAD segment when operating in
this mode.
these changes affect only non-FDPIC nommu support.
| Rich Felker | 2015-11-11 | 1 | -4/+15 |
| * | explicitly assemble all arm asm sources as UAL•••these files are all accepted as legacy arm syntax when producing arm
code, but legacy syntax cannot be used for producing thumb2 with
access to the full ISA. even after switching to UAL, some asm source
files contain instructions which are not valid in thumb mode, so these
will need to be addressed separately.
| Rich Felker | 2015-11-10 | 1 | -0/+1 |
| * | fix missing bss handling in FDPIC ELF loader•••when a library being loaded has bss (i.e. data segment with
p_memsz>p_filesz), this region needs to be zeroed with a combination
of memset and/or mmap. the regular ELF loader always did this but the
FDPIC code path omitted it, leading to objects in bss having
uninitialized/junk contents.
| Rich Felker | 2015-10-28 | 1 | -0/+13 |
| * | fix dladdr treatment of function descriptors for fdpic•••when determining which module an address belongs to, all function
descriptor ranges must be checked first, in case the allocated memory
falls inside another module's memory range.
dladdr itself must also check addresses against function descriptors
before doing a best-match search against the symbol table. even when
doing the latter (e.g. for code addresses obtained from mcontext_t),
also check whether the best-match was a function, and if so, replace
the result with a function descriptor address. which is the nominal
"base address" of the function and which the caller needs if it
intends to subsequently call the matching function.
| Rich Felker | 2015-10-15 | 1 | -9/+22 |
| * | fix visibility mismatch in dynamic linker stage 2 function definition•••since commits 2907afb8dbd4c1d34825c3c9bd2b41564baca210 and
6fc30c2493fcfedec89e45088bea87766a1e3286, __dls2 is no longer called
via symbol lookup, but instead uses relative addressing that needs to
be resolved at link time. on some linker versions, and/or if
-Bsymbolic-functions is not used, the linker may leave behind a
dynamic relocation, which is not suitable for bootstrapping the
dynamic linker, if the reference to __dls2 is marked hidden but the
definition is not actually hidden. correcting the definition to use
hidden visibility fixes the problem.
the static-PIE entry point rcrt1 was likewise affected and is also
fixed by this patch.
| Rich Felker | 2015-10-15 | 1 | -0/+1 |
| * | fix dlsym RTLD_NEXT behavior for fdpic•••lookup the dso an address falls in based on the loadmap and not just a
base/length. fix the main app's fake loadmap used when loaded by a
non-fdpic-aware loader so that it does not cover the whole memory
space.
function descriptor addresses are also matched for future use by
dladdr, but reverse lookups of function descriptors via dladdr have
not been implemented yet. some revisions may be needed in the future
once reclaim_gaps supports fdpic, so that function descriptors
allocated in reclaimed heap space do not get detected as belonging to
the module whose gaps they were allocated in.
| Rich Felker | 2015-09-22 | 1 | -4/+28 |
| * | fix dlsym lookup of function symbols on fdpic•••previously these resolved to the code address rather than the address
of the function descriptor.
the conditions for accepting or rejecting symbols are quite
inconsistent between the different points in the dynamic linker code
where such decisions are made. this commit attempts to be at least as
correct as anything already there, but does not improve consistency.
it has been tested to correctly avoid symbols that are merely
references to functions defined in other modules, at least in simple
usage, but at some point all symbol lookup logic should be reviewed
and refactored/unified.
| Rich Felker | 2015-09-22 | 1 | -0/+6 |
| * | move calls to application init functions after crt1 entry point•••this change is needed to be compatible with fdpic, where some of the
main application's relocations may be performed as part of the crt1
entry point. if we call init functions before passing control, these
relocations will not yet have been performed, and the init code will
potentially make use of invalid pointers.
conceptually, no code provided by the application or third-party
libraries should run before the application entry point. the
difference is not observable to programs using the crt1 we provide,
but it could come into play if custom entry point code is used, so
it's better to be doing this right anyway.
| Rich Felker | 2015-09-22 | 1 | -1/+5 |
| * | fix breakage in non-fdpic dynamic linker init/fini processing•••a mistaken #ifdef instead of #if caused conversion of code addresses
to function descriptors to be performed even on non-fdpic.
| Rich Felker | 2015-09-22 | 1 | -1/+1 |
| * | fix resolving interp string address on fdpic ldd command | Rich Felker | 2015-09-22 | 1 | -2/+1 |
| * | add real fdpic loading of shared libraries•••previously, the normal ELF library loading code was used even for
fdpic, so only the kernel-loaded dynamic linker and main app could
benefit from separate placement of segments and shared text.
| Rich Felker | 2015-09-22 | 1 | -9/+54 |
| * | add general fdpic support in dynamic linker and arch support for sh•••at this point not all functionality is complete. the dynamic linker
itself, and main app if it is also loaded by the kernel, take
advantage of fdpic and do not need constant displacement between
segments, but additional libraries loaded by the dynamic linker follow
normal ELF semantics for mapping still. this fully works, but does not
admit shared text on nommu.
in terms of actual functional correctness, dlsym's results are
presently incorrect for function symbols, RTLD_NEXT fails to identify
the caller correctly, and dladdr fails almost entirely.
with the dynamic linker entry point working, support for static pie is
automatically included, but linking the main application as ET_DYN
(pie) probably does not make sense for fdpic anyway. ET_EXEC is
equally relocatable but more efficient at representing relocations.
| Rich Felker | 2015-09-22 | 2 | -11/+188 |
| * | factor symbol counting out of dladdr as its own function•••the fdpic code will need to count symbols, and it may be useful
elsewhere in the future too. counting is trivial as long as sysv hash
is present, but for gnu-hash-only libraries it's complex.
the behavior of the count is changed slightly: we now include symbols
that are not accessible by the gnu hash table in the count. this may
make dladdr slightly slower. if this is a problem, dladdr can subtract
out the part that should not be accessible. unlike in the old code,
subtracting this out is easy even in the fast path where sysv hash is
available too.
| Rich Felker | 2015-09-21 | 1 | -19/+20 |
| * | simplify dlstart code by using integer type for base address | Rich Felker | 2015-09-21 | 1 | -8/+7 |
| * | refactor some more dynamic linker load address computations•••these were just missed in the previous commits.
| Rich Felker | 2015-09-17 | 1 | -7/+7 |
| * | remove some useless casts in dynamic linker | Rich Felker | 2015-09-17 | 1 | -2/+2 |
| * | further refactoring of dynamic linker load address computations•••these are in do_relocs. the first one was omitted in commit
301335a80b85f12c018e4acf1a2c28615e119f8d because it slightly changes
code (using dso->base rather than cached local var base) and would
have prevented easy verification. the other was an oversight.
| Rich Felker | 2015-09-17 | 1 | -2/+2 |
| * | begin refactoring load address computations in dynamic linker•••for ordinary ELF with fixed segment displacements, load address
computation is simply adding the base load address. but for FDPIC,
each segment has its own load address, and virtual addresses need to
be adjusted according to the segment they fall in. abstracting this
computation is the first step to making the dynamic linker ready for
FDPIC.
for this first commit, a macro is used rather than a function in order
to facilitate correctness checking. I have verified that the generated
code does not change on my i386 build.
| Rich Felker | 2015-09-17 | 1 | -19/+22 |
| * | remove old dlstart stage-2 symbolic lookup code; add new generic•••this new generic version of the stage-2 function lookup should work
for any arch where static data is accessible via got-relative or
pc-relative addressing, using approximately the technique described in
the log message for commit 2907afb8dbd4c1d34825c3c9bd2b41564baca210.
since all the mips-like archs that need got slots fo access static
data have already transitioned to the new stage chaining scheme, the
old dynamic symbol lookup code is now removed.
aarch64, arm, and sh have not yet transitioned; with this commit, they
are now using the new generic code.
| Rich Felker | 2015-09-17 | 1 | -14/+8 |
| * | introduce new symbol-lookup-free rcrt1/dlstart stage chaining•••previously, the call into stage 2 was made by looking up the symbol
name "__dls2" (which was chosen short to be easy to look up) from the
dynamic symbol table. this was no problem for the dynamic linker,
since it always exports all its symbols. in the case of the static pie
entry point, however, the dynamic symbol table does not contain the
necessary symbol unless -rdynamic/-E was used when linking. this
linking requirement is a major obstacle both to practical use of
static-pie as a nommu binary format (since it greatly enlarges the
file) and to upstream toolchain support for static-pie (adding -E to
default linking specs is not reasonable).
this patch replaces the runtime symbolic lookup with a link-time
lookup via an inline asm fragment, which reloc.h is responsible for
providing. in this initial commit, the asm is provided only for i386,
and the old lookup code is left in place as a fallback for archs that
have not yet transitioned.
modifying crt_arch.h to pass the stage-2 function pointer as an
argument was considered as an alternative, but such an approach would
not be compatible with fdpic, where it's impossible to compute
function pointers without already having performed relocations. it was
also deemed desirable to keep crt_arch.h as simple/minimal as
possible.
in principle, archs with pc-relative or got-relative addressing of
static variables could instead load the stage-2 function pointer from
a static volatile object. that does not work for fdpic, and is not
safe against reordering on mips-like archs that use got slots even for
static functions, but it's a valid on i386 and many others, and could
provide a reasonable default implementation in the future.
| Rich Felker | 2015-09-17 | 1 | -0/+6 |
| * | dynlink.c: pass gnu-hash table pointer to gnu_lookup•••The callers need to check the value of the pointer anyway, so make
them pass the pointer to gnu_lookup instead of reloading it there.
Reorder gnu_lookup arguments so that always-used ones are listed
first. GCC can choose a calling convention with arguments in registers
(e.g. up to 3 arguments in eax, ecx, edx on x86), but cannot reorder
the arguments for static functions.
| Alexander Monakov | 2015-06-28 | 1 | -13/+11 |
| * | dynlink.c: slim down gnu_lookup•••Do not reference dso->syms and dso->strings until point of use.
Check 'h1 == (h2|1)', the simplest condition, before the others.
| Alexander Monakov | 2015-06-28 | 1 | -9/+5 |
| * | dynlink.c: use bloom filter in gnu hash lookup•••Introduce gnu_lookup_filtered and use it to speed up symbol lookups in
find_sym (do_dlsym is left as is, based on an expectation that
frequently dlsym queries will use a dlopen handle rather than
RTLD_NEXT or RTLD_DEFAULT, and will not need to look at more than one
DSO).
| Alexander Monakov | 2015-06-28 | 1 | -3/+22 |
| * | dynlink.c: use a faster expression in gnu_hash•••With -Os, GCC uses a multiply rather than a shift and addition for 'h*33'.
Use a more efficient expression explicitely.
| Alexander Monakov | 2015-06-27 | 1 | -1/+1 |
| * | fix local-dynamic model TLS on mips and powerpc•••the TLS ABI spec for mips, powerpc, and some other (presently
unsupported) RISC archs has the return value of __tls_get_addr offset
by +0x8000 and the result of DTPOFF relocations offset by -0x8000. I
had previously assumed this part of the ABI was actually just an
implementation detail, since the adjustments cancel out. however, when
the local dynamic model is used for accessing TLS that's known to be
in the same DSO, either of the following may happen:
1. the -0x8000 offset may already be applied to the argument structure
passed to __tls_get_addr at ld time, without any opportunity for
runtime relocations.
2. __tls_get_addr may be used with a zero offset argument to obtain a
base address for the module's TLS, to which the caller then applies
immediate offsets for individual objects accessed using the local
dynamic model. since the immediate offsets have the -0x8000 adjustment
applied to them, the base address they use needs to include the
+0x8000 offset.
it would be possible, but more complex, to store the pointers in the
dtv[] array with the +0x8000 offset pre-applied, to avoid the runtime
cost of adding 0x8000 on each call to __tls_get_addr. this change
could be made later if measurements show that it would help.
| Rich Felker | 2015-06-25 | 1 | -3/+3 |
| * | make dynamic linker work around MAP_FAILED mmap failure on nommu kernels•••previously, loading of additional libraries beyond libc/ldso did not
work on nommu kernels, nor did loading programs via invocation of the
dynamic linker as a command.
| Rich Felker | 2015-06-23 | 1 | -2/+24 |
| * | ignore ENOSYS error from mprotect in pthread_create and dynamic linker•••this error simply indicated a system without memory protection (NOMMU)
and should not cause failure in the caller.
| Rich Felker | 2015-06-17 | 1 | -2/+4 |
| * | fix regression in pre-v7 arm on kernels with kuser helper removed•••the arm atomics/TLS runtime selection code is called from
__set_thread_area and depends on having libc.auxv and __hwcap
available. commit 71f099cb7db821c51d8f39dfac622c61e54d794c moved the
first call to __set_thread_area to the top of dynamic linking stage 3,
before this data is made available, causing the runtime detection code
to always see __hwcap as zero and thereby select the atomics/TLS
implementations based on kuser helper.
upcoming work on superh will use similar runtime detection.
ideally this early-init code should be cleanly refactored and shared
between the dynamic linker and static-linked startup.
| Rich Felker | 2015-06-07 | 1 | -17/+14 |
| * | fix dynamic linker regression processing R_*_NONE type relocations•••commit f3ddd173806fd5c60b3f034528ca24542aecc5b9 inadvertently removed
the early check for "none" type relocations, causing the address
dso->base+0 to be dereferenced to obtain an addend. shared libraries,
(including libc.so) and PIE executables were unaffected, since their
base addresses are the actual address of their mappings and are
readable. non-PIE main executables, however, have a base address of 0
because their load addresses are absolute and not offset at load time.
in practice none-type relocations do not arise with toolchains that
are in use except on mips, and on mips it's moderately rare for a
non-PIE executable to have a relocation table, since the mips-specific
got processing serves in its place for most purposes.
| Rich Felker | 2015-06-04 | 1 | -0/+1 |
| * | reprocess all libc/ldso symbolic relocations in dynamic linking stage 3•••commit f3ddd173806fd5c60b3f034528ca24542aecc5b9 introduced early
relocations and subsequent reprocessing as part of the dynamic linker
bootstrap overhaul, to allow use of arbitrary libc functions before
the main application and libraries are loaded, but only reprocessed
GOT/PLT relocation types.
commit c093e2e8201524db0d638920e76bcb6b1d925f3a added reprocessing of
non-GOT/PLT relocations to fix an actual regression that was observed
on powerpc, but only for RELA format tables with out-of-line addends.
REL table (inline addends at the relocation address) reprocessing is
trickier because the first relocation pass clobbers the addends.
this patch extends symbolic relocation reprocessing for libc/ldso to
support all relocation types, whether REL or RELA format tables are
used. it is believed not to alter behavior on any existing archs for
the current dynamic linker and libc code. the motivations for this
change are consistency and future-proofing. it ensures that behavior
does not differ depending on whether REL or RELA tables are used,
which could lead to undetected arch-specific bugs. it also ensures
that, if in the future code depending on additional relocation types
is added to libc.so, either at the source level or as part of the
compiler runtime that gets pulled in (for example, soft-float with TLS
for fenv), the new code will work properly.
the implementation concept is simple: stage 2 of the dynamic linker
counts the number of symbolic relocations in the libc/ldso REL table
and allocates a VLA to save their addends into; stage 3 then uses the
saved addends in place of the inline ones which were clobbered. for
stack safety, a hard limit (currently 4k) is imposed on the number of
such addends; this should be a couple orders of magnitude larger than
the actual need. this number is not a runtime variable that could
break fail-safety; it is constant for a given libc.so build.
| Rich Felker | 2015-05-25 | 1 | -11/+43 |
| * | move call to dynamic linker stage-3 into stage-2 function•••this move eliminates a duplicate "by-hand" symbol lookup loop from the
stage-1 code and replaces it with a call to find_sym, which can be
used once we're in stage 2. it reduces the size of the stage 1 code,
which is helpful because stage 1 will become the crt start file for
static-PIE executables, and it will allow stage 3 to access stage 2's
automatic storage, which will be important in an upcoming commit.
| Rich Felker | 2015-05-25 | 2 | -11/+8 |
| * | simplify/shrink relocation processing in dynamic linker stage 1•••the outer-loop approach made sense when we were also processing
DT_JMPREL, which might be in REL or RELA form, to avoid major code
duplication. commit 09db855b35709aa627d7055c57a98e1e471920ab removed
processing of DT_JMPREL, and in the remaining two tables, the format
(REL or RELA) is known by the name of the table. simply writing two
versions of the loop results in smaller and simpler code.
| Rich Felker | 2015-05-25 | 1 | -23/+15 |
| * | remove processing of DT_JMPREL from dynamic linker stage 1 bootstrap•••the DT_JMPREL relocation table necessarily consists entirely of
JMP_SLOT (REL_PLT in internal nomenclature) relocations, which are
symbolic; they cannot be resolved in stage 1, so there is no point in
processing them.
| Rich Felker | 2015-05-25 | 1 | -1/+0 |
| * | reprocess libc/ldso RELA relocations in stage 3 of dynamic linking•••this fixes a regression on powerpc that was introduced in commit
f3ddd173806fd5c60b3f034528ca24542aecc5b9. global data accesses on
powerpc seem to be using a translation-unit-local GOT filled via
R_PPC_ADDR32 relocations rather than R_PPC_GLOB_DAT. being a non-GOT
relocation type, these were not reprocessed after adding the main
application and its libraries to the chain, causing libc code not to
see copy relocations in the main program, and therefore to use the
pre-copy-relocation addresses for global data objects (like environ).
the motivation for the dynamic linker only reprocessing GOT/PLT
relocation types in stage 3 is that these types always have a zero
addend, making them safe to process again even if the storage for the
addend has been clobbered. other relocation types which can be used
for address constants in initialized data objects may have non-zero
addends which will be clobbered during the first pass of relocation
processing if they're stored inline (REL form) rather than out-of-line
(RELA form).
powerpc generally uses only RELA, so this patch is sufficient to fix
the regression in practice, but is not fully general, and would not
suffice if an alternate toolchain generated REL for powerpc.
| Rich Felker | 2015-05-18 | 1 | -1/+1 |
| * | remove always-true conditional in dynamic linker TLSDESC processing•••the allocating path which can fail is for dynamic TLS, which can only
occur at runtime, and the check for runtime was already made in the
outer conditional.
| Rich Felker | 2015-04-21 | 1 | -1/+1 |
| * | remove redundant code in do_dlsym function•••commit 637dd2d383cc1f63bf02a732f03786857b22c7bd introduced the checks
for RTLD_DEFAULT and RTLD_NEXT here, claiming they fixed a regression,
but the above conditional block clearly already covered these cases,
and removing the checks produces no difference in the generated code.
| Rich Felker | 2015-04-21 | 1 | -1/+1 |
| * | make dlerror state and message thread-local and dynamically-allocated•••this fixes truncation of error messages containing long pathnames or
symbol names.
the dlerror state was previously required by POSIX to be global. the
resolution of bug 97 relaxed the requirements to allow thread-safe
implementations of dlerror with thread-local state and message buffer.
| Rich Felker | 2015-04-18 | 1 | -32/+61 |
| * | apply hidden visibility to tlsdesc accessor functions•••these functions are never called directly; only their addresses are
used, so PLT indirections should never happen unless a broken
application tries to redefine them, but it's still best to make them
hidden.
| Rich Felker | 2015-04-17 | 5 | -0/+10 |
| * | comment fixes in aarch64 tlsdesc asm | Szabolcs Nagy | 2015-04-17 | 1 | -4/+4 |
| * | ensure debugger hook for dynamic linker does not point to a PLT slot•••this change is made in preparation to support linking without
-Bsymbolic-functions.
| Rich Felker | 2015-04-17 | 1 | -2/+4 |
| * | fix PLT call offset in sh dlsym asm•••the braf instruction's destination register is an offset from the
address of the braf instruction plus 4 (or equivalently, the address
of the next instruction after the delay slot). the code for dlsym was
incorrectly computing the offset to pass using the address of the
delay slot itself. in other places, a label was placed after the delay
slot, but I find this confusing. putting the label on the branch
instruction itself, and manually adding 4, makes it more clear which
branch the offset in the constant pool goes with.
| Rich Felker | 2015-04-17 | 1 | -3/+3 |
| * | fix sh build regressions in asm•••even hidden functions need @PLT symbol references; otherwise an
absolute address is produced instead of a PC-relative one.
| Rich Felker | 2015-04-17 | 1 | -1/+1 |
| * | use hidden __tls_get_new for tls/tlsdesc lookup fallback cases•••previously, the dynamic tlsdesc lookup functions and the i386
special-ABI ___tls_get_addr (3 underscores) function called
__tls_get_addr when the slot they wanted was not already setup;
__tls_get_addr would then in turn also see that it's not setup and
call __tls_get_new.
calling __tls_get_new directly is both more efficient and avoids the
issue of calling a non-hidden (public API/ABI) function from asm.
for the special i386 function, a weak reference to __tls_get_new is
used since this function is not defined when static linking (the code
path that needs it is unreachable in static-linked programs).
| Rich Felker | 2015-04-14 | 3 | -4/+10 |
| * | use hidden visibility for call from dlsym to internal __dlsym | Rich Felker | 2015-04-14 | 11 | -3/+14 |
| * | fix inconsistent visibility for internal __tls_get_new function•••at the point of call it was declared hidden, but the definition was
not hidden. for some toolchains this inconsistency produced textrels
without ld-time binding.
| Rich Felker | 2015-04-14 | 1 | -0/+1 |
| * | make _dlstart_c function use hidden visibility•••otherwise the call/jump from the crt_arch.h asm may not resolve
correctly without -Bsymbolic-functions.
| Rich Felker | 2015-04-14 | 1 | -0/+1 |
| * | remove initializers for decoded aux/dyn arrays in dynamic linker•••the zero initialization is redundant since decode_vec does its own
clearing, and it increases the risk that buggy compilers will generate
calls to memset. as long as symbols are bound at ld time, such a call
will not break anything, but it may be desirable to turn off ld-time
binding in the future.
| Rich Felker | 2015-04-13 | 1 | -5/+5 |
| * | remove remnants of support for running in no-thread-pointer mode•••since 1.1.0, musl has nominally required a thread pointer to be setup.
most of the remaining code that was checking for its availability was
doing so for the sake of being usable by the dynamic linker. as of
commit 71f099cb7db821c51d8f39dfac622c61e54d794c, this is no longer
necessary; the thread pointer is now valid before any libc code
(outside of dynamic linker bootstrap functions) runs.
this commit essentially concludes "phase 3" of the "transition path
for removing lazy init of thread pointer" project that began during
the 1.1.0 release cycle.
| Rich Felker | 2015-04-13 | 1 | -10/+2 |
| * | move thread pointer setup to beginning of dynamic linker stage 3•••this allows the dynamic linker itself to run with a valid thread
pointer, which is a prerequisite for stack protector on archs where
the ssp canary is stored in TLS. it will also allow us to remove some
remaining runtime checks for whether the thread pointer is valid.
as long as the application and its libraries do not require additional
size or alignment, this early thread pointer will be kept and reused
at runtime. otherwise, a new static TLS block is allocated after
library loading has finished and the thread pointer is switched over.
| Rich Felker | 2015-04-13 | 1 | -8/+23 |
| * | stabilize dynamic linker's layout of static TLS•••previously, the layout of the static TLS block was perturbed by the
size of the dtv; dtv size increasing from 0 to 1 perturbed both TLS
arch types, and the TLS-above-TP type's layout was perturbed by the
specific number of dtv slots (libraries with TLS). this behavior made
it virtually impossible to setup a tentative thread pointer address
before loading libraries and keep it unchanged as long as the
libraries' TLS size/alignment requirements fit.
the new code fixes the location of the dtv and pthread structure at
opposite ends of the static TLS block so that they will not move
unless size or alignment changes.
| Rich Felker | 2015-04-13 | 1 | -9/+6 |