Commit graph

312 commits

Author SHA1 Message Date
Dmitriy Ivanov
f33ad40023 Merge "Fix symbol lookup order during relocation" 2014-10-31 23:51:18 +00:00
Dmitriy Ivanov
da8e591c39 Use local copy of the library name on dlopen
Bug: 18052100
Change-Id: Idbc2a3691db3b5525d4e9bca81d78d5f29bc438f
2014-10-31 14:23:34 -07:00
Dmitriy Ivanov
d225a5e652 Fix symbol lookup order during relocation
Relocate symbol against DF_1_GLOBAL shared libraries
  loaded before this shared library. This includes
  main executable, ld_preloads and other libraries
  that have DF_1_GLOBAL flag set.

Bug: 2643900
Bug: 15432753
Change-Id: Ia788748be59b739d1c7e62b978e7e255f9e65c7b
2014-10-31 11:39:51 -07:00
Dmitriy Ivanov
c9d1658397 Remove unnecessary reinterpret_cast
Change-Id: Id2ddf4e74bc66825206d1287f899d716537a68d0
2014-10-24 14:46:12 -07:00
Dmitriy Ivanov
90b74fb867 Fix mips build
Change-Id: Ia2dc2e07740bdbb91ee92bfea459230015fcc99b
2014-10-23 14:34:12 -07:00
Dmitriy Ivanov
e47b3f8456 Remove unnecessary lookups during relocations
local_group includes this library and its dependencies.

Change-Id: Ib02474b2355bb147de3889f60092cb2f312997ef
2014-10-23 14:19:07 -07:00
Dmitriy Ivanov
cfa97f172d Fix relocation to look for symbols in local group
The local group is a sequence of libraries in default (breadth-first)
  order. It allows RTLD_LOCALLY loaded library to correctly relocate
  symbols within its group (see test-cases).

  Local group lookup is performed after main executable and ld_preloads.

Bug: 2643900
Bug: 15432753
Change-Id: I9bb013b46d17dbb5cbdfb8fef26f552748385541
2014-10-23 12:13:54 -07:00
Dmitriy Ivanov
a6c1279098 Rename library_offset to library_fd_offset
replace lseek() and use pread() instead
 add test for library_fd_offset > file_size case

Bug: 17762003
Change-Id: I4555f0be635124efe849c1f226985bcba72ffcbd
2014-10-21 13:51:08 -07:00
Dmitriy Ivanov
ea6eae182a Ignore DT_BIND_NOW (0x18)
Bug: 17552334
Change-Id: Ibe93fd3d6580f369f9a6ef8d235bf0df00fe7607
2014-10-15 22:57:14 +00:00
Dmitriy Ivanov
513e29e16f Resolve "unused DT entry" warnings for x86_64
Change-Id: I3a2c87bf6e6259313cd9203389623f13b7405ef3
2014-10-06 11:32:19 -07:00
Dmitriy Ivanov
07e5bc152d Add file_offset parameter to android_extinfo
Bug: 17762003
Change-Id: I8fb267a3155acef3dba534038cf5d1ef00d7154b
2014-10-06 10:02:34 -07:00
Dmitriy Ivanov
d5df4124bb Merge "Add RTLD_NODELETE flag support" 2014-10-02 21:47:29 +00:00
Dmitriy Ivanov
1b20dafdbe Add RTLD_NODELETE flag support
Bug: https://code.google.com/p/android/issues/detail?id=64069
Change-Id: Ie5f90482feae86391172be4b32d6cb7d76f446fb
2014-10-01 11:09:37 -07:00
Dmitriy Ivanov
ecf532fa1c Fix mips build
Change-Id: I4454e69a982f239b168678c5a681d1078b4bd4f1
2014-09-30 16:30:22 -07:00
Dmitriy Ivanov
6cdeb5234d Fix unused DT entry warnings.
DT_STRSZ Implement strtab boundary checks
 DT_FLAGS_1 Warn if flags other than DF_1_NOW|DF_1_GLOBAL are set

Bug: 17552334
Change-Id: Iaad29cd52f5b2d7d2f785fb351697906dc1617d9
2014-09-30 14:41:29 -07:00
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
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
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
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
Dmitriy Ivanov
b2a30ee8d2 Fix order of soinfo links (repairs libcxx tests).
Change-Id: Iee9de09657351cd6a7512784ca797e4b84cdd98b
2014-09-05 16:01:47 -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
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
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
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
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
Dmitriy Ivanov
3a8646fc5d Change android_dlextinfo flags to uint64_t
Change-Id: Id27e8f8e58dbcf6ae79644f2ad3af3dd0aef9ae7
2014-07-08 11:24:03 -07:00
Nick Kralevich
76e289c026 Revert "Reenable support for non-PIE executables"
/system/bin/tf_daemon on Nakasi has been updated so it's
a PIE executable. We can now drop non-PIE support.

This reverts commit d81b3b275d.

Bug: 15086752
Bug: 15732002
Bug: 14566672
Change-Id: I832c4de01a8fa050754ea64da317d1639990265e
2014-07-03 12:08:34 -07:00
Dmitriy Ivanov
d383066941 Build fix
Change-Id: Ib43e0f055e3c5f07b50393bfcab9738454835ac3
2014-07-02 16:06:50 -07:00
Dmitriy Ivanov
04dc91ae76 Load library using file handle.
* This patch enables dlopen by file descriptor
   instead of path/name.

Bug: 15984217
Change-Id: Ib39051e00567fb97070bf96d8ce63993877c0a01
2014-07-02 13:20:47 -07:00
Dmitriy Ivanov
12bf3bcdee Write message to stderr on __libc_fatal()
Change-Id: Ia8d6e256768fa51786d0139d3f3b6e9e4bebe027
2014-07-01 14:46:03 -07:00
Dmitriy Ivanov
d97e9f546e Add support for protected local symbol lookup.
Bug: http://code.google.com/p/android/issues/detail?id=66048
Change-Id: Ib334223df27adad9477fb241ab099c5e26df4a7d
2014-07-01 10:25:54 -07:00
Elliott Hughes
aa836f7310 Reinstate the x86 dynamic linker warning for text relocations.
Bug: 11358761
Change-Id: I4fc56ce7d76c9703a307ddd4d371d5e98bc6f51d
2014-06-30 14:46:53 -07:00
Dmitriy Ivanov
e43c4a7a66 Disallow dlopen("egl/blah.so") on LP64
Bug: 7465467
Change-Id: Ibd3a4f1a6095f4397bde4f656e3c11b67f7edd47
2014-06-29 13:02:06 -07:00
Nick Kralevich
d81b3b275d Reenable support for non-PIE executables
On Nakasi builds, /system/bin/tf_daemon is a pre-compiled
vendor supplied binary. When support for non-PIE executables
was removed, that daemon failed to start, which induced
a number of bugs.

  * keystore is broken
  * CTS runs will hang after a certain period of time

Temporarily reenable non-PIE support for 32-bit platforms
until Nakasi is fixed.

This rolls back the following commits:

  Cleanup: updated comments
  * 6275f20834
  Cleanup: remove AARCH/ARM_COPY relocation support
  * b906e13c55

And restricts the following patch to 64 bit only:

  Remove support for non-PIE executables
  * 2aebf5429b

Bug: 14566672
Bug: 15086752
Bug: 15732002
Change-Id: Ia2501aa14bd30feb4a6ce66bdb7c9f066dba0b5f
2014-06-19 09:09:54 -07:00
Elliott Hughes
1a58629340 Remove an unused parameter from the dlopen implementation.
Change-Id: I9297913a743bb570b48ebbe594ff711a481e89e0
2014-06-03 16:23:08 -07:00
Elliott Hughes
d286796fce Turn on -Wunused and fix the mistakes it uncovers.
Change-Id: I023d2d8b547fbc21d4124bb7510d42b06a0dc501
2014-06-03 15:22:34 -07:00
Dmitriy Ivanov
ce00354fec Merge "Do not add arcs to the soinfo graph on dlopen" 2014-05-23 02:19:10 +00:00
Bjorn Andersson
3c005d6019 Do not add arcs to the soinfo graph on dlopen
While introducing RTLD_NOLOAD in b648a8a5 a change in how soinfo structs are
connected was also introduced. When calling dlopen the library that is loaded
is added as a child to the soinfo from which the caller comes - i.e. building a
dependency graph.

Unfortunately this shows issues upon unloading, such as blowing the stack if
there are loops in the graph.

This change reverts that part of b648a8a5, keeping everything as a child of the
root soinfo.

Change-Id: I604ee9210613b19f693a568158e69707620a95db
Signed-off-by: Bjorn Andersson <bjorn.andersson@sonymobile.com>
2014-05-22 19:08:14 -07:00
Elliott Hughes
2ea60ff0b4 Remove unnecessary #includes of <sys/atomics.h>.
Bug: 14903517
Change-Id: I7b5bcebe58774a441da986cc02376dd88e00ea0e
2014-05-22 11:00:21 -07:00
Dmitriy Ivanov
f092feb81b Merge "Add R_X86_64_64 to the list of possible weak relocs" 2014-05-20 19:11:25 +00:00
Dmitriy Ivanov
b648a8a57e Add RTLD_NOLOAD support and some related changes.
* Aligned RTLD_ values with glibc for lp64
 * dlopen supports RTLD_NOLOAD flag
 * soinfo_unload calls find_library(.., RTLD_NOLOAD)
   instead of naive find_loaded_library_by_name()
 * dlopen changed to add child to caller soinfo instead
   of somain.

Bug: https://code.google.com/p/android/issues/detail?id=64069
Change-Id: I1a65f2c34f3e0edc6d2c41a2e408b58195feb640
2014-05-20 12:02:24 -07:00
Pavel Chupin
bb5bb2046f Add R_X86_64_64 to the list of possible weak relocs
Change-Id: I768a5948d89701a1719734954a3524d3c7187e6a
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
2014-05-20 16:53:33 +04:00
Dmitriy Ivanov
489e498434 Fix lookup-by-base-name for lp64
Bug:https://code.google.com/p/android/issues/detail?id=6670
Change-Id: I5b70e7cde7f40799148aca0a91fb2bb08e0f2b54
2014-05-19 19:15:06 -07:00
Dmitriy Ivanov
d59e50063a Improve detection of already loaded libraries
Linker is now able to resolve symlinked libraries correctly.

soinfo is extended to save the graph of dependencies during
load/unload. Dependencies are used only in CallConstructor.

Bug: 9741592
Change-Id: Id9c48a74c46aa89bcdf3d54ec2f8ba3d398130b1
2014-05-14 15:16:35 -07:00
Elliott Hughes
1728b23965 Switch to g_ for globals.
That's what the Google style guide recommends, and we're starting
to get a mix.

Change-Id: Ib0c53a890bb5deed5c679e887541a715faea91fc
2014-05-14 10:02:03 -07:00
Dmitriy Ivanov
d44927b8e9 Merge "Refactor linker allocator" 2014-05-13 15:49:18 +00:00
Dmitriy Ivanov
d597d263bc Refactor linker allocator
Makes it reusable for different fixed sized and not very
big structures (<PAGE_SIZE).

Change-Id: Id5ec13fc6541b1935ef7fe3671c22b98685abbae
2014-05-12 21:40:09 -07:00
Dmitriy Ivanov
6275f20834 Cleanup: updated comments
Bug: 14566672
Change-Id: I49ad28e3914b7d559db1e98542fee919db768f49
2014-05-12 11:47:10 -07:00
Dmitriy Ivanov
b906e13c55 Cleanup: remove AARCH/ARM_COPY relocation support
They are only legal for ET_EXEC binaries and these are no
longer supported.

Bug: 14566672
Change-Id: I99e0ff47e8c572db474bc5e52df870a72269abb3
2014-05-12 09:06:14 -07:00
Nick Kralevich
2aebf5429b Remove support for non-PIE executables
Don't support the dynamic linker loading ET_EXEC executables. Only
support ET_DYN executables.

Bug: 14566672
Change-Id: Ia1f2bfffe7ea867c1cd62e67d7fd637c60c0728d
2014-05-08 13:17:17 -07:00
Dmitriy Ivanov
5ca7ed9005 Disallow dlopen("egl/blah.so") on LP64
Change-Id: I9a563a9dada6522129b1890bc1292667230e80a5
2014-05-02 18:18:50 -07:00
Torne (Richard Coles)
0dcf06f976 Fix arm64/x86 build.
Add missing second param to soinfo_link_image in a section that's not
compiled on ARM.

Bug: 13005501
Change-Id: Id0ede8e03da4e05b25c0aeb24a840f868031d4e8
2014-04-22 11:59:26 +01:00
Torne (Richard Coles)
b1bfa7956c Merge "Allow sharing the RELRO section via a file." 2014-04-22 10:39:49 +00:00
Torne (Richard Coles)
c363e5dd0a Merge "Support loading libraries to a reserved address." 2014-04-22 10:33:34 +00:00
Torne (Richard Coles)
16f6429c38 Merge "Add android_dlopen_ext() interface to linker." 2014-04-22 10:33:07 +00:00
Du Chenyang
865119efd4 Temporarily disable text relocation warnings for x86 libraries
Too many such warnings will cause CTS failed. This issue still exists
in some x86 version libraries: libdvm.so/libart.so.

$scanelf -qT out/target/product/generic_x86/system/lib/libdvm.so
  libdvm.so: (memory/data?) [0x2BAC7] in (optimized out: previous dvmAsmInstructionStartCode) [0x2B2F8]
  libdvm.so: (memory/data?) [0x2BB98] in (optimized out: previous dvmAsmInstructionStartCode) [0x2B2F8]
  libdvm.so: (memory/data?) [0x2EB28] in (optimized out: previous dvmAsmInstructionStartCode) [0x2B2F8]
  libdvm.so: (memory/data?) [0x2EF87] in (optimized out: previous dvmAsmInstructionEndCode) [0x2EF63]
  libdvm.so: (memory/data?) [0x2EFAF] in (optimized out: previous dvmAsmInstructionEndCode) [0x2EF63]
  libdvm.so: (memory/data?) [0x2EFD7] in (optimized out: previous dvmAsmInstructionEndCode) [0x2EF63]
  libdvm.so: (memory/data?) [0x2EFFF] in (optimized out: previous dvmAsmInstructionEndCode) [0x2EF63]
  libdvm.so: (memory/data?) [0x2F027] in (optimized out: previous dvmAsmInstructionEndCode) [0x2EF63]

Bug: https://code.google.com/p/android/issues/detail?id=68431
Change-Id: I11ecac282f1163e49a82156fce2a76cc2d619960
2014-04-18 16:00:55 -07:00
Torne (Richard Coles)
183ad9df53 Allow sharing the RELRO section via a file.
Add flags and a file descriptor to android_dlopen_ext() to allow writing
the RELRO section of the loaded library to a file after relocation
processing, and to allow mapping identical pages from the file over the
top of relocated memory in another process. Explicitly comparing the
pages is required in case a page contains a reference to a symbol
defined in another library loaded at a random base address.

Bug: 13005501
Change-Id: Ibb5b2d384edfaa5acf3e97a5f8b6115c10497a1e
2014-04-17 14:30:46 +01:00
Torne (Richard Coles)
12bbb91645 Support loading libraries to a reserved address.
Add flags and parameters to android_dlopen_ext() to allow loading a
library at an already-reserved fixed address. If the library to be
loaded will not fit within the space reserved, then the linker will
either fail, or allocate its own address space as usual, according to
which flag has been specified. This behaviour only applies to the
specific library requested; any other libraries loaded as dependencies
will be loaded in the normal fashion.

There is a new gtest included to cover the functionality added.

Bug: 13005501
Change-Id: I5d1810375b20fc51ba6a9b3191a25f9792c687f1
2014-04-17 14:22:17 +01:00
Torne (Richard Coles)
012cb4583a Add android_dlopen_ext() interface to linker.
Add a function "android_dlopen_ext()", defined in <android/dlext.h>.
This is an extended version of dlopen() which takes a struct for passing
additional parameters for Android-specific functionality. This will be
used to support RELRO section sharing between separate processes.

Bug: 13005501
Change-Id: I9c99b2f2a02ee329dedaeba09ef3a1113b17b2d6
2014-04-17 13:50:55 +01:00
Kito Cheng
812fd4263a Use __unused instead of UNUSED in linker.cpp
- sys/cdefs.h already define __unused, just use it
   instead of define a local one.

Change-Id: Iacf3da9193e65e1f34b12760b28bcb64b67cb790
2014-03-25 22:54:19 +08:00
Benjamin Adolphi
006f9ad891 Linker writes to wrong memory location when processing DT_MIPS_RLD_MAP
When bionic's dynamic linker processes the .dynamic section of a MIPS ELF binary and encounters the DT_MIPS_RLD_MAP dynamic array tag, it calculates the address of where to write a pointer to the _r_debug structure. The current implementation simply reads the value given in the d_ptr field and writes the pointer address to that location. However, this value has to be adjusted to reflect the real load address of the binary. Otherwise the linker will write to a faulty location possibly resulting in a crash when linking a MIPS binary that includes DT_MIPS_RLD_MAP. This change corrects that problem.

Change-Id: I1a91874f7ab47289001fe72d9016660c14c70362
Signed-off-by: Benjamin Adolphi <b.adolphi@gmail.com>
2014-02-19 00:50:32 +01:00
Elliott Hughes
c62b8a4d3f Remove unused variables not spotted by GCC.
Change-Id: I49a16096bc0f41f3ad0007249161e8bdfcf3438c
2014-02-12 17:17:41 -08:00
Elliott Hughes
faf05bacd4 Clean up all the lint cpplint can find in the dynamic linker.
Change-Id: Ic9ee7153817c22a252cc4b309283e355b623cab9
2014-02-11 17:33:49 -08:00
Chris Dearman
9918665a45 [MIPS64] Dynamic linker
Change-Id: I937c7c776cae3d66e214798d5217a922cd106bfc
Signed-off-by: Chris Dearman <chris.dearman@imgtec.com>
Signed-off-by: Duane Sand <duane.sand@imgtec.com>
2014-02-11 15:33:14 -08:00
Elliott Hughes
0266ae5f88 Switch <elf.h> over to linux uapi under the covers.
Remove the linker's reliance on BSD cruft and use the glibc-style
ElfW macro. (Other code too, but the linker contains the majority
of the code that needs to work for Elf32 and Elf64.)

All platforms need dl_iterate_phdr_static, so it doesn't make sense
to have that part of the per-architecture configuration.

Bug: 12476126
Change-Id: I1d7f918f1303a392794a6cd8b3512ff56bd6e487
2014-02-10 18:22:24 -08:00
Elliott Hughes
3a9c5d66dc Fix <link.h>.
Also move some of the stuff that should be in <link.h> out of the
private "linker.h", to make it clearer that these are public API
known to gdb that we can't change.

Bug: 12554197
Change-Id: I830e1260d3d8b833ed99bc1518f1c6b6102be8af
2014-02-10 13:31:13 -08:00
Weiwu Chen
5ceb889ac9 bionic: Change the type of soinfo's size to size_t
Some system functions like munmap expect soinfo's size to be size_t, but currently
it is unsigned. Change it to size_t to fit 64bit's portability.

Change-Id: I0bf6d522b38b0cd9bf1db05b004b5326217412a2
Signed-off-by: Weiwu Chen <weiwu.chen@intel.com>
Signed-off-by: Qiming Shi <qiming.shi@intel.com>
2014-01-28 11:54:01 -08:00
Elliott Hughes
a4aafd1560 Make it possible for code to query the dynamic linker's default search path.
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
2014-01-13 16:37:47 -08:00
Elliott Hughes
b93702a046 Improve dynamic linker diagnostics for internal errors.
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-22 19:38:42 +00:00
Marcus Oakland
e365f9d654 AArch64: Linker64 support for AArch64
Addition of support for AArch64 in the linker64 target.

Change-Id: I8dfd9711278f6706063e91f626b6007ea7a3dd6e
Signed-off-by: Marcus Oakland <marcus.oakland@arm.com>
2013-12-17 15:02:43 -08:00
Pavel Chupin
5407eed84b Fix debugging issues in vdso handling
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-12-12 11:18:46 -08:00
Sergey Melnikov
ebd506c69e Fix linker crashes during unknown symbol lookup
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-31 15:06:20 -07:00
Elliott Hughes
e4d792adb8 Don't allow text relocations on 64-bit.
I've also updated our <sys/exec_elf.h> to match upstream.

Change-Id: I52f9fce3167541811208d273ff23ceaa112f7135
2013-10-28 14:34:56 -07:00
Elliott Hughes
4eeb1f12a8 Clean up linker architecture macros.
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-28 11:02:49 -07:00
Elliott Hughes
b8b0b6b412 Revert "Don't warn about x86 text relocations. They're too prevalent."
This reverts commit 5be2c5998c.

Change-Id: I3fc8ca530cdbd74c834fb9cfabe812c9386419fc
2013-10-24 22:58:28 +00:00
Elliott Hughes
5be2c5998c Don't warn about x86 text relocations. They're too prevalent.
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-23 13:45:01 -07:00
Nick Kralevich
3d4470c14a change wording on text relocation message.
The current message is too alarmist.

Change-Id: I53e8eadca239f867b4e6b9c193eba96e267950c3
2013-10-22 12:06:36 -07:00
Pavel Chupin
c075c18537 x86_64: Add R_X86_64_64 relocation handling
Change-Id: I86ffc56fa6a9053bed44e92a579530c2beb8eb2c
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
2013-10-16 19:13:58 +04:00
Pavel Chupin
1a57f9f75c x86_64: Rename 64-bit linker to linker64
That's for having both on the same system.

Change-Id: Ic2bc2c015e6486e8b6a7576f7b28d2d027534368
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
2013-10-09 16:50:30 -07:00
Elliott Hughes
eb847bc866 Fix x86_64 build, clean up intermediate libraries.
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-09 16:00:17 -07:00
Elliott Hughes
011bc0ba45 Use /system/lib64 and /vendor/lib64 for 64-bit libraries.
Change-Id: I4886aeb3070bf97b4cfe8053388ecb1bda288017
2013-10-08 14:27:10 -07:00
Elliott Hughes
c00f2cb587 x86_64 linker.
Based on I8dc3e2cb596f75dc58ae82e4dc58f8c177dd3323 by
Pavel Chupin <pavel.v.chupin@intel.com>.

Change-Id: Icd582d277cbe273477b450f2848343d72c86ec9f
2013-10-08 09:57:01 -07:00
Elliott Hughes
c620059479 Remove 32-bit assumptions from the ELF code.
Change-Id: I2c1f3d34c33685799aade8866eec44479ff9f963
2013-09-30 18:43:46 -07:00
Christopher Ferris
24053a461e Add the dl_iterate_phdr function to libdl for arm.
Bug: 8410085

Merge from internal master.

(cherry-picked from cb491bc66d)

Change-Id: I94ed51bc5d4c626df7552c0e85c31ccee2d6568f
2013-09-06 09:53:54 -07:00
Brian Carlstrom
87c358524e Make mips_relocate_got tolerate a missing got
Bug: 10094803

(cherry picked from commit 7ee26878065abb494600595349ce58b2b2db3709)

Change-Id: Ib15bccecaee421dc463d46a3956b054051708759
2013-08-21 10:20:13 -07:00
Sergey Melnikov
c45087bffa Kernel dso support for 'dl_iterate_phdr' function
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-25 13:12:39 -07:00
Nick Kralevich
c9084427aa linker: Emit a warning on text relocations
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-21 15:33:15 -07:00
Elliott Hughes
7e5a8cc523 Make LD_PRELOAD failures just warnings.
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-18 13:15:00 -07:00
Christopher Ferris
6bec5b792a Small cleanup of soinfo_elf_lookup.
- Remove unnecessary line.
- Move declarations to first use.

Change-Id: I1d8398d6c13f7cb86bffe0b68af849e35a4b234d
2013-06-03 20:15:14 -07:00
Elliott Hughes
8147d3c284 Don't fail to run DT_INIT and DT_INIT_ARRAY constructors if a shared library 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-05-09 15:29:54 -07:00
Nick Kralevich
8d3e91d4f8 linker: only re-open std* for setuid programs.
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-25 13:15:24 -07:00
Elliott Hughes
0d787c1fa1 Make abort messages available to debuggerd.
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-04-05 11:24:19 -07:00
Kito Cheng
8f7120bbac Drop unnecessary execution permission for .cpp/.c/.h
Change-Id: I9ac2b9d8f6bdb4fab8962210c5ec8f9c3e8c0ebf
2013-03-22 10:28:15 +08:00
Elliott Hughes
8f2a5a0b40 Clean up internal libc logging.
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-15 16:12:58 -07:00
Elliott Hughes
ca0c11bd82 Use more types than just 'unsigned' in the linker.
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-12 11:26:56 -07:00
Kito Cheng
fa8c05dc00 Use Elf32_Addr instead of unsigned in linker
Change-Id: I52dcbb4b0ff0a4052e0ad7a9bbeb2df65c9d2f66
2013-03-12 10:19:14 -07:00
Brian Carlstrom
2d4b9b7cff Fix typo of DT_NEEDED for DT_NULL
(cherry-pick of 138b205ea9efc117fe522c2d7191378023a6e2cd)

Change-Id: Ia895cb3018df55554627f1f61dcdfdada4a961ce
2013-03-06 15:50:30 -08:00
Kito Cheng
5e2492eb89 Fix TIMING/STATS/COUNT_PAGES dynamic linker build
Change-Id: I6432ac378816da253b83d1c7fb1d3fb64647b89e
2013-03-06 23:58:48 +08:00
Brian Carlstrom
43cc7f795b Fix MIPS linker build
(cherry-picked from 8c7d8c2057e303985f78eab96da747ddaa013c78)

Change-Id: Idcf62ab95f8fccbc2d7c3e771a4cfbe768a1555e
2013-03-06 01:05:08 -08:00
Elliott Hughes
650be4e584 More linker cleanup.
Change-Id: I9fb3c7c0d4b4ffef0eeaf092d4e30ffe63a08671
2013-03-05 22:24:34 -08:00
Brian Carlstrom
d4ee82dfa3 Minor linker cleanup, primarily to use Elf32_Dyn
Change-Id: Ifa9408e9859c6f79444715bed4808b7c13fdced5
2013-03-05 15:27:21 -08:00
Elliott Hughes
d3920b3a99 Switch to using AT_RANDOM for the stack guards.
Bug: 7959813
Change-Id: I8db4b8912ba649bfe668c6f22aa44690ddd401a2
2013-02-08 11:16:13 -08:00
Elliott Hughes
42b2c6a5ee Clean up the argc/argv/envp/auxv handling.
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-07 11:44:21 -08:00
Elliott Hughes
d2b1a7311f Remove partial implementation of MIPS non-PIC support.
Change-Id: I3c287e52aae10559508174e73113367aea40e5c2
2013-02-06 11:02:28 -08:00
Elliott Hughes
1e980b6bc8 Fix the duplication in the debugging code.
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-18 22:20:06 -08:00
Nick Kralevich
36bd371e26 Revert "stack protector: use AT_RANDOM"
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 e3a49a8661.

Change-Id: I05c58a896b1fe32cfb5d95d43b096045cda0aa4a
2013-01-16 13:16:42 -08:00
Nick Kralevich
e3a49a8661 stack protector: use AT_RANDOM
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-16 10:09:52 -08:00
Elliott Hughes
99c32055cb Fix my git mistake.
This was the formatting change that was supposed to be in
cf23905a4b.

Change-Id: Ib79fa031b68f6f541f532507eb589afeaedb831f
2013-01-14 09:56:21 -08:00
Chris Dearman
cf23905a4b [MIPS] Set DT_DEBUG dyntab entry if it is writable
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-14 09:30:25 -08:00
Elliott Hughes
db492b3ca7 Fix debug malloc.
...which has been broken since the linker data structures went read-only.

Bug: 7941716
Change-Id: If28f6bac0fcb13e371e4d85b064544f561c8d692
2013-01-03 15:44:03 -08:00
Elliott Hughes
cade4c36e7 Support System.loadLibrary for libraries with transitive dependencies.
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-20 14:42:14 -08:00
Elliott Hughes
e66190d2a9 Check for unknown flags passed to dlopen(3).
Change-Id: I56f4aab0e5a1487bc32d2c4d231e8bd15c4ac8da
2012-12-18 15:57:55 -08:00
Chris Dearman
20a24403bc Do not include '\0' when writing error messages to stderr
Change-Id: I6adc806c3920e5a4ae61ca55c40613fcf338b18c
Signed-off-by: Chris Dearman <chris@mips.com>
2012-11-26 15:43:17 -08:00
Chao-Ying Fu
c5db969aa4 We should use load_bias. This patch fixes MIPS NDK device exception test failures.
Change-Id: I4b718c36666e66062c1f13e4deea1ec7a7951c54
2012-11-19 10:30:15 -08:00
Elliott Hughes
9c94fc9fbe Tone down some of the overly-verbose linker logging.
We don't need to see every dlopen(3)/dlsym(3) failure unless LD_DEBUG is on.

Change-Id: I1edfe8b72f32ff54dd30e1acf32e20d470d5e9f7
2012-11-05 09:11:43 -08:00
Elliott Hughes
61a9ccb41e Make dynamic linker debugging always available.
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-02 13:46:23 -07:00
Elliott Hughes
ed537239a9 Merge "Adjust symbol lookup for DT_SYMBOLIC case" 2012-11-02 11:25:49 -07:00
Pavel Chupin
c77c434149 Adjust symbol lookup for DT_SYMBOLIC case
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-02 18:34:22 +04:00
Elliott Hughes
6971fe4ca5 Allow dlopen("egl/blah.so").
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-01 22:59:19 -07:00
Elliott Hughes
d23736e4f2 Keep the dynamic linker's soinfo pools mostly read-only.
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-01 16:48:14 -07:00
Elliott Hughes
1a6961650c Stop defining our own PAGE_SIZE and PAGE_MASK, and test dlclose(3) too.
Also remove an unnecessary #include and a now-obsolete TODO.

Change-Id: I36d923721e349a286934b9534090a67ce0786e7b
2012-11-01 13:53:26 -07:00
Magnus Malmborn
ba98d9237b Dynamically allocate soinfo-structs in linker
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-11-01 11:31:39 -07:00
Elliott Hughes
124fae9eab Reject .so files with no sysv hash table.
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-31 14:30:50 -07:00
Ard Biesheuvel
5ae44f302b linker: handle R_ARM_COPY relocations in a proper way
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-30 17:09:21 -07:00
Elliott Hughes
18a206c81d More dynamic linker cleanup.
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-30 16:35:38 -07:00
Elliott Hughes
5419b94747 Make dlerror(3) thread-safe.
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-16 17:58:17 -07:00
Elliott Hughes
3b297c4079 Fix dlerror(3).
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-10-11 16:08:51 -07:00
Xiaokang Qin
9c3449ecd9 bionic: linker: Need update the map->l_addr for execution.
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-09-13 18:09:20 +08:00
Elliott Hughes
e9b6fc6f82 Improve the dynamic linker diagnostics.
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-29 13:10:54 -07:00
Nick Kralevich
d39c3abd5a linker: Fix ARM_R_COPY relocations
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-28 11:48:32 -07:00
Elliott Hughes
bedfe38b8b More cleanup.
Make more stuff static, remove some dead code, and fix a few typos.

Change-Id: I010b0eadeaf61e2899c37014ad1e7082c70bd510
2012-08-14 14:07:59 -07:00
Ard Biesheuvel
12c78bbded linker: avoid clobbering the .dynamic section of shared libs
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-14 19:38:28 +02:00
Evgeniy Stepanov
9181a5dcfe Fix module constructor order.
.preinit_array goes before the constructors of LD_PRELOAD-ed libraries.

Change-Id: I1af32ce29eaf3ca4351ae8a0f7f5da5165853216
2012-08-13 11:05:47 -07:00
Nick Kralevich
5135b3ae6e linker: don't perform unnecessary mprotects
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-13 08:50:11 -07:00
Ben Cheng
06f0e74a2b Set the dynamic field in the link map for the linker itself.
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-10 16:07:02 -07:00
Elliott Hughes
4688279db5 Clean up the linker a bit, remove prelinking support.
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
2012-08-07 11:41:10 -07:00
Renamed from linker/linker.c (Browse further)