summaryrefslogtreecommitdiff
path: root/linker/linker.cpp
AgeCommit message (Collapse)Author
2017-11-29Revert "Fix bug with double unload on unsuccessful dlopen"Elliott Hughes
This reverts commit 58554ccb8ac27fd3b5693efde2e1f7ab2a895ea2. causes /vendor/bin/qseecomd to hit the new abort: [ 8.983301] c5 603 DEBUG: Abort message: 'soinfo=0x7147894cd0 is not in soinfo_list (double unload?)' Bug: http://b/69909887 Bug: http://b/69787209 Change-Id: Ied38f797e0a071a1acc5ed41adf1b45e855143c7
2017-11-29Merge "Fix bug with double unload on unsuccessful dlopen"Dimitry Ivanov
am: dc89324e93 Change-Id: Ibff72e8a13cdc737d950dc71f2612fc99740109f
2017-11-28Fix bug with double unload on unsuccessful dlopendimitry
In the case of unsuccessful dlopen the failure guard is triggered for two namespaces which leads to double unload. Also update soinfo_free to abort in case when linker tries to free same soinfo for the second time - this makes linker behavior less undefined. Test: bionic-unit-tests Bug: http://b/69787209 Change-Id: I886787ee021b050667f967bce7aa2708390886ea
2017-11-14Merge commit 'e3d21c84af0b8e3244e4c67a873d2a16bfb85034' into HEADXin Li
Change-Id: I09b21c2e27a0dfbef10633b20d8ee7adbedc1597
2017-10-27Log dlclose calls and library unloadsdimitry
Bug: http://b/29458203 Bug: http://b/68262627 Test: make && run bionic-unit-tests Test: set debug.ld.all to dlopen and check the logs Change-Id: I9a5495843a4145f267cc3a4714294d05b1e1fe90
2017-10-23linker: fix error message for inaccessible libsdimitry
Added a test to make sure linker produces correct error message when user attempts to load a library in a linked namespace and fails. Bug: http://b/67866190 Bug: http://b/64950640 Bug: http://b/64888291 Test: bionic-unit-test --gtest_filter=dlext* Change-Id: I5b5c2070d1388eff123118350b2b5c8fc7571a29
2017-10-19Fix: linker segfault on dlopen of a DF_1_GLOBAL soJiyong Park
Added the missing null check routine. Bug: 67755729 Test: dlfcn.dlopen_df_1_global added and it passes Change-Id: Ibe8db18b0b5a481e2e9937041abef6d6b179dd87
2017-09-21Merge changes from topic "host_bionic" am: 6e6e1abb89 am: 9938cdeee8Dan Willemsen
am: 23ec4fd7e6 Change-Id: Ieb803f66f1f0f7bd29fea16df7e48f3c0195e3bf
2017-09-20Use an embedded linker for host bionicDan Willemsen
The linux kernel requires that the ELF interpreter (runtime linker) that's referenced by PT_INTERP be either an absolute path, or a relative path from the current working directory. We'd prefer a relative path from the binary, similarly to how we handle looking up shared libraries, but that's not supported. Instead, extract the LOAD segments from the runtime linker ELF binary and embed them into each host bionic binary, omitting the PT_INTERP declaration. The kernel will treat it as a static binary, and we'll use a special entry point (linker_wrapper) to fix up the arguments passed by the kernel before jumping to the embedded linker. From the linker's point of view, it looks like the kernel loaded the linker like normal. Bug: 31559095 Test: Enable host bionic, build and run libdemangle_test Change-Id: I1753401ef91eecbf0ae3376faca31eec1c53842b
2017-09-18Merge "Always log errno when aborting." am: 0c9ea17e0c am: 002b30843bElliott Hughes
am: 5d1cf56ce5 Change-Id: I1999c656307aea0a0a0372248d65a05657546e59
2017-09-15Always log errno when aborting.Elliott Hughes
(Where errno is relevant.) Also consistently use -1 as the fd for anonymous mmaps. (It doesn't matter, but it's more common, and potentially more intention-revealing.) Bug: http://b/65608572 Test: ran tests Change-Id: Ie9a207632d8242f42086ba3ca862519014c3c102
2017-08-30Merge "Explicitly name DT_RPATH." am: e0e2798f11 am: e68ca24650Elliott Hughes
am: 1b64c2c4f0 Change-Id: I59b094b9a1c76d77f01f8a25102b3e0a6dc6f257
2017-08-30Explicitly name DT_RPATH.Elliott Hughes
The specific case of finding a DT_RPATH entry is a pretty common harmless warning. An alternative to this change would be to just add a case to the switch for DT_RPATH to just silently ignore it, since it's never been supported and is deprecated anyway. Bug: N/A Test: builds Change-Id: I01986da8f1f8d411fc2ea32d492c53b9f4488c72
2017-08-24Merge "Add support of architecture specific ld.configs" am: 506f3f11f1 am: ↵Dimitry Ivanov
bfec477beb am: 595ac73b12 Change-Id: Id5e8ddaf0b6cbabf3973fa5601e0531e6d7739a0
2017-08-23Add support of architecture specific ld.configsdimitry
Prefer architecture specific ld.config.<arch>.txt if it exists; fall back to default ld.config.txt files if arch-specific one is not present. Bug: http://b/64061157 Test: bionic-unit-tests && linker-unit-tests Change-Id: I83a298a932f2e4af7acb2049a7641fb86908736c
2017-08-16Merge "Make default namespace handle the 'visible' flag." am: f2c203f188 am: ↵Justin Yun
01a2910758 am: 897b6dabef am: 07cdf5e9a6 Change-Id: Ib56be3f3b4ad716dc023be3cfec531afe29246bb
2017-08-16Make default namespace handle the 'visible' flag.Justin Yun
'visible' flag was interpreted only the namespaces other than 'default'. The flag has to be handled without exception once it is set. Bug: 63411330 Test: Build and boot without errors. Test: Add `namespace.default.visible = true` to [vendor] process in 'ld.config.txt' and reboot the device. Change-Id: Ia363dfadf0200317b875e26bb4b2fae849af1384
2017-08-03Merge "linker: the global group is added to all built-in namespaces" am: ↵Jiyong Park
c9fb66209d am: ec8c79aaa1 am: 0a51b36ad6 am: e247953f1b Change-Id: I26521ec9cc11b9ee9ce55a61ac2bfe3152a0dd7f
2017-08-03linker: the global group is added to all built-in namespacesJiyong Park
With ld.config.txt, we now have multiple built-in namespaces other than the default namespace. Libs (and their dependents) listed in LD_PRELOAD must be visible to those additional namespaces as well. This also adds a debugging only feature: path to the linker config file can be customized via LD_CONFIG_FILE environment variable. This works only for debuggable builds. Bug: 38114603 Bug: 62815515 Test: 1. ./external/compiler-rt/lib/asan/scripts/asan_device_setup --lib prebuilts/clang/host/linux-x86/clang-stable/lib64/clang/5.0/lib/linux 2. enable talkback shortcut 3. in the home screen, hold vol-up/down together 4. device does not reboots and talkback shortcut is toggled Test: bionic-unit-tests and linker-unit-tests successful Change-Id: I9a03591053f4a9caea82f0dcb23e7a3d324bb9bd
2017-07-27Fix asan path translation loading a library twice.Evgenii Stepanov
An ASan binary may load a non-ASan library from /system if /data is not mounted yet. A dlopen() call for the same library later, when /data/ is available, will translate the path and attempt to load an ASan copy of the library from /data/asan/system. This way we may end up loading both ASan and non-ASan copies of the library in the same process, which is a very bad thing. This change adds a check for a loaded library with the non-translated real path before applying path translation. Bug: 63622872 Test: hide/rename a library in /data/asan; dlopen; restore the library; dlopen; check that the library from /data/asan is NOT loaded. Change-Id: I17060837f08dc3c665cab803dd89979d88f0a019
2017-05-18Merge "Revert "linker: remove link from external library on unload"" into oc-devDimitry Ivanov
am: f80b2bae2f Change-Id: Id7e4908181fb869de30676fc5c5e6abe3d24d383
2017-05-18Revert "linker: remove link from external library on unload"Dimitry Ivanov
This reverts commit b37d10cc8017c102530c096537890b7c6215ad2b. Was merged from nyc-dev to master and oc-dev by mistake. Bug: http://b/38384727 Test: bionic-unit-tests Change-Id: I7cd352baceb3180342abb6ffec1dfa96a217961f
2017-05-16linker: remove link from external library on unload am: b37d10cc80 am: ↵Dimitry Ivanov
3a644889b2 am: cb40eec87c am: 0399816edb am: 85efd3b591 Change-Id: I115a7adb07feedf81064c0e740cfc617263eb689
2017-05-16linker: remove link from external library on unload am: b37d10cc80 am: ↵Dimitry Ivanov
3a644889b2 am: cb40eec87c am: 0399816edb am: 85efd3b591 Change-Id: I0b41cdffdccab8b79a4d9c6327dc0f6f521c1acf
2017-05-16linker: remove link from external library on unload am: b37d10cc80Dimitry Ivanov
am: 3a644889b2 Change-Id: I7c022194739391c24a736a3a5deb906433fc5649
2017-05-16linker: remove link from external library on unloadDimitry Ivanov
am: b37d10cc80 Change-Id: I48901a8fbf4bc25fff1462e6086fc23b76ca2ba3
2017-05-15linker: remove link from external library on unloadDimitry Ivanov
When unloading library make sure the soinfo_link to parent from linked external libraries is removed as well. Bug: 36104177 Bug: http://b/37433850 Test: manual Change-Id: I601b54144acecac54744805b38313c46045c54cb (cherry picked from commit ee398f820700de30941fd82e38bd917e1513cbc6)
2017-05-09greylist is no longer enabled by default.Jiyong Park
greylist is needed only for application namepaces. Since we started using linker-namesapces for vendors and other platform apps linker should not enable greylist workaround by default. Bug: http://b/37731053 Bug: https://issuetracker.google.com/38146125 Test: sailfish builds and boots Test: bionic-unit-tests and linker-unit-tests pass Change-Id: Iee83db6fb1ae754f5ade18491321d9bca3b5ead4 (cherry picked from commit e8ffe56a9c2bacc6bd880238250ad61e2bbb257b)
2017-05-08greylist is no longer enabled by default.Jiyong Park
greylist is needed only for application namepaces. Since we started using linker-namesapces for vendors and other platform apps linker should not enable greylist workaround by default. Bug: http://b/37731053 Bug: https://issuetracker.google.com/38146125 Test: sailfish builds and boots Test: bionic-unit-tests and linker-unit-tests pass Change-Id: Iee83db6fb1ae754f5ade18491321d9bca3b5ead4
2017-05-03Merge "Move libc_log code into libasync_safe."Christopher Ferris
2017-05-03Move libc_log code into libasync_safe.Christopher Ferris
This library is used by a number of different libraries in the system. Make it easy for platform libraries to use this library and create an actual exported include file. Change the names of the functions to reflect the new name of the library. Run clang_format on the async_safe_log.cpp file since the formatting is all over the place. Bug: 31919199 Test: Compiled for angler/bullhead, and booted. Test: Ran bionic unit tests. Test: Ran the malloc debug tests. Change-Id: I8071bf690c17b0ea3bc8dc5749cdd5b6ad58478a
2017-05-02Shared namespaces inherit parent ns propertiesDimitry Ivanov
Make shared namespace inherit namespace links and search/permitted paths from the parent namespace. Bug: http://b/37854032 Test: bionic_unit_tests --gtest_filter=dl*:Dl* Change-Id: I174661d4a1dd0cbe4a378179073719aa955f3592 (cherry picked from commit ec43dd6c36d75014c4e4dc592dd67ab20033a76a)
2017-05-02Shared namespaces inherit parent ns propertiesDimitry Ivanov
Make shared namespace inherit namespace links and search/permitted paths from the parent namespace. Bug: http://b/37854032 Test: bionic_unit_tests --gtest_filter=dl*:Dl* Change-Id: I174661d4a1dd0cbe4a378179073719aa955f3592
2017-05-02Merge "linker: add android_get_exported_namespace"Treehugger Robot
2017-04-28linker: add android_get_exported_namespaceJiyong Park
Depending on how ld.config.txt is configured, there can be multiple built-in namespaces created by the linker from the beginning of a process. android_get_exported_namespace is a platform only API for getting a handle (android_namespace_t*) to one of the built-in namespaces with given name. The returned namespace can then be given to android_dlopen_ext in order to explicitly specify the target namespace where the library is searched and loaded from. Note that this function only returns 'exported' namespaces created via ld.config.txt file. In order to export a namespace, the visible property should be set to true: namespace.<name>.visible = true Namespaces are hidden by default. Hidden namespaces and namespaces that are created programmatically, notably 'classloader-namespace', aren't returned by this function. Bug: 36851137 Test: confirmed that namespaces created with ld.config.txt is retrieved. Test: linker-unit-tests passes Merged-in: I714b510fa24f77e42c3dfc4c827b3befa8bb2951 Change-Id: I0d05fa7e0e116009edf8ea362ab46774bc617cbf (cherry picked from commit d7c4832e6a640be972017e85ab21e72950dfeddd)
2017-04-24Revert "Revert "loader: enable loading libraries from tmpfs""Dimitry Ivanov
This reverts commit 6d59318d78553c32c8f2f43ee48ec3bebace8e86. Bug: http://b/37245203 Bug: http://b/37590327 Test: bionic-unit-tests on angler and marlin Test: boot an angler and make sure mediacodec does not crash
2017-04-22Revert "loader: enable loading libraries from tmpfs"Yin-Chia Yeh
This reverts commit bb8b22a087db32773f1a9cd3473061f3ad714afc. http://b/37245203 http://b/37590327 Change-Id: I36f45697f7478b830947d641942e453ed0d5466e
2017-04-21loader: enable loading libraries from tmpfsDimitry Ivanov
This change adds two tests for dlopen from temporary files. 1. One Uses memfd_create() can be used to load libraries directly from memory. This requires relaxing namespace accessibility check in order to make this work in isolated namespaces. 2. Another checks that open with O_TMPFILE works. Bug: http://b/37245203 Test: bionic-unit-tests --gtest_filter=dl*:Dl* Change-Id: I3be1d7198ca17e7f1ba022a0d86c64d59a493506 (cherry picked from commit bb8b22a087db32773f1a9cd3473061f3ad714afc)
2017-04-21loader: enable loading libraries from tmpfsDimitry Ivanov
This change adds two tests for dlopen from temporary files. 1. One Uses memfd_create() can be used to load libraries directly from memory. This requires relaxing namespace accessibility check in order to make this work in isolated namespaces. 2. Another checks that open with O_TMPFILE works. Bug: http://b/37245203 Test: bionic-unit-tests --gtest_filter=dl*:Dl* Change-Id: I3be1d7198ca17e7f1ba022a0d86c64d59a493506
2017-04-21Make the _Unwind_Ptr declaration match clang's.Elliott Hughes
Bug: https://issuetracker.google.com/37126620 Test: builds, boots angler Change-Id: I7d4a9b998f2e5c4c7b0beed87807d7b76a564c5c
2017-04-11Merge "Send developers straight to the text relocation docs."Treehugger Robot
2017-04-10Send developers straight to the text relocation docs.Elliott Hughes
It's been years since we allowed text relocations, but I had a developer ask me how to fix them at last week's O Developer Day. They'd never seen our docs, so let's try to fix that for anyone else who's still confused... Bug: N/A Test: builds Change-Id: I9202a7b0a3f024041b646c43c87585f4fab22d09
2017-04-06Merge "Move scopeguard into android::base"Tom Cherry
2017-04-06linker: add android_get_exported_namespaceJiyong Park
Depending on how ld.config.txt is configured, there can be multiple built-in namespaces created by the linker from the beginning of a process. android_get_exported_namespace is a platform only API for getting a handle (android_namespace_t*) to one of the built-in namespaces with given name. The returned namespace can then be given to android_dlopen_ext in order to explicitly specify the target namespace where the library is searched and loaded from. Note that this function only returns 'exported' namespaces created via ld.config.txt file. In order to export a namespace, the visible property should be set to true: namespace.<name>.visible = true Namespaces are hidden by default. Hidden namespaces and namespaces that are created programmatically, notably 'classloader-namespace', aren't returned by this function. Bug: 36851137 Test: confirmed that namespaces created with ld.config.txt is retrieved. Test: linker-unit-tests passes Change-Id: I0d05fa7e0e116009edf8ea362ab46774bc617cbf
2017-04-06Add support for disabling the greylist.Elliott Hughes
Useful for testing whether apps have actually stopped using greylisted libraries even if they still have references to them in their apk to support old Android releases but also haven't bumped their targetSdkVersion yet. Since we already have two expensive __system_property_get calls and this would add a third, optimize two (but leave the third since it's not obviously amenable to optimization). None of this matters for user builds, but I don't want userdebug/eng to have distractingly different performance. (cherrypick of 7933bec2872aa1c3430149c7649726333c0ac9d8.) Bug: http://b/36106661 Test: ran "can you escape 5" with and without this property Change-Id: Id9a804695c1dca9b4be2ebd0e72f01817bb13cba
2017-04-05Move scopeguard into android::baseTom Cherry
Test: boot bullhead, bionic unit tests Change-Id: I223249684867655ecb53713b10da41d3014f96ae
2017-04-05Add support for disabling the greylist.Elliott Hughes
Useful for testing whether apps have actually stopped using greylisted libraries even if they still have references to them in their apk to support old Android releases but also haven't bumped their targetSdkVersion yet. Since we already have two expensive __system_property_get calls and this would add a third, optimize two (but leave the third since it's not obviously amenable to optimization). None of this matters for user builds, but I don't want userdebug/eng to have distractingly different performance. Bug: http://b/36106661 Test: ran "can you escape 5" with and without this property Change-Id: Id9a804695c1dca9b4be2ebd0e72f01817bb13cba
2017-04-01Fix lookup logic for linked namespacesDimitry Ivanov
When looking for already loaded libraries include linked namespaces to the search, but check if the library is accessible from the main namespace. Bug: http://b/36008422 Bug: http://b/35417197 Bug: http://b/34052337 Bug: http://b/36660652 Bug: https://issuetracker.google.com/36636090 Test: run bionic-unit-tests --gtest_filter=dl*:Dl* Change-Id: Ic7c1d48114da3ca5dc6512ef03f595dd17b6ed17 (cherry picked from commit d3e7d088453e089b3d625b0864ccdf3c74893f18)
2017-04-02Merge "Fix lookup logic for linked namespaces"Treehugger Robot
2017-03-31Refactor sanitized library on-disk layout - bionic.Vishwath Mohan
This CL changes the linker to point to the newly refactored location of ASAN-ified libraries on disk. This supports changes made by the following CLs - https://android-review.googlesource.com/#/c/359087/ https://android-review.googlesource.com/#/c/359389/ Which refactor the on-disk location as follows: /data/lib* --> /data/asan/system/lib* /data/vendor/* --> /data/asan/vendor/* There are a couple of advantages to this, including better isolation from other components, and more transparent linker renaming and SELinux policies. (cherry picked from commit 4113def4fa1526f1823549f6cc9cfe4c05964aa3) Bug: 36574794 Bug: 36674745 Test: m -j40 && SANITIZE_TARGET="address" m -j40 and the device boots. All sanitized libraries are correctly located in /data/asan/*. Change-Id: Iad8b298a66c38eb0f6327f6b51027f0728aa7a40