Commit graph

788 commits

Author SHA1 Message Date
Dmitriy Ivanov
126af757c6 Implement load at fixed address feature
Bug: http://b/24683631
Change-Id: I3a39ab526c8f9e213339b60e135e5459d0f41381
2015-10-27 11:27:34 -07:00
Dmitriy Ivanov
4f7a7ad3fe Implement Library Load Order Randomization
Bug: http://b/24047022
Change-Id: I36e05b403bfbaae8542a95147f9114a8b9c8ac0e
2015-10-22 18:26:07 -07:00
Dmitriy Ivanov
cf1cbbe432 refactoring: introduce MappedFileFragment
Change-Id: I97b0c1131711ed0ac13ab33e3357e99e0b6b1a4e
2015-10-22 18:01:56 -07:00
Mike Frysinger
747d30ebf3 dlfcn: update ifdef around old_name_
Commit 9185e04f72 changed the ifdef around
old_name_ from __arm__ to __work_around_b_###__, but missed one place in
dlfcn.cpp.  So if you do a build w/out that workaround for arm, you end
up with a build failure:
bionic/linker/dlfcn.cpp:275:27: error: no member named 'old_name_' in 'soinfo'
    strlcpy(__libdl_info->old_name_, __libdl_info->soname_, sizeof(__libdl_info->old_name_));
            ~~~~~~~~~~~~  ^
bionic/linker/dlfcn.cpp:275:82: error: no member named 'old_name_' in 'soinfo'
    strlcpy(__libdl_info->old_name_, __libdl_info->soname_, sizeof(__libdl_info->old_name_));
                                                                   ~~~~~~~~~~~~  ^

Bug: 24425865
Change-Id: Idbe1cc1c28083afeee6d90203c221f30f661c69c
2015-10-20 14:06:25 -04:00
Dimitry Ivanov
5fd94dfe3b Merge "Replace auto -> const auto&/auto&&" 2015-10-16 20:37:34 +00:00
Dimitry Ivanov
9c2122e803 Merge "Fix R_AARCH64_ABS/PREL relocations" 2015-10-16 20:36:25 +00:00
Dmitriy Ivanov
77f91c6d99 Fix R_AARCH64_ABS/PREL relocations
According to specification arm64 relocations
should not use *reloc value.

See http://infocenter.arm.com/help/topic/com.arm.doc.ihi0056b/IHI0056B_aaelf64.pdf
section 4.6.5

Bug: http://b/24977219
Bug: http://b/24527155
Change-Id: I3813255771f408ba957963c6ad56ed08e5110d83
2015-10-16 10:42:16 -07:00
Dmitriy Ivanov
4e50d0247b Ensure that readlink has access to /proc/self/fd
/proc/self/fd is not available when PR_DUMPABLE is set to 0
which is default for the user builds. It leads to permission
denials on readlink.

This change fixes the problem by setting PR_DUMPABLE flag to 1
for readlink and restoring it's previous value after the call.

Bug: http://b/24912743
Change-Id: I3fd179c5c6b56af96d6a15ee597024ccb15e1a13
(cherry picked from commit cf92738fa5)
2015-10-14 18:24:54 -07:00
Dmitriy Ivanov
fae39d2bf9 Log dlopen failures caused by text relocations
Some apps will fail to load native libraries with
text relocations when switching target sdk version to M.
It could be hard to diagnose because some of them
suppress dlerror and/or UnsatisfiedLinkError.

This change unconditionally logs the error message making
the cause of the failure more visible to developers.

Bug: http://b/24876001
Change-Id: I0477a0d1307d0879000f3a3a43b974b4cf34bdb2
(cherry picked from commit f32b689d3d)
2015-10-13 15:48:57 -07:00
Dmitriy Ivanov
5dce8948b6 Replace auto -> const auto&/auto&&
Change-Id: Ie484e5a296b5dd222a9545d8539d40d97a6c158c
2015-10-13 12:14:16 -07:00
Lazar Trsic
6f2d3104c8 Correctly resolve realpath for absolute paths
Introduced by: https://android-review.googlesource.com/174475

Change-Id: I44e00040b28be167d5141454f919340afec6084e
2015-10-13 10:57:41 -07:00
Dmitriy Ivanov
b28ffc7744 linker: Switch to clang
x86_64 gcc exports malloc/free and co functions because they
are defined with visibility "default" somewhere in gcc builtins;
and vector d-tors for some reason. Switching to clang fixes
this problem.

Bug: http://b/24785482
Change-Id: I741503b4b446523e7ff3fb16de13ed99991fd0c0
2015-10-12 18:20:26 -07:00
Josh Gao
93c0f5ee00 Move VDSO pointers to a shared globals struct.
Change-Id: I01cbc9cf0917dc1fac52d9205bda2c68529d12ef
2015-10-09 15:59:04 -07:00
Dmitriy Ivanov
8068786ae6 Remove textrels support for platform libs
Bug: http://b/20013628
Change-Id: Ia9382c7113e09bb6aed65072543e4ebe33026cf8
2015-10-09 13:59:42 -07:00
Dmitriy Ivanov
a1feb117e4 Make dt_runpath work for libraries opened from apk
This patch also fixes realpath for libraries opened directly
from apks.

Bug: http://b/21960914
Bug: http://b/21961857
Change-Id: I35ade661c87f1d448191f385811f6e9fd3cacf11
2015-10-07 11:44:53 -07:00
Dmitriy Ivanov
a0f187bec7 Fix linker tests
Change-Id: I4794f2d9dcc5ceb419e1bf9151607a650eb801d9
2015-10-05 12:06:40 -07:00
Dmitriy Ivanov
7e039937b8 Fix the comment
Change-Id: Ic8126cf92d12851cccaa3e2e781f075c9f6c283a
2015-10-01 14:02:19 -07:00
Dmitriy Ivanov
b48275045d Optimize dlopen from a zip file
This change makes dynamic linker reuse ZipArchiveHandles in
ld_library_path on dlopen to optimize the lookup of dt_needed
libraries.

Bug: http://b/21960534
Change-Id: I65f897910d46dd2ffabdcb0b7842db2f127eee30
2015-09-30 10:47:11 -07:00
Dmitriy Ivanov
280d54680d Fix bug number for linker related workarounds
Bug: 24425865
Change-Id: I2021674a9df0e768f312ca024d906302db1c494f
2015-09-28 10:31:12 -07:00
Douglas Leung
dccc40883a Fix mips FP abi bug in the linker.
Change-Id: I1ffab938eb06f9dc0963ee15bc10eca216618792
2015-09-17 15:17:06 -07:00
Dmitriy Ivanov
edfc9f63a2 linker: don't pass dlextinfo to dependent loads
Don't pass the parent load's dlextinfo to dependent loads, since this
causes the linker to try to load the dependencies using the same
addresses/relro/fds/etc as the main library, which is never going to
work. This was how it worked before ae69a95 which broke this.

Bug: http://b/23742664
Bug: http://b/20948231
Bug: http://b/20841817
Change-Id: I340ebae1127666d5c6c6f9c6521b89fb93f15bdd
2015-09-02 16:32:02 -07:00
Elliott Hughes
44ead71726 Regenerate NOTICE files.
Change-Id: Ia5c340220bb75e4e3166cc483ea77d19cfb08a71
2015-08-28 20:23:52 -07:00
skvalex
93ce35434c Fix a mistype in segment overrange checking
Change-Id: Ibea93514aa7ba3b1ac2bc00420f5124fb34f5f66
Signed-off-by: skvalex <skvalex@gmail.com>
2015-08-20 01:06:42 +03:00
Ying Wang
d1afa661af Don't attach linker_asan to linker in module definition.
With this change, we only define the rules to create the symlinks in
this Android.mk but without attaching the symlinks to the module linker.
Instead the core build system will set up the dependency whenever a
module needs these symlinks.

Bug: 22850550
Change-Id: I36c58fd411f1c27f3f638b229699d7dc1d66abb2
2015-08-17 16:17:03 -07:00
Dan Albert
5341691955 Move up to C++14.
The default standard version is now ahead of us. Stop specifying C++11
so we get that too.

Change-Id: Ic96942cd7fd134118e29b744601b0119e49b6ac4
2015-08-10 16:40:06 -07:00
Duane Sand
0acb15ead6 [MIPS] Link .dex or .oat code lacking .MIPS.abiflags segment
This corrects an issue with mips32 Art on mips64r6 Android, where
Java ran slowly due to unintended use of kernel-trap emulation of
single-precision floating point registers. This also regressed all
Art tests due to an extra logcat line
    WARNING: linker: Using FRE=1 mode to run "..."

When targeting mips32r6, Art generates modeless or FR=1 floating point
code, same as Android's own native mips32r6 modules. So the trapping was
unneeded. Linker was confusing Art-generated modules with those from
old NDK compilers, which do need that trapping mode.

This linker filename check may become unnecessary, if Art learns how to
generate .MIPS.abiflags segments in its generated elf-like codefiles.

Change-Id: I18069d1234960c680c5df739514da09015a7fdb6
2015-07-31 13:55:42 -07:00
Elliott Hughes
9f03ed12a6 Stop sending SIGPIPE to debuggerd.
SIGPIPE is a pretty normal way for command-line apps to die, but because
we catch it and report it via debuggerd, we get a lot of bogus bugs. We
could catch SIGPIPE in our tools, but that's not really legit and slightly
misleading.

"But", you say, "catching SIGPIPE is useful for app bugs!". Except a trawl
through buganizer suggests it's misleading there too. Not least because
it's usually an innocent victim that dies --- the problem is usually on the
other end of the pipe (which you learn nothing about because that process
already died, which is what closed the pipe).

We also don't catch SIGALRM, which is another signal that will terminate
your process if you don't catch it, but that one actually represents a
logic error in the crashing process, so there's a stronger argument for
catching that. (Except it too is not a real source of bugs.)

Bug: http://b/20659371
Change-Id: I79820b36573ddaa9a7bad0561a52f23e7a8d15ac
2015-07-29 22:24:13 -07:00
tony.ys_liu
b447440a4b Prevent buffer over-read in linker.cpp's parse_path.
Also, the old behavior of skipping empty entries doesn't match glibc.

Change-Id: I497774377113ab6c5d962e0f20066e2192748f06
2015-07-29 17:21:30 -07:00
Elliott Hughes
afab3ffcce Move PAGE_MASK into <sys/user.h>.
I'm removing the TODO on the assumption that being compatible with glibc
is more useful than BSD. The new internal "bionic_page.h" header factors
out some duplication between libc and the linker.

Bug: http://b/22735893
Change-Id: I4aec4dcba5886fb6f6b9290a8f85660643261321
2015-07-28 14:58:37 -07:00
Dmitriy Ivanov
ec83a61c8b Restore protection flags for ifunc during relocs.
IFUNC relocations require executable flag for the load
segment containing .text. When dso has text relocs linker
removes exec which causes crash during ifunc relocations.

This patch fixes this problem by restoring segments protection
for ifunc relocs.

Bug: http://b/22611399
Change-Id: Icbf3be0fec0e42bf805bcad7533e2032a2e11b9c
(cherry picked from commit de0fb393ae)
2015-07-26 08:23:01 -07:00
Elliott Hughes
d29486343a Use a less misleading name for the code that sets up the main thread.
Change-Id: I50c1b0a3b633cf8bc40a6bd86f12adb6b91e2888
2015-07-21 11:57:09 -07:00
Dmitriy Ivanov
e5cfafe344 Fix potential race condition on dlopen
Call to find_containing_library should be guarded.

Change-Id: I985a903da48b83bcd35e957a979158eb9b80e70b
2015-07-17 10:36:10 -07:00
Dmitriy Ivanov
730ed9dfec Add constant for zip separator
Change-Id: I1dcbb15ac612fc28e922eb3de8148fcaebbc0820
2015-07-16 04:52:06 -07:00
Evgenii Stepanov
d11c3e5c3a Replace spaces with tabs in a Makefile.
Sorry, I undertested my previous change and these guys somehow sneaked in.
This only affects SANITIZE_TARGET builds.

Change-Id: Id6986d89fa3d4965339f7b6fe973e9db73b380da
2015-07-15 16:19:59 -07:00
Evgenii Stepanov
d640b225ec A special linker for ASan executables.
Setup a /system/bin/linker_asan as a symlink to "linker".
Read the linker name from PT_INTERP, and if it is linker_asan,
switch default library lookup paths to the ASan set, which
starts with the path to the instrumented libraries
(/data/lib), followed by /system/lib as a fallback.

This ensures that ASan binaries prefer ASan libraries, when
available. This approach is way better then RPATH/RUNPATH and even
better than LD_LIBRARY_PATH:
- RUNPATH is per-DSO, while default paths are global.
- LD_LIBRARY_PATH is overwritten by android_update_LD_LIBRARY_PATH.
- neither RUNPATH nor LD_LIBRARY_PATH appear in
  android_get_LD_LIBRARY_PATH which is used to build java.lang.path.
  Having ASan libraries in java.lang.path is a good thing.

Bug: 22355945
Change-Id: I1d2791fbf5740618f18f71a3ae3d873714669d3f
2015-07-14 16:12:27 -07:00
Dmitriy Ivanov
609f11b31e Fix memory-leak on soinfo_free()
Bug: http://b/22290728
Change-Id: I00747056db2cd3ff8b33936278464daed7236536
2015-07-08 15:26:46 -07:00
Evgenii Stepanov
33ef6c20f2 Merge "Respect caller DT_RUNPATH in dlopen()." 2015-07-08 19:50:03 +00:00
Evgenii Stepanov
0cdef7e7f3 Respect caller DT_RUNPATH in dlopen().
When dlopen-ing a library, add the caller's DT_RUNPATH to the directory search
list. This fixes dlfcn.dt_runpath in bionic-unit-tests-glibc(32|64).

Bug: 21899363
Change-Id: Ife6a7e192939292cf4dc291b7e6b95945761cde3
2015-07-07 10:56:06 -07:00
Dmitriy Ivanov
c2247478d5 Improve personality initialization
1. Personality parameter should be unsigned int (not long)
2. Do not reset bits outside of PER_MASK when setting
   personality value.
3. Set personality for static executables.

Bug: http://b/21900686
Change-Id: I4c7e34079cbd59b818ce221eed325c05b9bb2303
(cherry picked from commit f643eb38c3)
2015-06-30 19:01:24 -07:00
Dmitriy Ivanov
7271caf93d Lock on dl_interate_phdr
There is possibility of someone dlclosing a library
while dl_iterate_phdr in progress which can lead to
dl_iterate_phdr calling callback with invalid address
if it was unmapped by dlclose.

Bug: http://b/22047255
Change-Id: I3fc0d9fd2c51fb36fd34cb035f37271fa893a7be
(cherry picked from commit f7d5bf334d)
2015-06-29 15:14:28 -07:00
Yusuke Sato
71107cdd02 Merge "Rename ZipEntryName to ZipString" 2015-06-29 17:49:41 +00:00
Dmitriy Ivanov
3f987f5b3e Fix crash when trying to load invalid ELF file.
Bug: http://b/22047255
Bug: http://b/22091640
Change-Id: I6c51cff43287a6ac4b25fa9ce6a6fc3d232fd047
(cherry picked from commit 06700b2b5e)
2015-06-25 20:05:50 -07:00
Yusuke Sato
56f40fbb82 Rename ZipEntryName to ZipString
This is for https://android-review.googlesource.com/#/c/156771/.

Bug: 21957428
Change-Id: Ida30c28c0fff0b2dadddbdb1aa1999ae3250610b
2015-06-25 14:56:07 -07:00
Duane Sand
bc425c73e0 [MIPS] Support FR=0 emulation on FR=1 64-bit FP registers
Enables running of older MIPS NDK-built apps on mips64r6.

Works with kernel supporting FRE emulation, and old kernels.

Change-Id: If5e392ed89e9910cd1ccd30e0fd5c4a5acea2c7d
2015-06-24 16:43:19 -07:00
Dimitry Ivanov
c666838ad6 Merge "Revert "[MIPS] Support FR=0 emulation on FR=1 64-bit FP registers"" 2015-06-24 20:44:36 +00:00
Dimitry Ivanov
cc83890464 Revert "[MIPS] Support FR=0 emulation on FR=1 64-bit FP registers"
This reverts commit d02ec08427.

Bug: http://b/22045439
Change-Id: Iaf10ff1e2948083cce0098f29d5b87b32bfae1b7
2015-06-24 20:43:33 +00:00
Dmitriy Ivanov
e4ad91f86a Remove text-relocs support for apps targeting M+
Remove support of text-relocations for apps targeting sdk version > 22

Bug: http://b/20013628
Change-Id: I2127739544480c747315e32df15dfbd1b79de4f5
(cherry picked from commit 3e6f780754)
2015-06-22 12:26:53 -07:00
Duane Sand
d02ec08427 [MIPS] Support FR=0 emulation on FR=1 64-bit FP registers
Enables running of older MIPS NDK-built apps on mips64r6.

Works with kernel supporting FRE emulation, and old kernels.

Change-Id: I13923fe62cd83ad1d337f13a50f2eda2dfdd906f
2015-06-21 11:36:57 -07:00
Dmitriy Ivanov
a9703332f6 Improve library lookup logic
Linker tries to open a library even if it can
be found by soname. This only happens if the
library was previously opened under different
target sdk version.

Bug: http://b/21876587
Bug: http://b/21153477
Bug: http://b/21171302
Bug: https://code.google.com/p/android/issues/detail?id=160921
Change-Id: I7dbbcc3b49933bffd89ca0af55371e1a1f2bf4c2
(cherry picked from commit 28154f5c56)
2015-06-17 17:16:44 -07:00
Dimitry Ivanov
d2c81ed000 Revert "Improve library lookup logic"
This reverts commit 455c145e3c.

Bug: http://b/21876587
Bug: http://b/21153477
Bug: http://b/21171302
Bug: https://code.google.com/p/android/issues/detail?id=160921
Change-Id: Iad21ddfc1ac749d12bcb52384a8d937b307dd03b
2015-06-17 21:34:25 +00:00
Dmitriy Ivanov
455c145e3c Improve library lookup logic
Linker tries to open a library even if it can
be found by soname. This only happens if the
library was previously opened under different
target sdk version.

Bug: http://b/21876587
Bug: http://b/21153477
Bug: http://b/21171302
Bug: https://code.google.com/p/android/issues/detail?id=160921
Change-Id: I769a04b6b1368a107d43f399297be14050338bbc
(cherry picked from commit ea4ef52fa4)
2015-06-17 10:18:28 -07:00
Nikola Veljkovic
dee130f598 Revert "[MIPS] Do not use compact branches until GDB supports them"
This reverts commit 3cec6eca92.
2015-06-17 17:17:54 +02:00
Dmitriy Ivanov
402a75060d Make path to apk compliant with jar url format
Bug: http://b/21726698
Bug: http://b/8076853
Change-Id: I8c1942a98fe3119746b4dc9f60a7ff215ea7009c
(cherry picked from commit 524f1f1efe)
2015-06-11 11:01:23 -07:00
Dmitriy Ivanov
175dae92d7 Fix l_addr for the linker
Bug: http://b/21765603
Change-Id: I97710ef2436eac2160e29ba3e4521f6e63a1907c
2015-06-10 19:47:26 -07:00
Evgenii Stepanov
72af1235e4 Merge "Support DT_RUNPATH in the linker." 2015-06-10 23:56:03 +00:00
Evgenii Stepanov
6865082ca6 Support DT_RUNPATH in the linker.
Only $ORIGIN substitution is supported, but not linux-specific $LIB
or $PLATFORM.

Change-Id: I5814a016c7c91afba080230a547a863686e7c2b9
2015-06-10 16:44:22 -07:00
Elliott Hughes
ba1d40a3f1 Merge "Statically linked executables should honor AT_SECURE." 2015-06-10 22:49:57 +00:00
Dmitriy Ivanov
f3463db7eb Merge "Check if strtab exists before using it" 2015-06-10 22:26:07 +00:00
Elliott Hughes
1801db3d3f Statically linked executables should honor AT_SECURE.
Bug: http://b/19647373
Change-Id: I10e7682d9cec26a523f1a3597ca5326c3ca42ebe
2015-06-09 20:10:25 -07:00
Dmitriy Ivanov
8a11628355 Add flag that makes linker honor min(p_vaddr)
Bug: http://b/21523078
Change-Id: Ice72766fb6ad3bd333c32b496e7870121e17a763
2015-06-09 13:44:31 -07:00
Dmitriy Ivanov
624b8f17a1 Check if strtab exists before using it
Bug: http://b/21696087
Change-Id: I1e22d5fd6fe2faead332249493123c9a085081e9
2015-06-08 10:41:33 -07:00
Dmitriy Ivanov
1913352c6b Backward compatibility for dlsym(RTLD_DEFAULT, ...)
Do not skip RTLD_LOCAL libraries in dlsym(RTLD_DEFAULT, ...)
 if the library is opened by application with target api level <= 22

Bug: http://b/21565766
Bug: http://b/17512583
Change-Id: Ic45ed1e4f53e84cba9d74cab6b0049c0c7aa8423
(cherry picked from commit 04f7e3e955)
2015-06-02 18:09:23 -07:00
Dmitriy Ivanov
11b15b23aa Merge "Work around for libraries without dt_soname" 2015-06-02 21:09:41 +00:00
Dmitriy Ivanov
75108f4f83 Work around for libraries without dt_soname
Applies only for apps targeting sdk version <= 22

Bug: http://b/21565766
Change-Id: If0bf2229dc1341e9ca09f9a05d0890515273d5a2
(cherry picked from commit 38c37d6705)
2015-06-02 14:02:22 -07:00
Dmitriy Ivanov
f439b5a318 Fix dlsym(handle_of_main_executable, ...)
According to man dlopen(3) and posix docs in the case when si is handle
  of the main executable we need to search not only in the executable and its
  dependencies but also in all libraries loaded with RTLD_GLOBAL.

  see also: http://pubs.opengroup.org/onlinepubs/9699919799/functions/dlopen.html

Bug: http://b/21528224
Bug: http://b/17512583
Bug: https://code.google.com/p/android/issues/detail?id=173822
Change-Id: Ib2801367ba48b6f3704da89a6d9f5e6911430013
2015-06-01 14:33:43 -07:00
Elliott Hughes
d70891687d Merge "[MIPS] Do not use compact branches until GDB supports them" 2015-05-29 04:39:24 +00:00
Dmitriy Ivanov
5511551009 Merge "Improve some of error/warning messages" 2015-05-28 22:28:13 +00:00
Dmitriy Ivanov
d974e88046 Work around incorrect dt_needed entries
This applies for apps targeting sdk<=22 and
  only for lp32 platforms.

Bug: http://b/21364029
Change-Id: I903e81c9ccda2a8beaba1d132d68c77d30a4cdb2
2015-05-28 14:56:42 -07:00
Dmitriy Ivanov
087005f37e Improve some of error/warning messages
Bug: http://b/20464031
Change-Id: I948141c46f9e054fc45f5934153dee56ce3cd558
2015-05-28 11:44:31 -07:00
Dmitriy Ivanov
79fd668bb4 Add functions to provide target sdk version
Bug: http://b/21364029
Change-Id: I8648d1bff6c8fd6e7cd12da7f128e048b9f2829a
2015-05-27 14:31:36 -07:00
Nikola Veljkovic
3cec6eca92 [MIPS] Do not use compact branches until GDB supports them
GDB does not yet have support for compact branches, and is not able
to set a breakpoint on rtld_db_dlactivity(), which is compiled into
one JIC instruction. Unfortunately, We cannot turn off generation of
JIC compact branch. Instead, add unoptimized FP handling code, so GDB
will have something to land on.

Change-Id: Iddcf40ec018972398179018d049b8323fcd258b7
2015-05-25 16:28:14 +02:00
Dmitriy Ivanov
b96ac41b32 Fix RTLD_NEXT lookup for the local_group
Linker used to skip RTLD_NEXT within local_group when
  caller->next is nullptr (which represents load order
  but not the order within local_group dependency tree)

Bug: http://b/21380474
Change-Id: I178fc4657b19bceb871635b177c1df67855b1708
2015-05-22 19:46:11 +00:00
Dmitriy Ivanov
a42b5bcd89 Merge "Apply work around b/19059885 to x86" 2015-05-16 16:56:49 +00:00
Dmitriy Ivanov
9185e04f72 Apply work around b/19059885 to x86
Bug: http://b/19059885
Bug: http://b/21203348
Change-Id: Ic375e9f877d68de8f866d17362879a7dde638465
(cherry picked from commit 69a5fb951d)
2015-05-15 18:42:14 -07:00
Elliott Hughes
882283e9e2 Merge "Don't use TEMP_FAILURE_RETRY on close in bionic." 2015-05-15 23:24:12 +00:00
Elliott Hughes
4e8ef698d0 Don't use TEMP_FAILURE_RETRY on close in bionic.
Bug: http://b/20501816
Change-Id: Id64b5109cc2b165fa0351b6edbb865a5e5058008
2015-05-15 16:20:07 -07:00
John Reck
e77e335b54 Fix regression in crash reporting
Bug: 19532651

Partial revert of be0e43b776

Change-Id: I99e220328aff985facb920ebcd84ac1a016759b5
(cherry picked from commit d7ad443cfd)
2015-05-15 09:28:10 -07:00
Spencer Low
0346ad7a4f ScopedFd: Don't use TEMP_FAILURE_RETRY() with close()
According to the comments in Posix_close(), TEMP_FAILURE_RETRY() should
not be used with close():

462bdac45c%5E%21/#F12

Kill ScopedFd by simplifying the single caller.

Change-Id: I248c40b8c2fc95f1938a6edfc245c81847fc44af
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-05-13 13:27:11 -07:00
Dmitriy Ivanov
fe77d2d003 Merge "Improved dlsym tests and fixes to linker" 2015-05-12 20:48:17 +00:00
Dmitriy Ivanov
697bd9fd38 Improved dlsym tests and fixes to linker
Answers the question: what if dependent library
 was preloaded with RTLD_LOCAL flag.

 Also add test for RTLD_NEXT within local_group.

Bug: http://b/17512583
Change-Id: I79e081e68b3a8c0ed8980d4275a06515fea94ec9
2015-05-12 13:46:40 -07:00
Elliott Hughes
f58ac87182 Update NOTICE files (the second time today).
Change-Id: Ifb031d29ee697ee0682bd651e0081493e8016e67
2015-05-12 10:44:37 -07:00
Elliott Hughes
7e54c762fc Update NOTICE files.
(cherry-pick of f0bd92db8966b04062fda0986dacf80891e1a378.)
Change-Id: I4e170118abf452dd87ffe79d343ba1e2b53955de
2015-05-12 10:33:20 -07:00
Elliott Hughes
8a330cad8d Merge "Simplify three copyright headers." 2015-05-12 17:27:04 +00:00
Elliott Hughes
c69ace87ec Simplify three copyright headers.
There's no reason to have multiple years in our own copyright headers,
and given the stupidity of our NOTICE file generation, it just creates
more junk.

Change-Id: I065a3811c2e2584e3b649a18ad9460286bc72b92
2015-05-12 10:10:01 -07:00
Dmitriy Ivanov
3edb9182ff Use realpath for log and error messages
Bug: http://b/20885931
Change-Id: Ida8ab7982ca75fa73da13c4cb10a6b2e53bc2c8e
2015-05-07 10:48:00 -07:00
Dmitriy Ivanov
406d99665c VersionTracker: Ignore libraries without soname
Bug: http://b/20872443
Change-Id: I7bd076885c1feae39af6ea64c9442bcc5ae5a1dc
(cherry picked from commit 8264afb377)
2015-05-06 12:04:57 -07:00
Dmitriy Ivanov
dbe26fdcc7 Fix protected symbol lookups for mips
Bug: http://b/20694161
Change-Id: I5cc58034f9776e1db9cddc34abe48ef85f6048f4
2015-05-04 19:30:49 -07:00
Dmitriy Ivanov
f39cb63603 Lookup version info when relocating mips got
Bug: http://b/20693971
Bug: http://b/20139821
Change-Id: I28bd3bc44dafe048761b2c598facfe20320128c4
2015-04-30 20:17:03 -07:00
Dmitriy Ivanov
7e4bbbae4a Refactoring: move VersionTracker to link_image
Use one instance of VersionTracker per link (instead of 2).

Change-Id: I6860013df65f5969975c82ebdae8bd90a82e0a82
2015-04-30 19:49:19 -07:00
Dmitriy Ivanov
31b408d2c2 Refactoring: extract lookup_version_info(..)
Change-Id: I47f9c21a1738dc520fd83281c8227dc3a7e79650
2015-04-30 16:12:32 -07:00
Dmitriy Ivanov
f29640c2d8 Merge "linker: initialize system properties" 2015-04-29 23:44:57 +00:00
Dmitriy Ivanov
0373d4f473 Fix mips relocation to use load_bias as intended
Bug: http://b/20658994
Change-Id: I5a15605fe34db359e26d563e13841ae993083c4a
2015-04-29 14:41:06 -07:00
Dmitriy Ivanov
f8093a9485 Fix LD_PRELOAD for dlopen()
We did not set DF_1_GLOBAL flag for LD_PRELOADed
 libraries which led to the situation when ld_preloads
 where ignored during on dlopen()

Change-Id: I696b3b2506a8ed4c0984ad2c803210a7a4f8e686
2015-04-28 18:09:53 -07:00
Dmitriy Ivanov
b4e5067cab linker: initialize system properties
Bug: http://b/20567629
Bug: https://code.google.com/p/chromium/issues/detail?id=478886
Change-Id: I8d2d89b749015e7fcd6e7ea646911f2e617dd1ba
2015-04-28 15:52:52 -07:00
Dmitriy Ivanov
a85bcc2e99 linker: use libc's environ variable to store envp
This is to make getenv() work correctly.

Bug: http://b/20567629
Change-Id: I148627e1efea1649fb0822c95876811652fb4082
2015-04-28 14:21:36 -07:00
Dmitriy Ivanov
2ea504fed1 Remove outdated warning
It is ok to use malloc in linker.

Bug: http://b/20567629
Change-Id: I54183dbe8ebcd223a44e710e511c339688a65dba
2015-04-27 11:24:36 -07:00
Dmitriy Ivanov
18870d350c Always use signed leb128 decoder
Relocation packer no longer encodes relocation tables
  using unsigned leb128: https://android-review.googlesource.com/147745

Bug: http://b/18051137
Change-Id: I620b7188e5f3dd9d5123431aa1fc7feca76be607
2015-04-22 13:29:42 -07:00
Dmitriy Ivanov
3d7bea1fa0 Add library name to error message
Change-Id: I079e6f1dd95fe9cae2135fcd7358c51f8b584ac9
2015-04-20 17:40:39 -07:00
Dmitriy Ivanov
2a81536144 Support symbol versioning
Bug: http://b/20139821
Change-Id: I64122a0fb0960c20b2ce614161b7ab048456b681
2015-04-16 17:57:30 -07:00
Dmitriy Ivanov
aae859cc3c Add realpath for soinfo
This change adds realpath to soinfo and
  extends limit on filenames from 128 to PATH_MAX.

  It also removes soinfo::name field, linker uses
  dt_soname instead.

Bug: http://b/19818481
Bug: https://code.google.com/p/android/issues/detail?id=80336
Change-Id: I9cff4cb5bda3ee2bc74e1bbded9594ea7fbe2a08
2015-04-06 21:15:43 +00:00
Dmitriy Ivanov
aea165cb03 Merge "Add ANDROID_DLEXT_FORCE_LOAD flag" 2015-04-03 19:45:24 +00:00
Dmitriy Ivanov
9b82136b98 Add ANDROID_DLEXT_FORCE_LOAD flag
This flag allows to force loading of the library
  in the case when for some reason multiple ELF files
  share the same filename (because the already-loaded
  library has been removed and overwritten, for example).

Change-Id: I798d44409ee13d63eaa75d685e99c4d028d2b0c1
2015-04-03 10:50:48 -07:00
Dmitriy Ivanov
06b6e3c51d Merge "Look into local group on dlsym with RTLD_DEFAULT" 2015-04-02 21:55:01 +00:00
Dmitriy Ivanov
76ac1acdac Look into local group on dlsym with RTLD_DEFAULT
Fix dlsym to look into local group when called with
  RTLD_DEFAULT and RTLD_NEXT.

Bug: 17512583
Change-Id: I541354e89539c712af2ea4ec751e546913027084
2015-04-02 14:12:45 -07:00
Nick Kralevich
8fdb3419a5 linker: never mark pages simultaneously writable / executable
When the Android dynamic linker handles a text relocation,
it first relaxes the permissions on the segment being modified,
performs the modifications, and then restores the page permissions.
The relaxation worked by adding PROT_WRITE to whatever protection
bits were set in the section. In effect, the pages were getting set
to PROT_READ|PROT_WRITE|PROT_EXEC, modified, then restored to
PROT_READ|PROT_EXEC

The SELinux kernel code differentiates between 4 different kinds
of executable memory:
* Executable stack (execstack)
* Executable heap (execheap)
* File-based executable code which has been modified (execmod)
* All other executable memory (execmem)

The execmod capability is only triggered by the kernel when a
dirty but non-executable mmap()ed page becomes executable. When that
occurs, an SELinux policy check is done to see if the execmod capability
is provided by policy.

However, if the page is already executable, and PROT_WRITE is added
to the page, it's considered an execmem permission check, not an execmod
permission check.

There are certain circumstances where we may want to distinguish between
execmod and execmem. This change adjusts the dynamic linker to avoid
using RWX pages, so that an RX -> RW -> RX transition will properly
be detected as an execmod permission check instead of an execmem permission
check.

Bug: 20013628
Change-Id: I14d7be29170b156942f9809023f3b2fc1f37846c
2015-04-01 18:05:19 -07:00
Dimitry Ivanov
56be6ed9e4 Revert "Remove text-relocation support for lp32"
This reverts commit cb00add1b3.

Bug: 20020312
Bug: 20013628
Change-Id: I8baa3d4b6c7fef50c9e2531257d5b96762099eb3
2015-04-01 21:18:48 +00:00
Dmitriy Ivanov
cb00add1b3 Remove text-relocation support for lp32
Bug: 20013628
Change-Id: Idaf8012f00ee1304d429c3b42f9ebc6b648c55b8
2015-03-31 17:42:45 -07:00
Dmitriy Ivanov
20d89cb5b0 Fix long lines and replace macros with functions.
Change-Id: I4e1cab488d5b2c8e4289da617350a86e72a4ba12
2015-03-31 11:49:25 -07:00
Nick Kralevich
e001ca3e18 linker_environ: clear MALLOC_CONF when AT_SECURE=1
Clear JE_MALLOC_CONF and MALLOC_CONF

Change-Id: Ia76e263783194ecaa362e8ccafbe13a28a4a1ba6
2015-03-27 15:49:33 -07:00
Dmitriy Ivanov
797bffb760 Explain why we need objcopy for the linker
Change-Id: I646673abc6095b56f72add493b60925375b75b78
2015-03-26 16:47:18 -07:00
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