summaryrefslogtreecommitdiff
path: root/linker/linker.cpp
AgeCommit message (Collapse)Author
2014-01-13Make it possible for code to query the dynamic linker's default search path.Elliott Hughes
We're not going to have init(1) set LD_LIBRARY_PATH globally on 64-bit. This patch makes it possible for libnativehelper to set LD_LIBRARY_PATH in each Java VM (to support System.loadLibrary) without also hard-coding the default search path there. Change-Id: If13961fae976e06dd80d5ef522f31e8b7eb01154
2013-12-22Improve dynamic linker diagnostics for internal errors.Elliott Hughes
If the linker can't resolve its own internal references to symbols, we currently exit silently (albeit with EXIT_FAILURE). Not very helpful. Change-Id: I1614fc970dee4560b38832ede1987b65a8e53a1e
2013-12-17AArch64: Linker64 support for AArch64Marcus Oakland
Addition of support for AArch64 in the linker64 target. Change-Id: I8dfd9711278f6706063e91f626b6007ea7a3dd6e Signed-off-by: Marcus Oakland <marcus.oakland@arm.com>
2013-12-12Fix debugging issues in vdso handlingPavel Chupin
Under valgrind ehdr_vdso is null and causing segfault. Adding debug info for vdso producing plenty of issues on debugging through gdbserver, removing it. It doesn't seem it should be here. Unwinding through vdso test still works. Change-Id: I1a7e233c493f2268d725fa8d7279822d07decc49 Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
2013-10-31Fix linker crashes during unknown symbol lookupSergey Melnikov
Integration of kernel VDSO into internal bionic data structures using common functions. Fix for dl_iterate_phdr function: the function provides incorrect address of object in case of nonzero virtual and base addresses. Location in address space of a particular program header should be calculated using the formula: addr = base_addr + virtual_addr. Signed-off-by: Sergey Melnikov <sergey.melnikov@intel.com> Change-Id: Ie2ab4257fd456242aab8afed0bd5bd6b29e81d6d
2013-10-28Don't allow text relocations on 64-bit.Elliott Hughes
I've also updated our <sys/exec_elf.h> to match upstream. Change-Id: I52f9fce3167541811208d273ff23ceaa112f7135
2013-10-28Clean up linker architecture macros.Elliott Hughes
We don't need our own architecture macros; the standard ones will do. This patch also fixes some __x86_64__ tests to be USE_RELA tests instead, because they're not actually x86_64-specific. I've cleaned up architecture-specific code slightly so where possible all the code corresponding to a particular architecture is together. This patch also fixes a bug in LP64 DT_PLTGOT handling, which should be an error rather than falling through into DT_DEBUG! There was another #ifdef bug where we'd only report unexpected DT_ entries on MIPS. Change-Id: Id1d04e372611f641c1aa278a18e379f28af9eaf5
2013-10-24Revert "Don't warn about x86 text relocations. They're too prevalent."Elliott Hughes
This reverts commit 5be2c5998c996ff9d5efb94c127d9b832a295822. Change-Id: I3fc8ca530cdbd74c834fb9cfabe812c9386419fc
2013-10-23Don't warn about x86 text relocations. They're too prevalent.Elliott Hughes
We should fix this (and disallow it for x86_64), but for now let's get CTS running again. libdvm.so and libcutils.so are the main problems. $ scanelf -qT out/target/product/generic_x86/symbols/system/lib/libcutils.so libcutils.so: (memory/data?) [0x4125] in (optimized out: previous android_memset16) [0x4100] libcutils.so: (memory/data?) [0x424F] in (optimized out: previous android_memset16) [0x4100] libcutils.so: (memory/data?) [0x42F8] in (optimized out: previous android_memset16) [0x4100] libcutils.so: (memory/data?) [0x4349] in (optimized out: previous android_memset16) [0x4100] libcutils.so: (memory/data?) [0x4406] in (optimized out: previous android_memset16) [0x4100] libcutils.so: (memory/data?) [0x45AC] in (optimized out: previous android_memset32) [0x4590] libcutils.so: (memory/data?) [0x4650] in (optimized out: previous android_memset32) [0x4590] libcutils.so: (memory/data?) [0x46F9] in (optimized out: previous android_memset32) [0x4590] libcutils.so: (memory/data?) [0x474A] in (optimized out: previous android_memset32) [0x4590] libcutils.so: (memory/data?) [0x4807] in (optimized out: previous android_memset32) [0x4590] Bug: 11353056 Change-Id: Id4a76b310be7fe858a8a60d0d260b09913b66be9
2013-10-22change wording on text relocation message.Nick Kralevich
The current message is too alarmist. Change-Id: I53e8eadca239f867b4e6b9c193eba96e267950c3
2013-10-16x86_64: Add R_X86_64_64 relocation handlingPavel Chupin
Change-Id: I86ffc56fa6a9053bed44e92a579530c2beb8eb2c Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
2013-10-09x86_64: Rename 64-bit linker to linker64Pavel Chupin
That's for having both on the same system. Change-Id: Ic2bc2c015e6486e8b6a7576f7b28d2d027534368 Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
2013-10-09Fix x86_64 build, clean up intermediate libraries.Elliott Hughes
The x86_64 build was failing because clone.S had a call to __thread_entry which was being added to a different intermediate .a on the way to making libc.so, and the linker couldn't guarantee statically that such a relocation would be possible. ld: error: out/target/product/generic_x86_64/obj/STATIC_LIBRARIES/libc_common_intermediates/libc_common.a(clone.o): requires dynamic R_X86_64_PC32 reloc against '__thread_entry' which may overflow at runtime; recompile with -fPIC This patch addresses that by ensuring that the caller and callee end up in the same intermediate .a. While I'm here, I've tried to clean up some of the mess that led to this situation too. In particular, this removes libc/private/ from the default include path (except for the DNS code), and splits out the DNS code into its own library (since it's a weird special case of upstream NetBSD code that's diverged so heavily it's unlikely ever to get back in sync). There's more cleanup of the DNS situation possible, but this is definitely a step in the right direction, and it's more than enough to get x86_64 building cleanly. Change-Id: I00425a7245b7a2573df16cc38798187d0729e7c4
2013-10-08Use /system/lib64 and /vendor/lib64 for 64-bit libraries.Elliott Hughes
Change-Id: I4886aeb3070bf97b4cfe8053388ecb1bda288017
2013-10-08x86_64 linker.Elliott Hughes
Based on I8dc3e2cb596f75dc58ae82e4dc58f8c177dd3323 by Pavel Chupin <pavel.v.chupin@intel.com>. Change-Id: Icd582d277cbe273477b450f2848343d72c86ec9f
2013-09-30Remove 32-bit assumptions from the ELF code.Elliott Hughes
Change-Id: I2c1f3d34c33685799aade8866eec44479ff9f963
2013-09-06Add the dl_iterate_phdr function to libdl for arm.Christopher Ferris
Bug: 8410085 Merge from internal master. (cherry-picked from cb491bc66dc0abc145930b09086eb9189a30f6c2) Change-Id: I94ed51bc5d4c626df7552c0e85c31ccee2d6568f
2013-08-21Make mips_relocate_got tolerate a missing gotBrian Carlstrom
Bug: 10094803 (cherry picked from commit 7ee26878065abb494600595349ce58b2b2db3709) Change-Id: Ib15bccecaee421dc463d46a3956b054051708759
2013-06-25Kernel dso support for 'dl_iterate_phdr' functionSergey Melnikov
Kernel provides virtual DSO for stack unwinding/exception handlind info for signal usage case. Stack unwinding routines use 'dl_iterate_phdr' function for additional DWARF info gathering from DSOs. Patch enables virtual DSO enumeration via dl_iterate_phdr function. Signed-off-by: Sergey Melnikov <sergey.melnikov@intel.com> Change-Id: Ic2882b28f40b456a088bc1e63c50cbfda7e4a102
2013-06-21linker: Emit a warning on text relocationsNick Kralevich
Text relocations unnecessarily mark pages as dirty, preventing them from being swapped out, wasting memory. Also, text relocations prevent the code from running on certain hardened systems. Print a message in logcat and stderr when we see a text relocation, to encourage developers to fix their code. Change-Id: I6051a7463911e090ae5727a355397d539669d5b9
2013-06-18Make LD_PRELOAD failures just warnings.Elliott Hughes
This matches glibc and makes life easier for developers who want to sometimes preload a library from init (which has no conditionals); they can simply move/remove the library to disable. Change-Id: I579b8633f958235af6e46bb53b378b9e363afb1f
2013-06-03Small cleanup of soinfo_elf_lookup.Christopher Ferris
- Remove unnecessary line. - Move declarations to first use. Change-Id: I1d8398d6c13f7cb86bffe0b68af849e35a4b234d
2013-05-09Don't fail to run DT_INIT and DT_INIT_ARRAY constructors if a shared library ↵Elliott Hughes
has DT_PREINIT_ARRAY constructors. The GNU dynamic linker silently ignores a DT_PREINIT_ARRAY section in a shared library. We had ineffectual code that tried to report an error, which I tried to fix but got wrong --- my version still wouldn't report the error to the caller, but would prevent us from continuing to call constructors. Bug: 8825226 Change-Id: I4fd8450ecc44d8767a1cb808aeecfbfbfc77c070
2013-04-25linker: only re-open std* for setuid programs.Nick Kralevich
get_AT_SECURE() was getting called before linker_env_init() had been called, and returning the default value ("true"). This was causing us to reopen closed stdin, stdout, and stderr for ALL processes, not just privileged (setuid) processes. Calling path: - __linker_init - soinfo_link_image - get_AT_SECURE - __linker_init_post_relocation - linker_env_init This change restores the intended behavior of only re-opening stdin, stdout, and stderr for privileged processes. Change-Id: I8b085ea6597710ac4c1a3c93f1bf8b81eecb08c0
2013-04-05Make abort messages available to debuggerd.Elliott Hughes
This adds __libc_fatal, cleans up the internal logging code a bit more, and switches suitable callers over to __libc_fatal. In addition to logging, __libc_fatal stashes the message somewhere that the debuggerd signal handler can find it before calling abort. In the debuggerd signal handler, we pass this address to debuggerd so that it can come back with ptrace to read the message and present it to the user. Bug: 8531731 Change-Id: I416ec1da38a8a1b0d0a582ccd7c8aaa681ed4a29
2013-03-22Drop unnecessary execution permission for .cpp/.c/.hKito Cheng
Change-Id: I9ac2b9d8f6bdb4fab8962210c5ec8f9c3e8c0ebf
2013-03-15Clean up internal libc logging.Elliott Hughes
We only need one logging API, and I prefer the one that does no allocation and is thus safe to use in any context. Also use O_CLOEXEC when opening the /dev/log files. Move everything logging-related into one header file. Change-Id: Ic1e3ea8e9b910dc29df351bff6c0aa4db26fbb58
2013-03-12Use more types than just 'unsigned' in the linker.Elliott Hughes
Still chipping away at the situation where every variable in the linker was of type 'unsigned'. This patch switches counts over to being size_t and adds an explicit type for init/fini function pointers and arrays of function pointers. Also improve logging from CallArray. Also remove trailing "\n"s from log messages. Change-Id: Ie036d2622caac50f4d29f0570888bb527661d77e
2013-03-12Use Elf32_Addr instead of unsigned in linkerKito Cheng
Change-Id: I52dcbb4b0ff0a4052e0ad7a9bbeb2df65c9d2f66
2013-03-06Fix typo of DT_NEEDED for DT_NULLBrian Carlstrom
(cherry-pick of 138b205ea9efc117fe522c2d7191378023a6e2cd) Change-Id: Ia895cb3018df55554627f1f61dcdfdada4a961ce
2013-03-06Fix TIMING/STATS/COUNT_PAGES dynamic linker buildKito Cheng
Change-Id: I6432ac378816da253b83d1c7fb1d3fb64647b89e
2013-03-06Fix MIPS linker buildBrian Carlstrom
(cherry-picked from 8c7d8c2057e303985f78eab96da747ddaa013c78) Change-Id: Idcf62ab95f8fccbc2d7c3e771a4cfbe768a1555e
2013-03-05More linker cleanup.Elliott Hughes
Change-Id: I9fb3c7c0d4b4ffef0eeaf092d4e30ffe63a08671
2013-03-05Minor linker cleanup, primarily to use Elf32_DynBrian Carlstrom
Change-Id: Ifa9408e9859c6f79444715bed4808b7c13fdced5
2013-02-08Switch to using AT_RANDOM for the stack guards.Elliott Hughes
Bug: 7959813 Change-Id: I8db4b8912ba649bfe668c6f22aa44690ddd401a2
2013-02-07Clean up the argc/argv/envp/auxv handling.Elliott Hughes
There's now only one place where we deal with this stuff, it only needs to be parsed once by the dynamic linker (rather than by each recipient), and it's now easier for us to get hold of auxv data early on. Change-Id: I6314224257c736547aac2e2a650e66f2ea53bef5
2013-02-06Remove partial implementation of MIPS non-PIC support.Elliott Hughes
Change-Id: I3c287e52aae10559508174e73113367aea40e5c2
2013-01-18Fix the duplication in the debugging code.Elliott Hughes
We had two copies of the backtrace code, and two copies of the libcorkscrew /proc/pid/maps code. This patch gets us down to one. We also had hacks so we could log in the malloc debugging code. This patch pulls the non-allocating "printf" code out of the dynamic linker so everyone can share. This patch also makes the leak diagnostics easier to read, and makes it possible to paste them directly into the 'stack' tool (by using relative PCs). This patch also fixes the stdio standard stream leak that was causing a leak warning every time tf_daemon ran. Bug: 7291287 Change-Id: I66e4083ac2c5606c8d2737cb45c8ac8a32c7cfe8
2013-01-16Revert "stack protector: use AT_RANDOM"Nick Kralevich
The AT_RANDOM changes broke setuid / setgid executables such as "ping". When the linker executes a setuid program, it cleans the environment, removing any invalid environment entries, and adding "NULL"s to the end of the environment array for each removed variable. Later on, we try to determine the location of the aux environment variable, and get tripped up by these extra NULLs. Reverting this patch will get setuid executables working again, but getauxval() is still broken for setuid programs because of this bug. This reverts commit e3a49a8661125f24aec8a1453e54b3b78005e21e. Change-Id: I05c58a896b1fe32cfb5d95d43b096045cda0aa4a
2013-01-16stack protector: use AT_RANDOMNick Kralevich
Populate the stack canaries from the kernel supplied AT_RANDOM value, which doesn't involve any system calls. This is slightly faster (6 fewer syscalls) and avoids unnecessarily reading /dev/urandom, which depletes entropy. Bug: 7959813 Change-Id: If2b43100a2a9929666df3de56b6139fed969e0f1
2013-01-14Fix my git mistake.Elliott Hughes
This was the formatting change that was supposed to be in cf23905a4bcc7bfdd109be5b6d69ad06877aa217. Change-Id: Ib79fa031b68f6f541f532507eb589afeaedb831f
2013-01-14[MIPS] Set DT_DEBUG dyntab entry if it is writableChris Dearman
This is primarily for MIPS exutables that do not have a DT_MIPS_RLD_MAP entry. Change-Id: I4c221d92debcfed961eeee2515123f3fb21ec8e6 Signed-off-by: Chris Dearman <chris@mips.com>
2013-01-03Fix debug malloc.Elliott Hughes
...which has been broken since the linker data structures went read-only. Bug: 7941716 Change-Id: If28f6bac0fcb13e371e4d85b064544f561c8d692
2012-12-20Support System.loadLibrary for libraries with transitive dependencies.Elliott Hughes
Also fix the FLAG_ERROR annoyance --- it's not helpful to cache failures. Bug: 7896159 Bug: http://code.google.com/p/android/issues/detail?id=34416 Bug: http://code.google.com/p/android/issues/detail?id=22143 Change-Id: I60f235edb4ea4756e1f7ce56f7739f18e8a50789
2012-12-18Check for unknown flags passed to dlopen(3).Elliott Hughes
Change-Id: I56f4aab0e5a1487bc32d2c4d231e8bd15c4ac8da
2012-11-26Do not include '\0' when writing error messages to stderrChris Dearman
Change-Id: I6adc806c3920e5a4ae61ca55c40613fcf338b18c Signed-off-by: Chris Dearman <chris@mips.com>
2012-11-19We should use load_bias. This patch fixes MIPS NDK device exception test ↵Chao-Ying Fu
failures. Change-Id: I4b718c36666e66062c1f13e4deea1ec7a7951c54
2012-11-05Tone down some of the overly-verbose linker logging.Elliott Hughes
We don't need to see every dlopen(3)/dlsym(3) failure unless LD_DEBUG is on. Change-Id: I1edfe8b72f32ff54dd30e1acf32e20d470d5e9f7
2012-11-02Make dynamic linker debugging always available.Elliott Hughes
If you need to build your own linker to get debugging, the debugging is never available when you need it. Change-Id: I5ff7e55753459d49a2990f25d9aa155e0b8602e0
2012-11-02Merge "Adjust symbol lookup for DT_SYMBOLIC case"Elliott Hughes