aboutsummaryrefslogtreecommitdiff
path: root/linker
AgeCommit message (Collapse)Author
2021-02-09Mark sh_binary target as being bp2build_available.Rupert Shuttleworth
Test: build/bazel/scripts/bp2build-sync.sh write. Change-Id: I8e8c3c95aa2c7ff6d7db3d92291f224bdf7cf255
2021-01-28Fix -Wl,--exclude-libs typo: x86->i686Ryan Prichard
These lines shouldn't actually matter, because the DSOs are using version scripts to allow-list exported symbols. Bug: none Test: bionic unit tests Change-Id: I39d3df8c4f8053624f862b3c6994e30c693e928c
2021-01-22Ensure same order of global group members in all NS'sRyan Prichard
During "step 1" of find_libraries, the linker finds the transitive closure of dependencies, in BFS order. As it finds each library, it adds the library to its primary namespace (so that, if some other library also depends on it, find_loaded_library_by_soname can find the library in the process of being loaded). LD_PRELOAD libraries are automatically marked DF_1_GLOBAL, and any DF_1_GLOBAL library is added to every linker namespace. Previously, this secondary namespace registration happened after step 1. The result is that across different namespaces, the order of libraries could vary. In general, a namespace's primary members will all appear before secondary members. This is undesirable for libsigchain.so, which we want to have appear before any other non-preloaded library. Instead, when an soinfo is added to its primary namespace, immediately add it to all the other namespaces, too. This ensures that the order of soinfo objects is the same across namespaces. Expand the dl.exec_with_ld_config_file_with_ld_preload and dl.exec_with_ld_config_file tests to cover the new behavior. Mark lib1.so DF_1_GLOBAL and use a "foo" symbol to mimic the behavior of a signal API interposed by (e.g.) libsigchain.so and a ASAN preload. Test: bionic unit tests Bug: http://b/143219447 Change-Id: I9fd90f6f0d14caf1aca6d414b3e9aab77deca3ff
2021-01-20Merge "Switch libc.so and linker to prebuilt LLVM libunwind"Ryan Prichard
2021-01-19Inline call_array for clearer stack traces.Elliott Hughes
No-one seems to understand that a crash in a random .so from call_array() in the linker isn't a linker bug. They _seem_ to understand (or at least claim to) when we explain that this is just the linker calling their ELF constructors --- despite the fact that the caller of call_array() is call_constructors(). One experiment we can try though is to inline call_array() to elide that frame from the crash dumps. I do also wonder whether renaming call_constructors() to call_elf_constructors() would help/hinder/make no difference. For now I'm leaning toward "hinder" because I suspect most people don't understand "ELF constructor" and C++ folks at least will probably be influenced in a not wholly incorrect direction when they hear "constructor" (whereas "ELF constructor" might mislead them back in the direction of "strange linker magic, not my fault" again)... (The reformatting is clang-format's decision, not mine.) Test: treehugger Change-Id: I65ab95ceb2e988fd053c48c66f51afba17ccfa61
2021-01-14Switch libc.so and linker to prebuilt LLVM libunwindRyan Prichard
For libc.so, use a special build of libunwind.a whose symbols aren't hidden ("libunwind-exported"), because libc.so exports the _Unwind_* APIs. Bug: http://b/153025717 Test: bionic unit tests Change-Id: I7435e076ec8cc4410e3e6086d3cf5d2c6011c80c
2021-01-13Delay setting linker soname until post-reloc and post-ctorRyan Prichard
Setting the linker's soname ("ld-android.so") can allocate heap memory now that the name uses an std::string, and it's probably a good idea to defer doing this until after the linker has relocated itself (and after it has called C++ constructors for global variables.) Bug: none Test: bionic unit tests Test: verify that dlopen("ld-android.so", RTLD_NOLOAD) works Change-Id: I6b9bd7552c3ae9b77e3ee9e2a98b069b8eef25ca
2021-01-11Store soname as a std::string.Elliott Hughes
Once upon a time (and, indeed, to this very day if you're on LP32) the soinfo struct used a fixed-length buffer for the soname. This caused some issues, mainly with app developers who accidentally included a full Windows "C:\My Computer\...\libfoo.so" style path. To avoid all this we switched to just pointing into the ELF file itself, where the DT_SONAME is already stored as a NUL-terminated string. And all was well for many years. Now though, we've seen a bunch of slow startup traces from dogfood where `dlopen("libnativebridge.so")` in a cold start takes 125-200ms on a recent device, despite no IO contention. Even though libnativebridge.so is only 20KiB. Measurement showed that every library whose soname we check required pulling in a whole page just for the (usually) very short string. Worse, there's readahead. In one trace we saw 18 pages of libhwui.so pulled in just for `"libhwui.so\0"`. In fact, there were 3306 pages (~13MiB) added to the page cache during `dlopen("libnativebridge.so")`. 13MiB for a 20KiB shared library! This is the obvious change to use a std::string to copy the sonames instead. This will dirty slightly more memory, but massively improve locality. Testing with the same pathological setup took `dlopen("libnativebridge.so")` down from 192ms to 819us. Bug: http://b/177102905 Test: tested with a pathologically modified kernel Change-Id: I33837f4706adc25f93c6fa6013e8ba970911dfb9
2021-01-06Use ELF notes to set the desired memory tagging level.Evgenii Stepanov
Use a note in executables to specify (none|sync|async) heap tagging level. To be extended with (heap x stack x globals) in the future. A missing note disables all tagging. Bug: b/135772972 Test: bionic-unit-tests (in a future change) Change-Id: Iab145a922c7abe24cdce17323f9e0c1063cc1321
2020-12-09linker: Enable PGOYi Kong
linker-reloc-bench shows 1.2% improvement on flame. PGO No PGO BM_linker_relocation/ real_time_mean 52215 us 52916 us Test: linker-reloc-bench --benchmark_repetitions=25 Bug: 175205560 Change-Id: I6abbbd51912f86fcf8112c024d1cf2519056bea7
2020-11-06linker: add ld.config.txt parse time to systrace.Elliott Hughes
Bug: http://b/172640358 Test: treehugger Change-Id: I9d6b7c1e200d2effb737508d3c282063edefa888
2020-10-29Merge "Make vendor_ramdisk_available."Yifan Hong
2020-10-27Make vendor_ramdisk_available.Yifan Hong
Test: pass Bug: 156098440 Change-Id: I8fe2deb8fa3b24c227202be02d8af648629cffeb
2020-10-01No global ThinLTO for linkerYi Kong
Previous CL aosp/1432874 missed one project to exclude. Test: make Change-Id: Ib39e6a86c410e35141cba17948a0f30e197ea9a3
2020-09-29No global ThinLTO for bionicYi Kong
There are multiple build breakages with bionic when we enable ThinLTO globally. Opt bionic out of ThinLTO for now. #global-thinlto-opt-out Test: TreeHugger Bug: 169004486 Change-Id: I546a8074f9c3e0ddbd01d3b7cd730e215e3c0c49
2020-09-23Enable BTI in bionic linkerTamas Petz
This patch adds support to load BTI-enabled objects. According to the ABI, BTI is recorded in the .note.gnu.property section. The new parser evaluates the property section, if exists. It searches for .note section with NT_GNU_PROPERTY_TYPE_0. Once found it tries to find GNU_PROPERTY_AARCH64_FEATURE_1_AND. The results are cached. The main change in linker is when protection of loaded ranges gets applied. When BTI is requested and the platform also supports it the prot flags have to be amended with PROT_BTI for executable ranges. Failing to add PROT_BTI flag would disable BTI protection. Moreover, adding the new PROT flag for shared objects without BTI compatibility would break applications. Kernel does not add PROT_BTI to a loaded ELF which has interpreter. Linker handles this case too. Test: 1. Flame boots 2. Tested on FVP with BTI enabled Change-Id: Iafdf223b74c6e75d9f17ca90500e6fe42c4c1218
2020-09-22Add arm64 source to linker_wrapperJiyong Park
As we enable arm64-based Bionic host target (linux_bionic_arm64), linker_wrapper is added with the corresponding source. Bug: 159685774 Test: HOST_CROSS_OS=linux_bionic HOST_CROSS_ARCH=arm64 m Test: copy out/soong/host/linux_bionic_arm64/ to an ARM64 emulator running Linux and execute the binaries Change-Id: I4f367a349f7e0015318352cb7f2870fc856eab05
2020-08-11Add a thread-properties APIVy Nguyen
(Based on proposal at https://sourceware.org/glibc/wiki/ThreadPropertiesAPI) This includes API to: - locate static and dynamic TLS - register thread-exit and dynamic TLS creation/destruction callbacks Change-Id: Icd9d29a5b2f47495395645e19d3b2c96826f19c8
2020-08-03Rename linker greylist to exempt-listRyan Prichard
Update a comment in android-changes-for-ndk-developers.md about the removed debug.ld.greylist_disabled system property. Update language to comply with Android's inclusive language guidance #inclusivefixit See https://source.android.com/setup/contribute/respectful-code for reference Bug: http://b/162536543 Test: bionic-unit-tests Change-Id: I760ee14bce14d9d799926c43d2c14fd8ffbc6968
2020-08-02Merge "linker: Cleanup for Android's inclusive language guidance"Treehugger Robot
2020-07-31linker: Cleanup for Android's inclusive language guidanceLuke Huang
1. Cleanup for #inclusivefixit. (whitelisted -> allowed_libs) 2. Support the old term for backwards compatibility. (Also update test.) 3. Fix the formatting errors found by clang-format. See https://source.android.com/setup/contribute/respectful-code for reference. Bug: 161896447 Test: atest linker-unit-tests linker-benchmarks Change-Id: I19dbed27a6d874ac0049cb7b67d2cb0f75369c1b
2020-07-30Remove debug.ld.greylist_disabled propertyRyan Prichard
This property provided a way to disable the greylist, for testing whether an app targeting < 24 still works. Instead of turning off the greylist, though, an app developer should simply target a newer API. (If app developers really need this property for testing, they can still use it on versions of Android between N and R, inclusive.) Update language to comply with Android's inclusive language guidance See https://source.android.com/setup/contribute/respectful-code for reference #inclusivefixit Bug: http://b/162536543 Test: bionic-unit-tests Change-Id: Id1eb2807fbb7436dc9ed7fe47e15b7d165a26789
2020-07-21Changes for #inclusivefixit.Elliott Hughes
Test: treehugger Change-Id: I7ff0496c5c2792a41781e74634247f55b0548213
2020-07-16Pagetable-friendly shared library address randomization.Evgenii Stepanov
Add inaccessible gaps between shared libraries to make it harder for the attackers to defeat ASLR by random probing. To avoid excessive page table bloat, only do this when a library is about to cross a huge page boundary, effectively allowing several smaller libraries to be lumped together. Bug: 158113540 Test: look at /proc/$$/maps Change-Id: I39c0100b81f72447e8b3c6faafa561111492bf8c
2020-07-06Merge "Revert "Add randomized padding around shared library mappings.""Evgenii Stepanov
2020-07-06Revert "Add randomized padding around shared library mappings."Evgenii Stepanov
This reverts commit a8cf3fef2aa2201014c35c3487da222ccfedfc1c. Reason for revert: memory regression due to the fragmentation of the page tables Bug: 159810641 Bug: 158113540 Change-Id: I6212c623ff440c7f6889f0a1e82cf7a96200a411
2020-06-30Disable warning message for missing linker config in some casesKiyoung Kim
There are some special cases - such as init process - when linker configuration is not expected to exist. This change disables warning message that generated linker configuration does not exist in those cases. Bug: 158800902 Test: Tested from cuttlefish that warning message is not generated from init Change-Id: Ie2fbb5210175cf1e6f2b7e638f57c3b74d395368
2020-06-17Add randomized padding around shared library mappings.Evgenii Stepanov
Improve ASLR by increasing the randomly sized gaps between shared library mappings, and keep them mapped PROT_NONE. Bug: 158113540 Test: look at /proc/$$/maps Change-Id: Ie72c84047fb624fe2ac8b7744b2a2d0d255ea974
2020-06-12Use PROT_NONE on the unused parts of CFI shadow.Evgenii Stepanov
This replaces a single 2Gb readable memory region with a bunch of tiny regions, and leaves the bulk of 2Gb mapped but unaccessible. This makes it harder to defeat ASLR by probing for the CFI shadow region. Sample CFI shadow mapping with this change: 7165151000-716541f000 ---p 00000000 00:00 0 [anon:cfi shadow] 716541f000-7165420000 r--p 00000000 00:00 0 [anon:cfi shadow] 7165420000-71654db000 ---p 00000000 00:00 0 [anon:cfi shadow] 71654db000-71654dc000 r--p 00000000 00:00 0 [anon:cfi shadow] 71654dc000-71654dd000 r--p 00000000 00:00 0 [anon:cfi shadow] 71654dd000-71654f0000 ---p 00000000 00:00 0 [anon:cfi shadow] 71654f0000-71654f1000 r--p 00000000 00:00 0 [anon:cfi shadow] 71654f1000-71e5151000 ---p 00000000 00:00 0 [anon:cfi shadow] This change degrades CFI diagnostics for wild jumps and casts (i.e. when the target of a CFI check is outside of any known library bounds). This is acceptable, because CFI does not have much to tell about those cases anyway. Such bugs will show up as SEGV_ACCERR crashes inside __cfi_slowpath in libdl.so from now on. Bug: 158113540 Test: bionic-unit-tests/cfi_test.* Test: adb shell cat /proc/$PID/maps | grep cfi Change-Id: I57cbd0d3f87eb1610ad99b48d98ffd497ba214b4 Merged-In: I57cbd0d3f87eb1610ad99b48d98ffd497ba214b4
2020-06-10linker: CHECK() or async_safe_fatal() rather than abort().Elliott Hughes
In particular, add the strerror() output if mprotect() fails. Fix the CHECK macro so that you can make assertions involving operator% without that being confused for a printf format specifier. Bug: https://issuetracker.google.com/158645318 Test: treehugger Change-Id: I6817f8ca5f094c52dc2c9067bfac90385a8743f5
2020-06-02Make .whitelisted property "append"-ableJooyung Han
.whitelisted is a list of sonames seperated by ":" just like .shared_libs and .paths properties. It makes sense to make it appendable using += as well ass .shared_libs and .paths. Bug: n/a Test: atest linker-unit-tests Change-Id: If61cc553c8080e8a58de8a3a6051c1853f7bfe5f
2020-05-19Refactor translateSystemPathToApexPathVictor Khimenko
This is more efficient and easier to read. Test: bionic-unit-tests --gtest_filter=*icu* Change-Id: Iddeed7cd4a1d48d8968f97951a9af004ccce52e8
2020-05-15Allow native_bridge linker to use different APEX from native oneVictor Khimenko
Bug: http://b/156397945 Test: dlfcn.dlopen_system_libicuuc_android_api_level_28 with native_bridge Change-Id: I3ecd929a0c31dda8cd424795f21f6ef472776557
2020-05-14Copy translateSystemPathToApexPath to linker_translate_path.cppVictor Khimenko
Bug: http://b/156397945 Test: m Change-Id: I33f11b8a6a41475b6cdd65e1ff49b2084c33b197
2020-05-11Merge "Move libicuuc.so into com.android.i18n module."vichang
2020-05-07Move libicuuc.so into com.android.i18n module.Victor Chang
Change the location set in the linker Bug: 130219528 Bug: 138994281 Test: atest CtsBionicTestCases Test: atest CtsJniTestCases Change-Id: I215a8e023ccc4d5ffdd7df884c809f8d12050c8f
2020-05-07Merge "Introduce a new heap tagging level, M_HEAP_TAGGING_LEVEL_SYNC."Peter Collingbourne
2020-05-05Introduce a new heap tagging level, M_HEAP_TAGGING_LEVEL_SYNC.Peter Collingbourne
The SYNC tagging level enables stack trace collection for allocations and deallocations, which allows allocation and deallocation stack traces to appear in tombstones when encountering a tag check fault in synchronous tag checking mode. Bug: 135772972 Change-Id: Ibda9f51b29d2c8e2c993fc74425dea7bfa23ab1e
2020-05-05Make Bionic and kernel system includes explicit in the blueprints.Martin Stjernholm
Before this Soong added hardcoded system include paths to bionic/libc/{include,kernel}, which won't work when Bionic libs are packaged up as prebuilts in an SDK module snapshot. Test: Build and boot Test: Check in out/verbose.log.gz that a C file doesn't get any bionic include path for linux_glibc. Bug: 153590472 Change-Id: I13c8eb3dd7150d6e0fee001b290b53fcebebcfea
2020-04-20__loader_cfi_fail: acquire g_dl_mutexRyan Prichard
CfiFail calls find_containing_library, which searches the linker's internal soinfo list, which could be modified by another thread. Bug: http://b/150372650 Test: bionic-unit-tests Change-Id: I59024a0a47913caa75702f15ec058b0a360727b5
2020-04-20android_get_exported_namespace: acquire g_dl_mutexRyan Prichard
android_get_exported_namespace searches g_exported_namespaces, which isn't modified after process initialization, but it does the search using a new std::string object, and the linker's malloc/free functions aren't thread-safe. (They're protected by the same lock (g_dl_mutex) as the rest of the linker's state.) Bug: http://b/150372650 Test: bionic-unit-tests Change-Id: Iafd12e5ab36ae61f0642aad59939f528d31bda16
2020-03-31Merge changes Ia359d9f2,Ibabbf559,I1b542e47,I4b6f48af,I82e442f0Ryan Prichard
* changes: Fix bootstrap linker library searching Remove dangling soinfo* from elf_readers_map_ Fix DL_WARN_documented_change URL remove search_linked_namespaces param Refactor linker lookup code a bit
2020-03-30Merge "Switch to debugger_process_info in bionic."Peter Collingbourne
2020-03-27Fix bootstrap linker library searchingRyan Prichard
For the bootstrap linker, insert /system/${LIB}/bootstrap in front of /system/${LIB} in any namespace search path. Bug: http://b/152572170 Test: bionic unit tests Change-Id: Ia359d9f2063f4b6fff3f79b51b500ba968a18247
2020-03-27Remove dangling soinfo* from elf_readers_map_Ryan Prichard
If ElfReader::Read fails, then it is hazardous to leave the invalid ElfReader in the soinfo*->ElfReader table, because a future soinfo object could happen to have the same address, then reuse the invalid ElfReader. I'm not sure whether this can break anything, because the linker would call ElfReader::Read on the invalid object and overwrite its previous value. Test: bionic unit tests Bug: none Change-Id: Ibabbf559443441b9caeacc34ca165feaafe5e3a7
2020-03-27Fix DL_WARN_documented_change URLRyan Prichard
The doc_link argument is really a URL fragment within the android-changes-for-ndk-developers.md document, not a filename at the root of the bionic repository. Test: manual Bug: none Change-Id: I1b542e47aca132ce43ba1d50d83db1bf3c7b10c6
2020-03-27remove search_linked_namespaces paramRyan Prichard
The search_linked_namespaces parameter to find_library_internal is always true. Bug: none Test: bionic tests Change-Id: I4b6f48afefca4f52b34ca2c9e0f4335fa895ff34
2020-03-27Refactor linker lookup code a bitRyan Prichard
Add a few _Nonnull / _Nullable annotations. Clang may use them to issue warnings but violating the annotation isn't undefined behavior. Bug: none Test: bionic tests Change-Id: I82e442f06a2c59c69bc0008f0f686785695cdd02
2020-03-18Merge "Revert "Statically link libdl.a to linker""android-r-preview-4android-r-preview-3android-r-preview-2Treehugger Robot
2020-03-18Revert "Statically link libdl.a to linker"Jooyung Han
This reverts commit 8dba7fefb0f00f697847bf0209a7289a689e80d2. Reason for revert: This workaround is not necessary with ag/10700799 Merged-In: I2bf469bfe00f3a70e67085abfb3822db6908d522 Change-Id: If351aedfce23d60582f0c5ff965f94356d1900d9 Bug: 150860940