Commit Graph

511 Commits

Author SHA1 Message Date
Dmitriy Ivanov
f947be2889 Revert "Fix symbol lookup order during relocation"
This reverts commit 976402cca1.

Bug: 18222321
Bug: 18211780
Change-Id: Iafdd3d843db7b1cf288be9a0232022816622c944
2014-11-03 22:15:08 -08:00
Dmitriy Ivanov
976402cca1 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
Bug: 18186310

(cherry picked from commit d225a5e652)

Change-Id: I4e889cdf2dfbf8230b0790053d311ee6b0d0ee2d
2014-10-31 17:10:30 -07:00
Dmitriy Ivanov
bf3d5ef5fd Fix mips build
Bug: 18186310

(cherry picked from commit 90b74fb867)

Change-Id: I8d4ed254e5c421b65b62c401abdb1ee07e5dc3b2
2014-10-31 17:04:00 -07:00
Dmitriy Ivanov
6442dbd3bc Remove unnecessary lookups during relocations
local_group includes this library and its dependencies.

Bug: 18186310

(cherry picked from commit e47b3f8456)

Change-Id: I93c2d873e924df7319569307444bf603d7d27bf0
2014-10-31 17:04:00 -07:00
Dmitriy Ivanov
fd2747bb58 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
Bug: 18186310

(cherry picked from commit cfa97f172d)

Change-Id: I5fa8c673f929e4652c738912c7ae078d7ec286d2
2014-10-31 17:04:00 -07:00
Dmitriy Ivanov
e4bc6f026a Ignore DT_BIND_NOW (0x18)
Bug: 18186310
Bug: 17552334

(cherry picked from commit ea6eae182a)

Change-Id: I07d6f6fbb462fea329581d0da02f6d88be1c262f
2014-10-31 17:04:00 -07:00
Dmitriy Ivanov
1d3e81a9e7 Resolve "unused DT entry" warnings for x86_64
Bug: 18186310

(cherry picked from commit 513e29e16f)

Change-Id: I1e4c5af2cdc09dc978c7a78fcdcf8796c919751e
2014-10-31 17:04:00 -07:00
Dmitriy Ivanov
c87f65d2cd Add RTLD_NODELETE flag support
Bug: 18186310
Bug: https://code.google.com/p/android/issues/detail?id=64069

(cherry picked from commit 1b20dafdbe)

Change-Id: Ic02eec22a7c322ece65eb40730a3404f611526b1
2014-10-31 17:04:00 -07:00
Dmitriy Ivanov
210ff1b27b Fix mips build
Bug: 18186310

(cherry picked from commit ecf532fa1c)

Change-Id: Ia12f2fa28c8cd3204eb7d6b4c7d872f4e81fb8ef
2014-10-31 17:04:00 -07:00
Dmitriy Ivanov
0f47d9c1ce 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
Bug: 18186310

(cherry picked from commit 6cdeb5234d)

Change-Id: I7ffc7bc600798308a77ad949a644949b64250ae2
2014-10-31 17:03:59 -07:00
Dmitriy Ivanov
f90e21004e 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)

Bug: 18186310

(cherry picked from commit 96bc37f2e1)

Change-Id: Ie217be4f3305d877066e4cfe91975ae1c7768330
2014-10-31 17:03:59 -07:00
Elliott Hughes
748fbe5c41 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.

Bug: 18186310

(cherry picked from commit 0dc39f9952)

Change-Id: I3e84488fc246f6c28cbd82e96d0cd4343a12c28a
2014-10-31 17:03:21 -07:00
Dmitriy Ivanov
d5eb10875a Temporary disable DL_WARNs for unused DT_*
Bug: 17552334
Bug: 18186310

(cherry picked from commit 1b77423eff)

Change-Id: I8a9d05195a862bc287fff7156913606f0311b8bb
2014-10-31 17:02:14 -07:00
Dmitriy Ivanov
09608848ed Fix 64bit build
Bug: 18186310

(cherry picked from commit f240aa8089)

Change-Id: Id46f1f9be90a17a58fb44d3540095c8c685c9726
2014-10-31 17:02:14 -07:00
Dmitriy Ivanov
634a045c5c 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.

Bug: 18186310

(cherry picked from commit 4a6e9a835a)

Change-Id: Ib40095f0770d65628fc7abac5a471378de35ebe7
2014-10-31 17:02:14 -07:00
Dmitriy Ivanov
b364d95380 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."

Bug: 18186310

(cherry picked from commit 8f61d99183)

Change-Id: I37024799ac8d1837993c8ae78780a448bedd6539
2014-10-31 17:02:13 -07:00
Dmitriy Ivanov
c85e82dde5 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
Bug: 18186310

(cherry picked from commit e8ba50fe0d)

Change-Id: Idf6bbe2233fb2bfc0c88677e7d1fc518fb3f7a8b
2014-10-31 17:02:13 -07:00
Dmitriy Ivanov
926797a8a9 Reformatting
No functional changes.

Bug: 18186310

(cherry picked from commit 6abf624d12)]

Change-Id: I0acf52d8ee7fe2d4f44bc832cbe9fabe1782f03f
2014-10-31 17:02:13 -07:00
Dmitriy Ivanov
702ab5b37e Rename library_offset to library_fd_offset
replace lseek() and use pread() instead
 add test for library_fd_offset > file_size case

Bug: 17762003

(cherry picked from commit a6c1279098)

Change-Id: Ie117c745081ee33d07db5341115ff6c8e98b0dec
2014-10-22 16:35:04 +00:00
Dmitriy Ivanov
de01780f46 Add file_offset parameter to android_extinfo
Bug: 17762003

(cherry picked from commit 07e5bc152d)

Change-Id: I72d527831384ff5dde013a4c8dfe639fbec165f5
2014-10-21 13:52:49 -07:00
Ningsheng Jian
04f5f4100c 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

(cherry picked from commit e93be99da0)

Change-Id: I347792dab25c7b19c3fc690e03d20899ce1e26e0
2014-10-02 15:35:47 -07:00
Dmitriy Ivanov
1cd0c6777f L-MR1 specific fixes
Reset soinfo version to 0.
 Disable ifunc test for arm64 because of old toolchain
 in lmp-mr1-dev branch

 Note: this commit should be reverted in -plus-aosp branch.

Change-Id: I2d6d996d43bc35d5d4975c745779f43a988b31e6
2014-10-01 16:26:49 -07:00
Dmitriy Ivanov
7d971ec14b Fix unload of recursively linked library
Expanded test for recursive libs. Fixed bug with unnecessary
  soinfo_free of already loaded library.

(cherry picked from commit a6ac54a215)

Change-Id: I6907c723d9fbdf6b2777f3f236b1e29b0843edd6
2014-10-01 16:04:58 -07:00
Dmitriy Ivanov
f4cb631364 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

(cherry picked from commit 9aea164457)

Change-Id: Ie19d900fc203beb93faf8943b0d06d534a6de4ad
2014-10-01 16:04:31 -07:00
Dmitriy Ivanov
ef1306d777 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';

(cherry picked from commit d9ff722661)

Change-Id: If2573d080770e18b36b56106f2369f7bb682cd3c
2014-10-01 16:03:51 -07:00
Dmitriy Ivanov
ae69a9584b 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
Attempt: 2

(cherry picked from commit 14669a939d)

Change-Id: Id87540c96a2242220967b6fa5d84ddcd829e2b97
2014-10-01 16:01:28 -07:00
Dmitriy Ivanov
c0133a73b6 Revert "Load libraries in breadth-first order"
This reverts commit a3ad450a2e.

(cherry picked from commit 498eb18b82)

Change-Id: Iec7eab83d0c0ed1604e1e8ea3f9e9d0ce1d29680
2014-10-01 16:00:52 -07:00
Dmitriy Ivanov
8de1ddece0 Fix order of soinfo links (repairs libcxx tests).
(cherry picked from commit b2a30ee8d2)

Change-Id: I59c5333bc050cbbea14051cea9220be2f64ee383
2014-10-01 16:00:41 -07:00
Dmitriy Ivanov
59c12a6527 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

(cherry picked from commit a3ad450a2e)

Change-Id: I1125de10272c84e4f075cbc72859c1f6b3e89943
2014-10-01 16:00:29 -07:00
Chih-Hung Hsieh
81fe2b16dc 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

(cherry picked from commit b58db8b083)

Change-Id: I916c05056d37a9c287b0a5ae3b1a209d98c8f70e
2014-10-01 15:57:09 -07:00
Dmitriy Ivanov
7210c41fdc Encapsulate soinfo_link_image and soinfo_relocate
Also get rid of needed[] array for these functions

(cherry picked from commit 29bbc9dd4c)

Change-Id: Id208621f66afa2e02a6b3facacee7d874466d81b
2014-10-01 15:56:44 -07:00
Dmitriy Ivanov
4466bd72fb Implement LinkedList::visit()
(cherry picked from commit a492605849)

Change-Id: I59554be45c910bfe33494016595a5ade9daad230
2014-10-01 15:56:23 -07:00
Dmitriy Ivanov
ff01f6fcce Introduce size-based r/w allocators
(cherry picked from commit 0cd83ebb0e)

Change-Id: Ib037bd5313c9a78b6051482f14e789aa820b4dd1
2014-10-01 15:55:58 -07:00
Dmitriy Ivanov
4d01d08c29 Erase elements in LinkedList::remove_if
(cherry picked from commit 4bea498544)

Change-Id: I1ffe248bc2b7572f38fbd987e9c6db5ecbd4559d
2014-10-01 15:55:35 -07:00
Dmitriy Ivanov
cfad7ae934 Replace NULL with nullptr
(cherry picked from commit 851135bf99)

Change-Id: Ic4997907680db7472ef38ffb0f0ca66fff37b797
2014-10-01 15:54:26 -07:00
Dmitriy Ivanov
5dfe802d0d Remove unnecessary calls to LinkedList::clear()
(cherry picked from commit 608217e167)

Change-Id: I031359d79b2e77977ace197ef410e41539dc0ce6
2014-10-01 15:53:07 -07:00
Dmitriy Ivanov
93c3f4203c Enable __cxa_atexit && __cxa_finalize for linker
This allows adding destructors to classes used
 for global variables.

(cherry picked from commit 14241402de)

Change-Id: I1d8776130d1e01a8c53d23a2949f5010f4c96b16
2014-10-01 15:52:38 -07:00
Dmitriy Ivanov
3bbd218ef1 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)

(cherry picked from commit 0d15094287)

Change-Id: Idf135fdd3d4826b5653f32add2adc6db5d4a4f95
2014-10-01 15:52:15 -07:00
Dmitriy Ivanov
bd321c1106 Run constructors before resolving ifunc functions
Bug: 17177284

(cherry picked from commit 9598b8c415)

Change-Id: I2c9631ee1cd77f8cf95ec0216a35b605c8786454
2014-10-01 15:51:47 -07:00
Brigid Smith
31b88da843 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
(cherry picked from commit c5a13efa9b)

Change-Id: I321d780bc2f9bd1baa749e1acacd2683aefe827b
2014-10-01 15:50:38 -07:00
Dmitriy Ivanov
05e190c093 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
Change-Id: If69aa16efe59aa35bb30e96feb83d08f1efbec86
2014-08-29 11:46:06 -07:00
Christopher Ferris
172955a4e3 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
Change-Id: I7a500f28adf153150cf2812fae745ff41f1c48d3
2014-08-27 15:30:43 -07:00
Dmitriy Ivanov
9419420919 Revert "Add support for protected local symbol lookup."
This reverts commit d97e9f546e.

Bug: 17107521
Change-Id: I2b81ce2b5a4a2d166133a2626e49d81b6aef3672
2014-08-18 15:11:50 -07:00
Dmitriy Ivanov
be4348e7c7 Keep symbols for linker
Bug: 17011146

(cherry picked from commit ad5e8b5073)

Change-Id: Ib1d3f8d6d38af98586658e01ed1ec79d2c5b4d42
2014-08-15 14:18:26 -07:00
Dmitriy Ivanov
4bea4c631f Label pages mapped by linker_allocator
(cherry picked from commit 51a22a12ab)

Bug: 17013324
Change-Id: I345c9d0fecc29d3626c5be01cc3c0ed1583ac361
2014-08-13 18:15:29 -07:00
Dmitriy Ivanov
8a84d383fb 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

(cherry picked from commit 042426ba63)

Change-Id: I69d59e395e8112f119343e8a4d72fe31cd449f31
2014-08-13 09:30:52 -07:00
Dmitriy Ivanov
db7a17d4ff Revert "Revert "Fix dlsym(3) to do breadth first search.""
This reverts commit 1b1966d944.

Change-Id: I05d6d3481aaf8f3e260d2e5e950248519a1d347f
2014-08-04 23:39:22 +00:00
Dmitriy Ivanov
1b1966d944 Revert "Fix dlsym(3) to do breadth first search."
This reverts commit 422106a24d.

Change-Id: I9e26a6933d10eb30438b521450f2010997ca5aee
2014-08-04 16:38:57 +00:00
Dmitriy Ivanov
422106a24d 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

(cherry picked from commit aa0f2bdbc2)

Change-Id: I0ba8c2034ab341f8a279cdb4e2e7e47f1aef7897
2014-07-29 15:02:15 -07:00
Dmitriy Ivanov
1a5db57d5a Fix mips/mips64 build
Add _start entry label to mips/mips64 linker begin.S

(cherry picked from commit ed48534718)

Change-Id: Id1b6bb3258f3bfbe3b7ec9491a977f56e44bed14
2014-07-28 22:00:01 -07:00