summaryrefslogtreecommitdiff
path: root/linker/linker.cpp
AgeCommit message (Collapse)Author
2012-11-02Adjust symbol lookup for DT_SYMBOLIC casePavel Chupin
According ELF spec re. DT_SYMBOLIC: This element's presence in a shared object library alters the dynamic linker's symbol resolution algorithm for references within the library. Instead of starting a symbol search with the executable file, the dynamic linker starts from the shared object itself. If the shared object fails to supply the referenced symbol, the dynamic linker then searches the executable file and other shared objects as usual. This change implements the last part. Change-Id: Iae95d53d455313a4306f11733941bcd3596ac85f Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
2012-11-01Allow dlopen("egl/blah.so").Elliott Hughes
NVIDIA binary blobs construct strings to pass to dlopen(3) that contain '/' but require that we fall back to LD_LIBRARY_PATH. Change-Id: Iad831899986baace6962f4b335eeb288250a1e22
2012-11-01Keep the dynamic linker's soinfo pools mostly read-only.Elliott Hughes
We'll need a lot more refactoring of this code before we can reduce the granularity, but this is a step forward. Change-Id: I07061720e734b571a8399c1d5b4f2f35cd681307
2012-11-01Stop defining our own PAGE_SIZE and PAGE_MASK, and test dlclose(3) too.Elliott Hughes
Also remove an unnecessary #include and a now-obsolete TODO. Change-Id: I36d923721e349a286934b9534090a67ce0786e7b
2012-11-01Dynamically allocate soinfo-structs in linkerMagnus Malmborn
Request memory from the system when needed instead of having a fixed array for soinfo structs. Note that malloc() et al can't be used in linker, so use mmap() instead. Change-Id: I4b495995931d7752b0e8c944e64d1fe41b9f7144
2012-10-31Reject .so files with no sysv hash table.Elliott Hughes
Also ensure that dlopen(3) errors always include the name of the library we failed to open. Also fix a bug where we'd fall back to searching LD_LIBRARY_PATH and the built-in paths for names that include slashes. Bug: http://code.google.com/p/android/issues/detail?id=38479 Change-Id: Ib2c009ed083344a7a012749d58f8679db2f26c78
2012-10-30linker: handle R_ARM_COPY relocations in a proper wayArd Biesheuvel
If an executable contain copy relocations, other references to the symbol it points to should be preempted and made to point to the copy instead. Also, the linker should make sure the target area has sufficient space to contain the copy. It also checks whether the library that supplies the symbol is built with -Bsymbolic, and errors out if this is the case. Change-Id: If135c83590092741cfd8f82f54816f363a4a4a3b Signed-off-by: Ard Biesheuvel <ard.biesheuvel@gmail.com>
2012-10-30More dynamic linker cleanup.Elliott Hughes
I still want to break linker_format out into its own library so we can reuse it for malloc debugging and so forth. (There are many similar pieces of code in bionic, but the linker's one seems to be the most complete/functional.) Change-Id: If3721853d28937c8e821ca1d23cf200e228a409a
2012-10-16Make dlerror(3) thread-safe.Elliott Hughes
I gave up trying to use the usual thread-local buffer idiom; calls to calloc(3) and free(3) from any of the "dl" functions -- which live in the dynamic linker -- end up resolving to the dynamic linker's stubs. I tried to work around that, but was just making things more complicated. This alternative costs us a well-known TLS slot (instead of the dynamically-allocated TLS slot we'd have used otherwise, so no difference there), plus an extra buffer inside every pthread_internal_t. Bug: 5404023 Change-Id: Ie9614edd05b6d1eeaf7bf9172792d616c6361767
2012-10-11Fix dlerror(3).Elliott Hughes
Add unit tests for dlerror(3) in various situations. I think We're at least as good as glibc now. Also factor out the ScopedPthreadMutexLock and use it here too. Bug: http://code.google.com/p/android/issues/detail?id=38398 Change-Id: I040938b4366ab836e3df46d1d8055b92f4ea6ed8
2012-09-13bionic: linker: Need update the map->l_addr for execution.Xiaokang Qin
Currently, linker doesn't update the map->l_addr for execution. Which could break the Unwind_Backtrace with PT_GNU_EH_FRAME enabled in new toolchain. Change-Id: Ifbd853134da64a962f7e4c4105e56a3f20def1b2 Author: Fengwei Yin <fengwei.yin@intel.com> Signed-off-by: Jack Ren <jack.ren@intel.com> Author-tracking-BZ: 57077
2012-08-29Improve the dynamic linker diagnostics.Elliott Hughes
Lose the pid, only show the name of the function (not its whole signature), and include the name of the library we failed to load. (I hadn't noticed that the library name was missing before because in Java we add that into the UnsatisfiedLinkError detail message.) The new output looks like this: Cannot load library: soinfo_relocate(linker.cpp:968): cannot locate symbol "__libc_malloc_default_dispatch" referenced by "libc_malloc_debug_leak.so"... Change-Id: I3bb5c9780d9aaf3a9e4418ea55bc98122a81f80f
2012-08-28linker: Fix ARM_R_COPY relocationsNick Kralevich
Per http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044d/IHI0044D_aaelf.pdf Section 4.7.1.10, ARM_R_COPY relocations are only suppose to reference shared libraries, not the executable itself. When resolving an R_ARM_COPY symbol, ensure we don't look in our own symbol. This partially addresses http://code.google.com/p/android/issues/detail?id=28598 . After this patch, the printfs generated by the test program are: global = 0x42 (0x401c7000) global = 0x42 (0x11000) before, the output was: global = 0x42 (0x40071000) global = 0x0 (0x11000) I'm still not very happy with this patch, but I think it's an improvement over where we were at before. This change was modeled after https://android-review.googlesource.com/38871 Change-Id: Id7ad921e58395e76a36875bcc742ec5eeba53f08
2012-08-14More cleanup.Elliott Hughes
Make more stuff static, remove some dead code, and fix a few typos. Change-Id: I010b0eadeaf61e2899c37014ad1e7082c70bd510
2012-08-14linker: avoid clobbering the .dynamic section of shared libsArd Biesheuvel
This patch removes the DT_NEEDED hack which stores pointers to soinfo structs in the .dynamic section of the library being loaded. Instead, it caches the soinfo struct pointers on the stack during relocation time. After relocation time, i.e. when calling constructors and destructors of the shared library and its dependencies, uncached access is used instead, doing lookups using the string table entries pointed to by the DT_NEEDED entries. By removing this hack, it is no longer needed to undo the PT_GNURELRO protection, i.e., all non-writable mappings can remain non-writable during their entire lifespan. Even though, strictly speaking, the algorithmic complexity has increased somewhat, the real-world adverse effect is negligible on the systems I have tested. Change-Id: I2361502560b96b5878f7f94a8e8a215350d70d64 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@gmail.com>
2012-08-13Fix module constructor order.Evgeniy Stepanov
.preinit_array goes before the constructors of LD_PRELOAD-ed libraries. Change-Id: I1af32ce29eaf3ca4351ae8a0f7f5da5165853216
2012-08-13linker: don't perform unnecessary mprotectsNick Kralevich
The linker only needs to mark the text segment as writable iff the file has text relocations. Unnecessarily calling mprotect when it isn't necessary is slow, and some security enhanced kernels don't like it. Pages which are simultaneously writable and executable are considered a no-no. The vast majority of executables / shared libraries on Android do NOT have text relocations. Change-Id: Ic38ce30a99b7e33ecf21efd9c108547a58eafa35
2012-08-10Set the dynamic field in the link map for the linker itself.Ben Cheng
Otherwise gdb will print a spurious warning each time gdb is used: warning: .dynamic section for "/system/bin/linker" is not at the expected address (wrong library or version mismatch?) BUG:6946614 Change-Id: Ib21b8db0615751189c1601140deb43bc089289b6
2012-08-07Clean up the linker a bit, remove prelinking support.Elliott Hughes
Also make the errors more readable, since none of us seemed to know what they actually meant. The new style is still as verbose as the old, but that's probably necessary in the absence of chained exceptions in C. Here's what you'd see if you try to boot after removing libsurfaceflinger.so: 32267 32267 E AndroidRuntime: java.lang.UnsatisfiedLinkError: Cannot load library: (linker.c:1629, pid 32259) soinfo_link_image: could not load library "libsystem_server.so" needed by "libandroid_servers.so"; caused by (linker.c:1629, pid 32259) soinfo_link_image: could not load library "libsurfaceflinger.so" needed by "libsystem_server.so"; caused by (linker.c:709, pid 32259) load_library: library "libsurfaceflinger.so" not found This patch also fixes almost all of the compiler warnings. Change-Id: I64bb59aed6d4e039c15ea45be2367f319ef879f8