Commit graph

578 commits

Author SHA1 Message Date
Dmitriy Ivanov
d165f56fb6 Replace fixed arrays with vectors
This effectively removes limit on length and count
  of LD_LIBRARY_PATH and LD_PRELOAD entries.

Change-Id: Ie7ea34a50d99c4018f9dd1a33aaebc4049a7f424
2015-03-24 16:55:52 -07:00
Dmitriy Ivanov
e631f91a01 Limit soinfo compatibility fields to arm32
Change-Id: I3924cd68397c223c0d206295d587f9dd8ebdc086
2015-03-19 17:50:29 -07:00
Dmitriy Ivanov
618f1a36f8 Implement lookup by DT_SONAME
This CL also fixes SEARCH_NAME hack and resolves
  https://code.google.com/p/android/issues/detail?id=6670
  once and for all.

Bug: https://code.google.com/p/android/issues/detail?id=6670
Change-Id: I9b8d6a672cd722f30fbfbb40cdee8d9b39cfe56e
2015-03-18 18:14:30 -07:00
Dmitriy Ivanov
e44fffd7f9 Fix library lookup for filenames with slash.
If filename contains a slash, then it is interpreted
  as a (relative or absolute) pathname.

Bug: https://code.google.com/p/android/issues/detail?id=6670
Change-Id: Iba57d638301f3089ad47ba083edca2dd36b801ed
2015-03-18 10:32:11 -07:00
Simon Baldwin
aef719510a Support loading shared libraries from zip files
Add code to support loading shared libraries directly from within
APK files.

Extends the linker's handling of LD_LIBRARY_PATH, DT_RUNPATH, etc
to allow elements to be either directories as normal, or ZIP
format files.  For ZIP, the ZIP subdirectory string is separated
from the path to file by '!'.

For example, if DT_NEEDED is libchrome.so and Chrome.apk is the
Android ARM APK then the path element

  /system/app/Chrome.apk!lib/armeabi-v7a

would cause the linker to load lib/armeabi-v7a/libchrome.so
directly from inside Chrome.apk.  For loading to succeed,
libchrome.so must be 'stored' and not compressed in Chrome.apk,
and must be page aligned within the file.

Motivation:
  Chromium tracking issue:
  https://code.google.com/p/chromium/issues/detail?id=390618

Bug: 8076853
Change-Id: Ic49046600b1417eae3ee8f37ee98c8ac1ecc19e7
2015-03-16 17:50:50 -07:00
Dmitriy Ivanov
19656ce537 General purpose memory allocator for linker.
Add basic general purpose memory allocator to
 linker in order to enable usage of other libraries
 like libziparchive.

Change-Id: I4a680ebb36ed5ba67c61249f81dba9f567808434
2015-03-16 11:19:53 -07:00
Dmitriy Ivanov
600bc3cb93 Rename LinkerAllocator and LinkerAllocatorPage
Change-Id: I87d80fbcd4ec26c0ee4f601b9c4c64f600418dd9
2015-03-10 15:43:50 -07:00
Dmitriy Ivanov
c9ce70d783 Refactoring: rename linker_allocator files
Change-Id: Ifc08e64b3a85205f072b7abab1149c7ab71e2f75
2015-03-10 15:30:26 -07:00
Dmitriy Ivanov
3597b8055d Store fields for gnu_hash separately
Kindle app relies on soinfo's sysv hash
  fields while linking native libraries.

  This change allows to keep sysv hash fields
  intact for the libraries linked with --hash-style=both.

Bug: 19059885
Change-Id: I12528652955638f1a6586bda99e111bb1c8aa7a3
2015-03-09 21:01:01 +00:00
Nick Kralevich
6bb01b6e63 linker: Allow an app to update it's own LD_LIBRARY_PATH
When the kernel executes a program which is setuid, setgid, has
file capabilities, or causes an SELinux domain transition, the
AT_SECURE flag is set. This flag instructs the dynamic linker to
prune any dangerous environment variables passed across security
boundaries.

For SELinux in particular, whether this flag is set depends on the
the "noatsecure" process permission. If that permission does not
exist, then AT_SECURE=1 whenever a domain transition occurs.

In https://android-review.googlesource.com/129971 , Android stopped
using noatsecure when executing init services. In
https://android-review.googlesource.com/130610 , init was flipped
back into SELinux enforcing mode, making ag/129971 active. The
combination of those two changes ensured that AT_SECURE=1 was
set when executing init spawned services.

In particular, AT_SECURE=1 is set when init executes zygote. Due to
the forking nature of zygote, AT_SECURE remains untouched when
executing zygote's children.

This causes problems for the code added in
https://android-review.googlesource.com/48409 . Specifically, if
AT_SECURE=1, an attempt to call android_update_LD_LIBRARY_PATH()
is silently ignored. This causes problems when art tries to adjust
the LD_LIBRARY_PATH for Android apps. Ultimately, apps are unable
to find shared libraries they depend on.

As discussed in bug 7896159, there's no security reason for
preventing an application from updating it's own LD_LIBRARY_PATH.
We only need to prune LD_LIBRARY_PATH when transitioning across
security boundaries, but not when we're entirely within a security
boundary.

Remove the AT_SECURE check within do_android_update_LD_LIBRARY_PATH().
It's unneeded and prevents an application from modifying it's own
LD_LIBRARY_PATH. This allows an application to specify a location
where it's dlopen()ed shared libraries should be loaded from.

There is no change to AT_SECURE handling in
__sanitize_environment_variables(). We continue to honor it there
to prevent using security sensitive environment variables across
an exec boundary.

Bug: 19559835
Change-Id: If4af2ee8e84265aaa0c93de8b281208b20d7942a
2015-03-07 13:37:05 -08:00
Dmitriy Ivanov
18a6956b76 Add support for packed relocations.
Change-Id: I796a4ce86d3fccb8361c19889419c96147ee3c9f
2015-03-06 17:12:47 -08:00
Dmitriy Ivanov
fa26eee776 Refactoring: introduce reloc_iterators
Replace rel/rela array with reloc_iterators.

Change-Id: I6165d062e0390b6bc60da2e8279aabbedf828ec9
2015-03-06 13:01:08 -08:00
Dmitriy Ivanov
c6292ea39c Fix: DT_DEBUG was acting as DT_REL on mips64
Change-Id: I88827aa07d75d06d606c987e6270fcca3ae6216f
2015-02-13 16:34:50 -08:00
Dimitry Ivanov
8e5f9bc8a4 Merge "linker: Use load_bias to adjust search address in elf_addr_lookup" 2015-02-05 02:23:34 +00:00
Chris Dearman
8e55381939 linker: Use load_bias to adjust search address in elf_addr_lookup
load_bias is the delta between a symbols address in memory and the value
contained in the symbol table.

Change-Id: I35c87b69025b64f7e4a1418ca766618f4533fb3e
2015-02-04 17:16:27 -08:00
Elliott Hughes
05fc1d7050 Add missing includes.
Change-Id: Ibf549266a19a67eb9158d341a69dddfb654be669
2015-01-28 19:23:11 -08:00
Christopher Ferris
8ea53fa87e Only one crashing thread should contact debuggerd.
If two or more threads crash at the same time, only let one talk to
debuggerd. It's possible for a race to occur that two threads send
data to debuggerd, the second one will cause errors in debuggerd since
the process will die once debuggerd lets the crashing pid start again.

Bug: 19183955
Change-Id: I17dfce46102117ab4a870f7381bd526488d37fb5
2015-01-28 16:20:26 -08:00
Nikola Veljkovic
db3078d97b Fix mips64 build. Replace explicit cast with static_cast
Change-Id: Ib08fbe8bb832884a3eb33904fe4d490759116cb2
2015-01-28 16:19:18 +01:00
Elliott Hughes
14152b9f31 Remove obsolete BUILD_TINY_ANDROID.
Change-Id: If2fc97134340fd09ec2583b666ace2f673cbdf66
2015-01-24 19:01:58 -08:00
Dmitriy Ivanov
31005ca4c8 Merge "Minimize calls to mprotect" 2015-01-24 00:45:25 +00:00
Dmitriy Ivanov
279a22f96e Minimize calls to mprotect
Implement refcounter based data protection guard
  to avoid unnecessary calls to mprotect when dlopen/dlclose
  is called from a constructor.

Bug: 19124318
Big: 7941716
Change-Id: Id221b84ce75443094f99756dc9950b0a1dc87222
2015-01-23 16:30:34 -08:00
Chih-Hung Hsieh
f5ae7e91ea Merge "Add comments about the -shared flag." 2015-01-23 23:33:54 +00:00
Elliott Hughes
611f95689e Add a log message to make the transition from linker to user code clear.
Handy when looking at strace output for seeing "where does my code start?",
though you'll need to set LD_DEBUG=1 (or greater) and constructors will
already have run (but you can set LD_DEBUG to a higher value to track that).

Change-Id: I82d53a7123b39febf5b2a956de83c8a30f229651
2015-01-23 10:43:58 -08:00
Chih-Hung Hsieh
306ea7ebe5 Add comments about the -shared flag.
Must build this linker as a shared object.
A statically linked module does not load during init.

BUG: 18008984

Change-Id: I5f0411129024edcb9381c473ea4e741a075e9184
2015-01-22 19:09:20 -08:00
Dmitriy Ivanov
1649e7ee5b Enable -Wold-style-cast warnings for linker
And fix old style casts.

Change-Id: I37e7a3e3fd852528ea76f02d967c7bd8cd5b06c9
2015-01-22 16:33:30 -08:00
Christopher Ferris
151da68100 Contact proper debuggerd when crashing.
Make the request structure match the new structure found in debuggerd
code.

On 64 bit systems, make sure that the 32 bit compiled linker is contacted.

Bug: https://code.google.com/p/android/issues/detail?id=97024
Change-Id: I675b8ff222fcf836b05de4e9b5976ff91ca929bf
2015-01-20 17:22:25 -08:00
Dmitriy Ivanov
114ff69f17 Refactoring: move mips reloc to separate method
Change-Id: I712614853e3f0e515f5c2bdd8f0aaa5feeae8e55
2015-01-14 18:03:19 -08:00
Dmitriy Ivanov
bcc04d0069 Refactoring: unify relocate function
Use one relocate for all platforms.

Change-Id: I43e75162c5b29105e651defc11a511e168368736
2015-01-13 19:15:02 -08:00
Dmitriy Ivanov
1b694693b4 Refactoring: use generic reloc constants
Change-Id: I94dd6256b1b4509b6ea696a3aff17a3991529468
2015-01-13 15:56:54 -08:00
Dimitry Ivanov
d338aac19c Revert "Refactoring: use generic reloc constants"
This reverts commit 265a60a0d2.

Change-Id: I6d46db0ac03cda44ed1e20f6084a552e0089eb14
2015-01-13 22:31:54 +00:00
Dmitriy Ivanov
265a60a0d2 Refactoring: use generic reloc constants
Change-Id: I67918a1a926164a38a5a47f2264390632eb42905
2015-01-13 12:17:31 -08:00
Dmitriy Ivanov
9c4783b18c Merge changes I713800ce,I1dea46c3
* changes:
  Refactor soinfo::relocate
  Add ARM_IRELATIVE relocation
2015-01-09 23:44:50 +00:00
Dmitriy Ivanov
cefef7dab6 Refactor soinfo::relocate
Move common relocation types outside of ifdefs

Change-Id: I713800ce123a18178b5ac80c0b3c7bd6b21a02c2
2015-01-09 14:57:53 -08:00
Duane Sand
6f40a8ac74 Revert "Must use Clang assembler for mips target."
This reverts commit 6f96d58c0d.
2015-01-09 10:24:11 -08:00
Dmitriy Ivanov
b5e508cfee Merge "Set linux 32bit personality for 32 bit processes" 2015-01-08 00:46:49 +00:00
Dmitriy Ivanov
bfa15e464e Set linux 32bit personality for 32 bit processes
Bug: 18069809
Change-Id: Ie143d56b0f8f03510dc451649291067e1add1d2f
2015-01-07 16:32:05 -08:00
Dmitriy Ivanov
6718125ac7 Print error when prelink fails for main executable
Bug: 18931021
Change-Id: Ib6c39a409161b20a10c3485272c73bc2abd4ee4f
(cherry picked from commit d9e211ca1f)
2015-01-07 15:49:40 -08:00
Raghu Gandham
688157295f Add support for DT_MIPS_RLD_MAP2 tag.
Position Independent Executables cannot communicate with GDB using DT_MIPS_RLD_TAG.
Hence a new tag DT_MIPS_RLD_MAP2 got introduced to fix the issue.

Change-Id: I77ce3faf1ef2e121003b804ecd291abb25cfbb56
Signed-off-by: Nikola Veljkovic<Nikola.Veljkovic@imgtec.com>
2014-12-19 11:13:11 -08:00
Chih-Hung Hsieh
6f96d58c0d Must use Clang assembler for mips target.
GNU assembler has internal error with clang's output.

BUG: 18807290
Change-Id: Iabbe991720fc562884f19d79bded903505fc891d
2014-12-18 17:10:56 -08:00
Dmitriy Ivanov
5ae82cba59 Fix soinfo_unload
1. Take into consideration that the local_group_root_
    is not set for all of not linked libraries.
 2. We need to check visited list earlier to avoid double
    soinfo_free.

Change-Id: Iabc0a06a97c63f7e6bd4641731f50bb1466fed4f
2014-12-02 17:28:34 -08:00
Elliott Hughes
b514026eb2 Kill <machine/exec.h>.
Bug: 18546535
Change-Id: I479e003deab21e31eb5caa5393067ed1dc558387
2014-12-02 16:16:29 -08:00
Dmitriy Ivanov
20463e3e53 Fix mips build
Change-Id: Iddbf06784d19556a55d833e20a68e6ccf5a7c5be
2014-12-02 13:27:40 -08:00
Dmitriy Ivanov
291dbf65ca Merge "Count references for groups instead of instances" 2014-12-02 19:10:04 +00:00
Dmitriy Ivanov
ab972b9adf Count references for groups instead of instances
Count references on the group level to avoid
  partially unloading function that might be
  referenced by other libraries in the local_group

  Bonus: with this change we can correctly unload recursively
  linked libraries. is_recursive check is removed.

  Also dynamic executables (not .so) with 0 DT_NEEDED libraries
  are now correctly linked.

Change-Id: Idfa83baef402840599b93a875f2881d9f020dbcd
2014-12-02 10:54:26 -08:00
Dmitriy Ivanov
224fb6144a Merge "Resolve "unused DT entry" warnings for DT_VERNEED and DT_VERNEEDNUM." 2014-12-02 17:37:18 +00:00
Alexander Ivchenko
e831433fe1 Resolve "unused DT entry" warnings for DT_VERNEED and DT_VERNEEDNUM.
Change-Id: Id18310811a6d183878a1d4d26cc2498f4fd00c55
Signed-off-by: Alexander Ivchenko <alexander.ivchenko@intel.com>
2014-12-02 15:34:30 +03:00
Elliott Hughes
212e0e3824 Build our benchmarks against glibc too.
Bug: 18556607
Change-Id: I455ac8b93c0835836180e549486bc52d393ee6a6
2014-12-01 16:43:51 -08:00
Dmitriy Ivanov
a2547055f2 Fix jump to unmapped memory on atexit
Split d-tor calls and soinfo_free to 2 separate steps

Bug: 18338888
Change-Id: Idbcb7242ade16fa18cba7fe30505ebd8d6023622
2014-11-18 13:16:27 -08:00
Dmitriy Ivanov
047b5934b5 Rename soinfo methods and fields
Change-Id: If68fbe287d3ad954238b1688f71013371f3f7fae
2014-11-13 19:48:32 -08:00
Dmitriy Ivanov
8894091683 Fix mips build
Change-Id: I58b01db38ab9a397a8bd77c1296aac12957c21da
2014-11-12 18:21:12 -08:00