Commit graph

687 commits

Author SHA1 Message Date
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