Commit graph

507 commits

Author SHA1 Message Date
Dmitriy Ivanov
96bc37f2e1 Return has_DT_SYMBOLIC flag.
This reverts commit 8f61d99183

 Despite the fact that static linker does all the work while linking
 -Bsymbolic executables, according to the SCO doc following DT_SYMBOLIC
 and DF_SYMBOLIC flags is still a requirement for the dynamic linker
 as well.

 (see http://www.sco.com/developers/gabi/2012-12-31/ch5.dynamic.html)

Change-Id: I23f6a5e9b662e40cdbc462b64feff912431e800c
2014-09-29 12:10:36 -07:00
Ningsheng Jian
e93be99da0 Fix gdb could not get shared library list issue
Get dynamic flags from phdr table's correct entry rather the first
entry, so that the following DT_DEBUG entry can be set.

Also fix the undefined reference to LoadTask::deleter issue under gcc
-O0 option.

Bug: 17524778
Change-Id: I9c679af197b034761fb739d6c980e628ff2ab84c
2014-09-26 22:58:57 +00:00
Dan Albert
4a6e71100e Merge "Add a dummy atexit(3) to the linker." 2014-09-24 17:27:38 +00:00
Dan Albert
9a05e3818a Add a dummy atexit(3) to the linker.
This is needed when building the linker against a libc that was built
with coverage information.

Bug: 17553780
Change-Id: If131002e067dd7768fc657c30e62c42a45c05ace
2014-09-24 10:26:41 -07:00
Elliott Hughes
0dc39f9952 Fix a couple more cases of missing CLOEXEC.
The debuggerd case can probably never happen, because you're crashing at this
point anyway. The system property one seems possible though.

Change-Id: Idba6a4f1d68587ec5b320d1e25f0b6a987ea32a0
2014-09-22 17:43:09 -07:00
Dmitriy Ivanov
1b77423eff Temporary disable DL_WARNs for unused DT_*
Bug: 17552334
Change-Id: I2f7b5e4b4d1db96e812a7f86adc929e113d4c11a
2014-09-17 16:46:40 -07:00
Dmitriy Ivanov
f240aa8089 Fix 64bit build
Change-Id: I6ef55b5951270c46ee5e9a11385bd09e33a9f969
2014-09-16 23:34:20 -07:00
Dmitriy Ivanov
4a6e9a835a Fix some unused DT_ warnings
* DT_PLTGOT - ignored for non-mips
 * DT_RELCOUNT/RELACOUNT - ignored
 * DT_RELENT/RELAENT - sanity checks
 * DT_SYMENT - sanity check
 * DT_SONAME - ignore for now.

Change-Id: Ied90748d12f733a84f6c38a1250567a2f77608b7
2014-09-16 18:19:36 -07:00
Dmitriy Ivanov
8f61d99183 Remove has_DT_SYMBOLIC flag
From the elf-spec: "Symbolically bound shared objects are
  identified by the .dynamic entry DT_SYMBOLIC. This tag is
  informational only; the runtime linker processes symbol
  lookups from these objects in the same manner as any
  other object."

Change-Id: I4aae0e502ed9fac096fbf076f4d6b2e055d784f6
2014-09-16 15:26:47 -07:00
Dmitriy Ivanov
e8ba50fe0d Fix dlsym() to take into account RTLD_GLOBAL/LOCAL
Symbols from libraries opened with RTLD_LOCAL (default)
  should not be visible via dlsym(RLTD_DEFAULT/RTLD_NEXT, .)

Bug: 17512583
Change-Id: I1758943081a67cf3d49ba5808e061b8251a91964
2014-09-15 17:39:48 -07:00
Dmitriy Ivanov
d74aa58035 Merge "Fix unload of recursively linked library" 2014-09-12 16:55:42 +00:00
Dmitriy Ivanov
aad92067bf Merge "Reformatting" 2014-09-12 16:50:29 +00:00
Dmitriy Ivanov
66bbf1595c Merge "Refactoring: C++11 style DISABLE_ bionic marcos" 2014-09-12 16:50:05 +00:00
Dmitriy Ivanov
6abf624d12 Reformatting
No functional changes.

Change-Id: If71775e5fc207e91ebd31ba3c5f9d2c13dc8dada
2014-09-12 09:43:13 -07:00
Dmitriy Ivanov
a6ac54a215 Fix unload of recursively linked library
Expanded test for recursive libs. Fixed bug with unnecessary
  soinfo_free of already loaded library.

Change-Id: I2cc19f2650c8b12a35feeac127ef608ebba44d88
2014-09-11 22:40:48 -07:00
Dmitriy Ivanov
9aea164457 Add IFUNC support for arm64 and IRELATIVE reloc
There are number of changes in the way IFUNC related relocations are done:
 1. IRELATIVE relocations are now supported for x86/x86_64 and arm64.
 2. IFUNC relocations are now relying on static linker to generate
    them in correct order - this removes necessety of additional
    relocation pass for ifuncs.
 3. Related to 2: rela?.dyn relocations are preformed before .plt ones.
 4. Ifunc are resolved on symbol lookup this approach allowed to avoid
    mprotect(PROT_WRITE) call on r-x program segments.

Bug: 17399706
Bug: 17177284
Change-Id: I414dd3e82bd47cc03442c5dfc7c279949aec51ed
2014-09-11 16:30:45 -07:00
Dmitriy Ivanov
d9ff722661 Refactoring: C++11 style DISABLE_ bionic marcos
Enable the -std=gnu++11 flag for libstdc++ static and
  dynamic libs.

  ScopeGuard uses DISABLE_ macros instead of '= delete';

Change-Id: I07e21b306f95fffd49345f7fa136cfdac61e0225
2014-09-08 17:51:31 -07:00
Dmitriy Ivanov
3c3624f3df Merge "Load libraries in breadth-first order" 2014-09-09 00:49:38 +00:00
Dmitriy Ivanov
14669a939d Load libraries in breadth-first order
This patch fixes the problem with symbol search order
  for dlsym(RTLD_DEFAULT/RTLD_NEXT, .) by loading libraries
  and ld_preloads in correct order.

Bug: https://code.google.com/p/android/issues/detail?id=74255
Change-Id: If1ba5c807322409faa914e27ecb675e2c4541f0d
Attempt: 2
2014-09-08 13:02:50 -07:00
Ying Wang
e07b4da53d Merge "Use LOCAL_POST_LINK_CMD to insert the objcopy command for linker." 2014-09-05 23:41:25 +00:00
Dmitriy Ivanov
498eb18b82 Revert "Load libraries in breadth-first order"
This reverts commit a3ad450a2e.

Change-Id: Ia2b838ad2159c643b80c514849582f4b4f4f40e5
2014-09-05 16:27:54 -07:00
Ying Wang
f9e147b0bf Use LOCAL_POST_LINK_CMD to insert the objcopy command for linker.
Previously we duplicated code in build/core/executable.mk and it's hard
to maintain. LOCAL_POST_LINK_CMD is a clean solution for this.

Bug: 17403674
Change-Id: I8c054bf782af68cf1f88b8d787a78ca74a7968b5
2014-09-05 16:16:35 -07:00
Dmitriy Ivanov
b2a30ee8d2 Fix order of soinfo links (repairs libcxx tests).
Change-Id: Iee9de09657351cd6a7512784ca797e4b84cdd98b
2014-09-05 16:01:47 -07:00
Chih-Hung Hsieh
b58db8b083 Enable clang compilation with libc but not linker.
Clang is still disabled for x86 and x86_64 long double code,
for x86_64 special assembly instruction, and the linker module.

BUG: 17163651
BUG: 17302991
BUG: 17403674
Change-Id: I43c5f5f0ddc0c2a31918f00b57150dadd8f3f26b
2014-09-05 11:18:35 -07:00
Dmitriy Ivanov
a3ad450a2e Load libraries in breadth-first order
This patch fixes the problem with symbol search order
  for dlsym(RTLD_DEFAULT/RTLD_NEXT, .) by loading libraries
  and ld_preloads in correct order.

Bug: https://code.google.com/p/android/issues/detail?id=74255
Change-Id: I4cf84c70dbaabe99310230dfda12385ae5401859
2014-09-03 15:06:14 -07:00
Dmitriy Ivanov
29bbc9dd4c Encapsulate soinfo_link_image and soinfo_relocate
Also get rid of needed[] array for these functions

Change-Id: I8d12887dbec0724309bb171e6bbd9b9ceb32cc70
2014-09-02 11:47:23 -07:00
Dmitriy Ivanov
e057b9fc82 Merge "Introduce size-based r/w allocators" 2014-09-02 17:21:51 +00:00
Dmitriy Ivanov
a492605849 Implement LinkedList::visit()
Change-Id: Ibd9d133dddf1f2e6e65660e3cd2dacafcc0c84d9
2014-09-02 09:45:40 -07:00
Dmitriy Ivanov
0cd83ebb0e Introduce size-based r/w allocators
Change-Id: I75165fc392e5380124039e6db49b0f559c8a518e
2014-09-01 16:17:05 -07:00
Dmitriy Ivanov
c2048944ff Look into ld_preloads before current library
Change lookup order during relocation so that
 ld_preloads always precede caller (unless caller
 is main executable).

 Asan needs this change in order to intercept libc->libc
 calls.

Bug: 15432753
(cherry picked from commit 05e190c093)

Change-Id: I5bfb58e18015b1ec5b77842dbb37fb122fa1fd1a
2014-09-01 14:14:09 -07:00
Dmitriy Ivanov
11387985d2 Merge "Erase elements in LinkedList::remove_if" 2014-09-01 21:06:32 +00:00
Dmitriy Ivanov
4bea498544 Erase elements in LinkedList::remove_if
Change-Id: I5119a78c73ffe780a81c53ab5ff0266d5c82d319
2014-08-29 17:09:24 -07:00
Dmitriy Ivanov
851135bf99 Replace NULL with nullptr
Change-Id: Iad50be617d318ca98883b843229c960ad5b9afa9
2014-08-29 14:13:48 -07:00
Christopher Ferris
052fa3a34c Replace snprintf calls in linker.
When enabling debug malloc, the snprintf calls in the linker fails to
update the buffer.

The problem is that snprintf makes a call to pthread_getspecific that
returns a valid pointer, but the data it points to is zero. This should
never happen and causes the snprintf to stop and do nothing.

Temporarily replace snprintf with a different implementation to work
around this issue.

Bug: 16874447
Bug: 17302493

(cherry pick from commit 172955a4e3)

Change-Id: Idca9d417978403d61debfd0434aaa82fd770f33b
2014-08-27 16:01:57 -07:00
Dmitriy Ivanov
608217e167 Remove unnecessary calls to LinkedList::clear()
Change-Id: I981d2700cb17322c634b751715543fd33ee49b7c
2014-08-26 15:56:31 -07:00
Dmitriy Ivanov
14241402de Enable __cxa_atexit && __cxa_finalize for linker
This allows adding destructors to classes used
 for global variables.

Change-Id: I5e1cd63fe3bf8f66de88cc4f7437cafb350f49b5
2014-08-26 15:44:18 -07:00
Dmitriy Ivanov
0d15094287 Bump soinfo version
This includes:
 1. Placing has_ifunc after fields with version = 0
 2. Switch to has_min_version(v) function.
 3. Minor soinfo initialization refactoring (placement new + ctor)

Change-Id: I1bf5fde4d930914012ce5f3ad5acb48217da9b2d
2014-08-22 13:29:18 -07:00
Dmitriy Ivanov
9598b8c415 Run constructors before resolving ifunc functions
Bug: 17177284
Change-Id: I5714b9bc2d1ca8f8711806bfb68da3d524213e99
2014-08-21 14:24:13 -07:00
Dmitriy Ivanov
02aa70589d Revert "Add support for protected local symbol lookup."
This reverts commit d97e9f546e.

Bug: 17107521
(cherry picked from commit 9419420919)

Change-Id: I1a6df946ac8075699e77d68ffa6ac4a21b88e4bf
2014-08-19 05:19:53 -07:00
Dmitriy Ivanov
ad5e8b5073 Keep symbols for linker
Bug: 17011146
Change-Id: I314e72a1ac9325bf5ea84d52e3d5bc51d8ea00cf
2014-08-14 15:46:36 -07:00
Dmitriy Ivanov
e942b3ed81 Merge "Added test for ifunc support in dynamic linker." 2014-08-12 19:23:43 +00:00
Dmitriy Ivanov
042426ba63 Optimize symbol lookup
Do not run symbol lookup on already visited soinfos
 Not taking into account already visited libraries
 dramatically slows down dlsym in cases when there
 are multiple occurrences of a large library in
 dependency tree.

Bug: 16977077
Change-Id: I1379f30ed8b06758dd1cc76b80833ac8589afa50
2014-08-13 09:21:57 -07:00
Dmitriy Ivanov
51a22a12ab Label pages mapped by linker_allocator
Change-Id: I7e0bf29bc1a480e9be0d1ae573ca1063d90d82ff
2014-08-11 09:22:48 -07:00
Brigid Smith
c5a13efa9b Added test for ifunc support in dynamic linker.
ifuncs now work in i386 and x86_64 when called in the same library as
well as in a different library.

Bug:6657325
Change-Id: Ic0c48b1b0a76cb90f36c20c79f68294cc3fd44a1
2014-08-08 11:29:35 -07:00
Dmitriy Ivanov
aa0f2bdbc2 Fix dlsym(3) to do breadth first search.
dlsym(3) with handle != RTLD_DEFAULT|RTLD_NEXT performs
  breadth first search through the dependency tree.

Bug: 16653281
Change-Id: I017a6975d1a62abb0218a7eb59ae4deba458e324
2014-07-29 14:35:13 -07:00
Dmitriy Ivanov
ed48534718 Fix mips/mips64 build
Add _start entry label to mips/mips64 linker begin.S

Change-Id: Idcdfc3391427b53880650798be0583a7ac022bcc
2014-07-28 21:03:17 -07:00
Dmitriy Ivanov
efe13832dc Fix 'adb shell /system/bin/linker' crash
Bug: https://code.google.com/p/android/issues/detail?id=63174
Change-Id: I072290ea11109c07f277ad3dec7f44fcb7bf6aa6
2014-07-28 16:29:52 -07:00
Dmitriy Ivanov
4151ea73b7 Fix global variable initialization for linker
Linker now calls init functions for itself.

Change-Id: Ibd099812493041ac70f591e3f379ee742b4683b8
2014-07-24 15:33:25 -07:00
Nick Kralevich
be0e43b776 debuggerd: if PR_GET_DUMPABLE=0, don't ask for dumping
PR_GET_DUMPABLE is used by an application to indicate whether or
not core dumps / PTRACE_ATTACH should work.

Security sensitive applications often set PR_SET_DUMPABLE to 0 to
disable core dumps, to avoid leaking sensitive memory to persistent
storage. Similarly, they also set PR_SET_DUMPABLE to zero to prevent
PTRACE_ATTACH from working, again to avoid leaking the contents
of sensitive memory.

Honor PR_GET_DUMPABLE when connecting to debuggerd. If an application
has said it doesn't want its memory dumped, then we shouldn't
ask debuggerd to dump memory on its behalf.

FORTIFY_SOURCE tests: Modify the fortify_source tests to set
PR_SET_DUMPABLE=0. This reduces the total runtime of
/data/nativetest/bionic-unit-tests/bionic-unit-tests32 from approx
53 seconds to 25 seconds. There's no need to connect to debuggerd
when running these tests.

Bug: 16513137
Change-Id: Idc7857b089f3545758f4d9b436b783d580fb653f
2014-07-23 15:48:49 -07:00
Elliott Hughes
3758a244cf Fix a couple of bugs in generate-NOTICE and regenerate the NOTICE files.
Change-Id: Id6fcb74292e661504d0758bfce24abdc18cb8d32
2014-07-22 21:29:00 -07:00