Commit graph

62 commits

Author SHA1 Message Date
Yabin Cui
722072d65a CloseArchive() to free memory when OpenArchive fails.
Bug: 26962895
Change-Id: I42418eee320ddae857b42572690316c53f638e85
2016-03-22 16:43:24 -07:00
Christopher Ferris
c0ffceccf9 Remove dependency on zipalign.
Roll our own version of zipalign so that we can break the dependency
on the build tools zipalign. This breaks the transitive dependency
on androidfw so that building bionic unit tests in brillo works again.

Also modify the DlExtTest.ExtInfoUseFdWithOffset test so it dynamically
gets the offset of the shared library inside of the zip instead of
hard-coding the value.

Bug: 25446938
Change-Id: Idfb5d3089960a94eefa2c76e03da1ad2f4d7fb2f
2016-01-20 19:56:53 -08:00
Dmitriy Ivanov
1ffec1cc4d Introduce anonymous namespace
The anonymous namespace is introduced to
handle cases when linker can not find the
caller. This usually happens when caller
code was not loaded by dynamic linker;
for example mono-generated code.

Bug: http://b/25844435
Bug: http://b/22548808
Change-Id: I9e5b1d23c1c75bc78548d68e79216a6a943a33cf
2015-11-23 16:13:10 -08:00
Dmitriy Ivanov
42d5fcb9f4 Introducing linker namespaces
Bug: http://b/22548808
Change-Id: Ia3af3c0a167f1d16447a3d83bb045d143319b1e1
2015-11-15 12:09:16 -08: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
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
Colin Cross
298d176813 Pass -q is zip for test
Pass -q to zip for dlext_testzip to avoid printing:
  adding: empty_file.txt (stored 0%)
on every compile.

Bug: 24409581
Change-Id: I2320f31182a9a332b3ef8b32a22561092ab5aceb
2015-09-28 15:56:18 -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
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
Dmitriy Ivanov
3fef96f827 Fix dt_runpath test.
Bfd linker produces DT_RPATH instead of DT_RUNPATH
unless --enable-new-dtags option is specified.

Bug: http://b/22560945
Change-Id: I71bdc5137b899ab736e55c5a9574cfbba8e1983b
2015-07-20 10:47:49 -07:00
Dmitriy Ivanov
7d09a8cd11 Work around compiler optimization
This makes bionic-unit-test-glibc64 behave consistently
when testing dlopen from a library with dt_runpath.

Bug: http://b/21899363
Change-Id: I9d446eb6852876975874d6b7761f6f81cc4e9916
2015-06-23 13:47:23 -07: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
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
Dmitriy Ivanov
933332462d Remove -z global workaround for target x86
Change-Id: I08e75a1c7437c97e4af59316d2c14c7fa3f65e03
2015-05-14 21:28:21 -07: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
Dmitriy Ivanov
2c256a0f09 Merge "Unregister pthread_atfork handlers on dlclose()" 2015-04-25 05:36:07 +00:00
Dmitriy Ivanov
e91e66f223 Use bfd linker for x86/x86_64 targets
ld.gold in current toolchain for x86_64
 does not support -z global.

Change-Id: Iea2b192f0f0aa998a02adb356fd4eec4e10a1739
2015-04-24 21:05:49 -07:00
Dmitriy Ivanov
ea295f68f1 Unregister pthread_atfork handlers on dlclose()
Bug: http://b/20339788
Change-Id: I874c87faa377645fa9e0752f4fc166d81fd9ef7e
2015-04-24 17:57:37 -07:00
Dmitriy Ivanov
6612d7a347 Enable dlsym_df_1_global test for arm/arm64
Change-Id: I1fdebced93175cb14053e2239e79f97239fc2dc2
2015-04-24 16:26:03 -07:00
Dimitry Ivanov
094f58fb2a Revert "Unregister pthread_atfork handlers on dlclose()"
The visibility control in pthread_atfork.h is incorrect.
 It breaks 64bit libc.so by hiding pthread_atfork.

 This reverts commit 6df122f852.

Change-Id: I21e4b344d500c6f6de0ccb7420b916c4e233dd34
2015-04-24 03:46:57 +00:00
Dmitriy Ivanov
6df122f852 Unregister pthread_atfork handlers on dlclose()
Change-Id: I326fdf6bb06bed12743f08980b5c69d849c015b8
2015-04-22 19:19:37 -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
45c57131d2 Add libdl dependency for target libraries
Fixed x86_64 target build with gcc 4.9

Change-Id: Id3b1e9286c2bcbb8e3ac117bcef957304db7cfd3
2015-04-03 15:17:52 -07: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
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
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
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
Dmitriy Ivanov
bfa88bca5c Add another test for weak-reference
This one covers undefined weak reference in .so
  referenced via JUMP_SLOT relocation.

Bug: 17526061
Change-Id: Ib8764bd30c1f686c4818ebbc6683cf42dee908b2
2014-12-16 19:46:45 +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
7699d13a74 Yet another relocation test
This time we check if a -> b -> c function in 'a' relocates against
 implementation in 'c'.

Change-Id: I528180c3efd346bd447ea0237e5a8a0ac3cc031f
2014-11-19 10:39:05 -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
9df4b13baf Fix host build for arm/arm64
Change-Id: Id92543e4080aede205b3e63099fa2baa36ba21f0
2014-11-14 12:17:06 -08:00
Dmitriy Ivanov
b3356773c6 Add test for --hash-style=sysv
With build system switched to gnu-hash we need
 a test for sysv-hashed library.

Change-Id: I34adc216fa79199aa46066cf13fcc1c1f2581f0e
2014-11-14 11:19:22 -08:00
Dmitriy Ivanov
ec18ce06f2 Add support for hash-style=gnu
Change-Id: I171434a587420895feac8a9b1ad2342087197568
2014-11-12 16:38:12 -08:00
Dmitriy Ivanov
4e446b19d8 Fix arm64 and arm builds.
Change-Id: I2c8c41626768e792f27a2616f2cd5ae66606319d
2014-10-31 17:27:02 -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
Chih-Hung Hsieh
b086298629 Disable clang compilation due to lack of ifunc.
BUG: 18055309
Change-Id: I0f36011cf7872a20ddd36a6c3c607eb96f0a8ec2
2014-10-24 11:04:51 -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
4a9e1937c5 Correct way to specify additional dependencies
Previous one was not covering all the targets

Bug: 17548097
Change-Id: I425e0f8d6e5a43feabd29dcb327049b82754d249
2014-10-17 11:47:18 -07:00
Ying Wang
667853d477 Build dlext_testzip as custom module.
Use $(BUILD_SYSTEM)/base_rules to build it as custom module, so that
it's exposed to utilities like mm/mmma etc.

Bug: 17887283
Change-Id: Idd7b62d08e4d56331a3ff15da6aa46eae8c41898
2014-10-08 16:38:58 -07:00
Dmitriy Ivanov
51166d3aa2 Fix mma build: 'cd bionic && mma' case
Bug: 17887283
Change-Id: If2015f2361348eac8c53aed3f8715077b79ce2f5
2014-10-08 15:36:56 -07:00
Dmitriy Ivanov
75d66dd9a7 Fix 2nd arch prefix application
Bug: 17887283
Change-Id: I7b3b2332212fe416d6b5f5c2e5c1e07605ba09aa
2014-10-07 09:46:46 -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
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
bf50e2645d Add Android*.mk files to additional dependencies
Bug: 17548097
Change-Id: Ie0d9c8f33459320008f561217c54eba42d283b47
2014-09-17 15:55:01 -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
eb27bbae8f Add dlfcn_test to glibc test suite.
Change-Id: I955e4f7dfcc23ea5c767f967b3532dc31663b876
2014-09-15 15:03:15 -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
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