summaryrefslogtreecommitdiff
path: root/linker/linker.cpp
AgeCommit message (Collapse)Author
2019-10-24Load /dev/linker/ld.config.txt by defaultKiyoung Kim
Linker config generator now covers ld.config.txt for Legacy and VNDK-Lite devices, so linker can use those instead of existing ones under /system/etc Bug: 139638519 Test: m -j passed Change-Id: I90f14727148cbf9629b90dc4fd78362bed8ea4e4
2019-10-19Merge changes Ia0c0018c,I2f1fc8b4,Ibe964c3b,I791da8acRyan Prichard
* changes: linker: stop relocating R_ARM_REL32 Factor out R_GENERIC_COPY Factor out R_GENERIC_ABSOLUTE Remove broken arm64 PREL/ABS relocations
2019-10-18linker: stop relocating R_ARM_REL32Ryan Prichard
This relocation is labeled as a static relocation in the ARM ELF ABI and shouldn't appear in position-independent code. It currently calculates the value to relocate incorrectly: "sym_addr - rel->r_offset" should be "sym_addr - reloc" I don't know of any other dynamic linker that handles this relocation. Test: bionic unit tests Bug: http://b/19197129 Change-Id: Ia0c0018c82fe98d5edb54ee6f5c9f402b1fa3076
2019-10-18Factor out R_GENERIC_COPYRyan Prichard
Test: bionic unit tests Bug: none Change-Id: I2f1fc8b4b9832f892e5cf13a3c685854de07a8d3
2019-10-18Factor out R_GENERIC_ABSOLUTERyan Prichard
Combine: - R_AARCH64_ABS64 - R_ARM_ABS32 - R_X86_64_64 - R_386_32 They do mostly the same thing as R_GENERIC_GLOB_DAT. They always have an addend, though, and R_GENERIC_GLOB_DAT currently only has an addend on RELA targets. Test: bionic unit tests Bug: none Change-Id: Ibe964c3b28705086aecb6e7d80c90998aad3c0a4
2019-10-17Remove broken arm64 PREL/ABS relocationsRyan Prichard
Specifically, remove: - R_AARCH64_ABS32 - R_AARCH64_ABS16 - R_AARCH64_PREL64 - R_AARCH64_PREL32 - R_AARCH64_PREL16 These relocations never currently appear in dynamic ELF files, and the linker didn't handle them correctly. The AArch64 ELF ABI document classifies them as "static relocations", which dynamic linkers don't need to handle. (The document also classifies R_AARCH64_ABS64 as static, though, and that relocation is common in DSOs. Perhaps static linkers can't use R_AARCH64_GLOB_DAT to relocate data outside the GOT.) Previously, for {ABS,PREL}{32,16}, Bionic always failed with an out-of-range error. e.g. For {ABS,PREL}16, the value had to satisfy two conditions: - be at least (Elf64_Addr)INT16_MIN, i.e. 0xffff_ffff_ffff_8000 - be at most (Elf64_Addr)UINT16_MAX, i.e. 0xffff The PREL relocations should have used sym_addr + addend - reloc, not sym_addr + addend - rel->r_offset. Bug: http://b/19197129 Test: bionic unit tests Change-Id: I791da8ac471b3fb108cf77405c222f6e4bd34ae4
2019-10-16Revert "Change linker config variable: VNDK_VER"Jooyung Han
This reverts commit e30a7f5d1f00f4571c4a6ea9766fd22a6be27904. Reason for revert: some targets are broken Bug: 142773030 Change-Id: I651ef00a9d1aaac6f0119d31712fb588d8aa68f0
2019-10-11Change linker config variable: VNDK_VERJooyung Han
With VNDK APEX, the path for VNDK libs has been changed from /system/lib/vndk-VER to /apex/com.android.vndk.vVER/lib Previously, VNDK_VER is replaced with prefix(e.g. "-29"). We could still prepend prefix("v") to the vndk version, but this change uses a raw vndk version as the value of VNKD_VER. Bug: 141451661 Test: m && boot (tested with cuttlefish) Change-Id: Ibf4cf5e29b7f28e733d4b3bc15171f4359e1d2f2
2019-09-26Merge "Use generated linker config by default"Kiyoung Kim
2019-09-24Remove libvorbisdec from greylist.Dongwon Kang
Test: build and boot. Checked libvorbisdec.so is not in /system/lib[64] Bug: 141257741 Change-Id: Id9d9f691d5e5fa089a9d98a1be49754c8355202f
2019-09-23Use generated linker config by defaultKiyoung Kim
Use generated linker config by default, but with some back up plan (sys.linker.use_generated_config property). Linker config generator still does not support non-treblelized devices and vndk-lite, so these cases should be handled later. Bug: 138920271 Test: m -j && atest passed Test: Tested from cuttlefish Change-Id: I39e9d089a82f9409eccdcaa4fb26660caf3f5779
2019-09-05Add more linker debug log.Martin Stjernholm
Main change is to log errors directly where they occur, to correlate with other dlopen/dlsym logs. Test: Build & boot with and without LinkerLogger::flags_ initialised to kLogDlopen Change-Id: If36f52914dc97cedd95dc9375c291640c6891728
2019-08-29Update references to the new com.android.art APEX.Martin Stjernholm
Test: Flash & boot Test: atest CtsJniTestCases CtsBionicTestCases Bug: 135753770 Exempt-From-Owner-Approval: Approved internally Change-Id: I1c16a798edc494e75b9d703990de08e60686a3ea Merged-In: I1c16a798edc494e75b9d703990de08e60686a3ea
2019-08-22Add additional dl_phdr_info fieldsRyan Prichard
Previously, Bionic's dl_phdr_info only included the first four dl_iterate_phdr fields. Several other libc's have these additional fields: unsigned long long dlpi_adds -- incremented when a library is loaded unsigned long long dlpi_subs -- incremented when a library is unloaded size_t dlpi_tls_modid -- TLS module ID void* dlpi_tls_data -- pointer to current thread's TLS block or NULL These extra fields are also exposed by glibc, musl, and FreeBSD. The unwinder in libgcc.a, linked into shipping Android DSOs, has a PC->eh_frame cache that activates if dl_phdr_info has the dlpi_adds and dlpi_subs fields (indicated at run-time by a sufficiently-large size argument to the callback). Bug: https://github.com/android-ndk/ndk/issues/1062 Test: bionic unit tests Change-Id: I6f0bab548cf8c828af2ddab9eb01c5c6d70cd81f
2019-08-16Merge "Fix a few bionic test failures caused by hwasan global instrumentation."Peter Collingbourne
2019-08-15Fix a few bionic test failures caused by hwasan global instrumentation.Peter Collingbourne
The call to the load hook needs to be moved before the call to link_image() because the latter calls ifunc resolvers which might access global variables. This fixes a bunch of ifunc tests. The dlfcn.segment_gap test is currently failing. One problem is that the name of the .bss.end_of_gap section changes as a result of global instrumentation. Add some wildcards in so that we match both names. The other problem seems to be the same as b/139089152. It turns out that we need to untag pointers in a few more places. Since we have quite a few of these now it seems worth creating a function for it. Test: bionic-unit-tests Change-Id: I44e2b0904faacdda7cc0c5e844ffc09de01dea2d
2019-08-14Merge "Use generated linker config"Kiyoung Kim
2019-08-14Merge "Don't create anonymous namespace"Jiyong Park
2019-08-08Don't create anonymous namespaceJiyong Park
Anonymous namespace is not created separately. When a regular namespace is created with ANDROID_NAMESPACE_TYPE_ALSO_USED_AS_ANONYMOUS, that namespace is used as the anonymous namespace. Bug: 130388701 Test: CtsBionicTestCases Change-Id: Ie449a59f303487a7a9ff6fff98e6148e9f968fd2
2019-08-07Use generated linker configKiyoung Kim
Linker config now generates ld.config.txt under /dev/linkerconfig from init. To use this, this change updates linker to pick up /dev/linkerconfig/ld.config.txt if system property (sys.linker.use_generated_config) is true. Bug: 138920271 Test: m -j && tested from cuttlefish Change-Id: I0f527741ace2d512b45fd72c301aa4cfcfe17a71
2019-08-05linker: Add library load and unload hooks for HWASan.Peter Collingbourne
These hooks notify the HWASan runtime library whenever a library is loaded or unloaded so that it can update its shadow memory. Bug: 138159093 Test: walleye_hwasan-userdebug boots with+without https://reviews.llvm.org/D65770 Change-Id: I6caf2a6540ed2c0d94db444e806a3c7ba504cabb
2019-07-30Enable traditional TLS accesses on arm64Ryan Prichard
Handle generic DTPMOD/DTPREL relocations on arm64. Expose __tls_get_addr. Bug: http://b/123385182 Test: manual -- compile code using arm64 gcc -mtls-dialect=trad Change-Id: I99d2faae35d1ebffc1be8de50b4a1f5e21b14348
2019-07-25linker: Speed up relocation with an 1-entry symbol cacheVic Yang
When relocating a DSO, it is not unusual to have consecutive relocations using the same symbol. In this case, it is wasteful to perform the same symbol lookup. This change implements an 1-entry symbol cache so that symbol lookup results are reused in such scenario. Test: On cuttlefish, enable STATS in linker_debug.h. Boot and see RELO STATS in logcat showing cache hits. Hit rate seen is mostly within 15% to 45%. Change-Id: I84783d3b9a6ac9e39ed7fb45e58f6b3c012478d0
2019-07-25Fix linker compilation when STATS is setVic Yang
Test: Compiles with STATS set in linker_debug.h Change-Id: I8ea6ca9a61ad316473dab51999885008f2721cee
2019-07-02Use an APEX's linker configuration for any executable under its `bin` directory.Roland Levillain
Previously, the linker configuration of an APEX would only be used for executables located exactly in its `bin` directory. This change relaxes this condition to also include executables located in any directory under the APEX's `bin` directory. This change is needed to support APEX binaries located in directories under the APEX's `bin` directory that need to use the APEX's linker configuration (e.g. ART gtests located in `bin/art/{arm,arm64,x86,x86-64}` in the Testing Runtime APEX). Test: Run ART gtests on device using the Testing Runtime APEX Bug: 129534335 Change-Id: I0eac317eba856211a344fa00e66640aae10816ea
2019-06-04linker: Speed up find_loaded_library_by_inode()Vic Yang
Rearrange the st_dev and st_ino checks to reduce the number of comparison needed. Test: Ran cameraserver on a Go device. Measured time spent in the linker and saw ~1% speed-up. Change-Id: I8e977ff37925eae3ba8348e7c4a01ce8af3b9b6d
2019-05-30Merge "Staticlly allocate string buffers for realpath_fd()"Treehugger Robot
2019-05-17Merge "Add bootstrap directory to bootstrap linker's search path."Peter Collingbourne
2019-05-16Add bootstrap directory to bootstrap linker's search path.Peter Collingbourne
A proposed set of changes: https://android-review.googlesource.com/q/topic:"no-dup-hwasans" will cause the HWASAN runtime to be moved from /system/lib64 to /system/lib64/bootstrap. This causes a problem in the case where libc is built with HWASAN but init is not built with HWASAN. In this case, libc.so will have a DT_NEEDED dependency on the HWASAN runtime but init will not. Currently, init and other bootstrap executables arrange to load bootstrap libraries by setting rpath, but rpath only has an effect on libraries directly depended on by the main executable, not libraries indirectly depended on by it. This means that the loading of the HWASAN runtime will fail. Instead of relying on rpath to find the bootstrap libraries, modify the bootstrap linker so that it searches the bootstrap library directory after searching the rpath. Change-Id: I297be32e04ecd316ee12b8e694588e1249e2bb89
2019-05-16Staticlly allocate string buffers for realpath_fd()Vic Yang
Creating two huge buffers with std::vector, as it is now, is very expensive, because it ends up being satisfied with mmap()/munmap(). Instead, we statically allocate a large string buffer while resizing the other one to be a smaller and more appropriate size so that it can be placed on the stack. Note that this does mean that we increase linker data segment by 4KB and that increases the overall system memory usage by about 400KB. However, since that additional page is mostly zeroed with only some ASCII text, it should be fairly easy to compress when it's swapped out to ZRAM. Test: Run with strace and observe no mmap/munmap around readlinkat(). Test: Measure average linker time of starting cameraserver on a Go device and see ~3% speed-up. Bug: 132783386 Change-Id: I600cc7a92be316ef67440a9a28c05d18de229f6c
2019-05-09linker: support ldd(1)-like behavior via --list.Elliott Hughes
Given that we have both linker and linker64, I didn't really want to have to have ldd and ldd64, so this change just adds the --list option to the linkers and a shell script wrapper "ldd" that calls the appropriate linker behind the scenes. Test: adb shell linker --list `which app_process32` Test: adb shell linker64 --list `which date` Test: adb shell ldd `which app_process32` Test: adb shell ldd `which date` Change-Id: I33494bda1cc3cafee54e091f97c0f2ae52d1f74b
2019-05-03Track libziparchive API change.Elliott Hughes
Bug: http://b/129068177 Test: treehugger Change-Id: Ieccd528a34b66de59fad78586dead6b1df9cae98
2019-04-22Merge "Only write main library's RELRO by default."Treehugger Robot
2019-04-11Only write main library's RELRO by default.Torne (Richard Coles)
ANDROID_DLEXT_WRITE_RELRO was inadvertently writing out the RELRO section of all libraries loaded during a given dlopen() call instead of only the main library; since the other libraries are loaded at unpredictable addresses this additional data is rarely useful. Fix this to only happen when the ANDROID_DLEXT_RESERVED_ADDRESS_RECURSIVE flag is being used. Bug: 128623590 Test: DlExtRelroSharingTest.CheckRelroSizes Change-Id: I05e8651d06ce2de77b8c85fe2b6238f9c09691ad
2019-04-04Merge changes I59a8bc4a,Ic437d352Ryan Prichard
* changes: Fix dlsym and dladdr for TLS symbols Fix BionicAllocator comment
2019-04-03Fix dlsym and dladdr for TLS symbolsRyan Prichard
* dlsym: call __tls_get_addr for TLS symbols * dladdr: skip TLS symbols Bug: b/123772574 Test: bionic unit tests Change-Id: I59a8bc4a7d455e1018b0d577b027b6417c8487cd
2019-04-02Fix DLEXT_WRITE_RELRO when loading multiple libs.Torne (Richard Coles)
ANDROID_DLEXT_WRITE_RELRO was causing the GNU RELRO sections of libraries to become corrupted if more than one library was being loaded at once (i.e. if the root library has DT_NEEDED entries for libraries that weren't already loaded). The file offset was not being correctly propagated between calls, so after writing out the (correct) RELRO data to the file, it was mapping the data at file offset 0 for all libraries, which corrupted the data for all but one of the libraries. Fix this by passing file_offset as a pointer the same way that phdr_table_map_gnu_relro does. Bug: 128623590 Test: tbd Change-Id: I196cd336bd5a67454e89fd85487356b1c7856871
2019-03-20linker: Add support for "whitelisted" property in linker config filesVic Yang
In order to enable no-vendor-variant VNDK, we need a way to restrict a namespace to only a list of whitelisted libraries. We add a new "whitelisted" property for this. If the property is not set, all libraries in the search paths are available in a namespace. If the property is set, only the libraries named are available. Bug: 119423884 Test: Boot with no-vendor-variant VNDK enabled using the new property. Change-Id: Id808c1733c8e2c2c3462b04c72461f9698403571
2019-03-19Add more linker debug.Martin Stjernholm
- Show which executable is being linked, which linker config file is being read, and which section in it is being used with, enabled on $LD_DEBUG>=1. - Show more info to follow the dlopen() process, enabled with "dlopen" in the debug.ld.xxx property. Test: Flash, boot, and look at logcat after "adb shell setprop debug.ld.all dlopen" Bug: 120430775 Change-Id: I5441c8ced26ec0e2f04620c3d2a1ae860b792154
2019-03-11Allow building the linker with -O0Ryan Prichard
The tlsdesc_resolver_dynamic function is only defined on arm64, but the code was taking its address on all targets. (Apparently the optimizer was removing the entire deferred_tlsdesc_relocs loop?) Bug: none Test: bionic unit tests Test: add -O0 to cc_defaults in linker/Android.bp, device boots Change-Id: I899c78018cbe82aeaca7856c9f7b04300c1d3196
2019-03-08linker: Handle libraries with disjoint mappings correctly.Peter Collingbourne
It's possible and sometimes beneficial for a library to have disjoint mappings and for other libraries to be mapped into the gap between the mappings using ANDROID_DLEXT_RESERVED_ADDRESS. See for example the proposal for partitioning in lld [1]. Because the find_containing_library and do_dl_unwind_find_exidx functions use a simple bounds check to figure out whether a pointer belongs to a library they will, given a pointer into a library mapped into the gap of a library with disjoint mappings, return a pointer to the soinfo for the outer library instead of the inner one, because the outer library will appear before the inner one in the solist. From a user perspective this means that we won't be able to unwind the inner library's frames on 32-bit ARM with libgcc, dladdr() will return information for the outer library given a pointer to the inner one and dlopen() et al will use the linker namespace of the outer library when called from the inner one (although they will usually be the same). To make this work correctly, make it so that once find_containing_library sees a match for the bounds check, it examines the library's PT_LOADs to make sure that there is a mapping for the given address. This is similar to how libgcc and libunwind_llvm already handle finding the PT_GNU_EH_FRAME on non-ARM32 platforms [2,3]. do_dl_unwind_find_exidx is reimplemented in terms of find_containing_library. [1] http://lists.llvm.org/pipermail/llvm-dev/2019-February/130583.html [2] https://github.com/llvm/llvm-project/blob/e739ac0e255597d818c907223034ddf3bc18a593/libunwind/src/AddressSpace.hpp#L523 [3] https://android.googlesource.com/toolchain/gcc/+/master/gcc-4.9/libgcc/unwind-dw2-fde-dip.c#294 Test: /data/nativetest{,64}/bionic-unit-tests/bionic-unit-tests on walleye-userdebug Change-Id: I368fe6ad3c470b3dff80f7d9b04253566d63a7d2
2019-02-21Merge "linker: allow using reserved space for multiple libraries."Treehugger Robot
2019-02-20linker: allow using reserved space for multiple libraries.Torne (Richard Coles)
Introduce a new flag ANDROID_DLEXT_RESERVED_ADDRESS_RECURSIVE which instructs the linker to use the reserved address space to load all of the newly-loaded libraries required by a dlopen() call instead of only the main library. They will be loaded consecutively into that region if they fit. The RELRO sections of all the loaded libraries will also be considered for reading/writing shared RELRO data. This will allow the WebView implementation to potentially consist of more than one .so file while still benefiting from the RELRO sharing optimisation, which would otherwise only apply to the "root" .so file. Test: bionic-unit-tests (existing and newly added) Bug: 110790153 Change-Id: I61da775c29fd5017d9a1e2b6b3757c3d20a355b3
2019-02-19Merge "Redirect /system/lib/libicuuc.so regardless of duplication in /system"vichang
2019-02-13Redirect /system/lib/libicuuc.so regardless of duplication in /systemVictor Chang
The change is a workaround of app compat issue until the app fixes the issue. Likely, the app does not only dlopen(), but open() the libicuuc.so with the absolute path. Note that platform uses the stub libandroidicu.so, not libicuuc directly. This CL topic moves (not duplicates) libandroidicu from /system to /apex. Even though /system/lib/libicuuc.so is kept in the default namespace, but no one should be using it. Some debug info after this CL: $ adb shell cat /proc/<zygote pid>/maps | grep libicuuc $ adb shell cat /proc/<app pid>/maps | grep libicuuc Only /apex/com.android.runtime/lib64/libicuuc.so is found, not the /system. Bug: 124218500 Test: The app can be launched successfully Test: CtsJniTestCases Change-Id: I67a50f0ad934be567a63d4038215546c9b4e5f7e
2019-02-12Greylist libraries are attempted to be loaded in the default nsJiyong Park
Some of the greylist libraries can be in directories other than /system/lib. For example, libnativehelper.so is moved from the directory to /apex/com.android.runtime/lib. Previous behavior for greylist libraries is to find the lib under /system/lib while "within" the current namespace which is usually the classloader-namespace. Since the libs no longer exist there, linker fails to load it and no further attempt is made. This change fixes the problem by loading the greylist libs "from" the default namespace. Since there is a link from the default namespace to the namespace where the moved libraries are intended to be loaded (e.g., the 'runtime' namespace for libnativehelper.so), the call is successful. Bug: 124201397 Test: bionic-unit-tests Change-Id: I11d15993d18896bdf663c408f9e40d8a607c9b80
2019-02-07Revert "Revert "Allow dlopen("/system/lib/<soname>") for pre-Q""Victor Chang
This reverts commit 1906e77665758c61b0d97c35f3d64225f296504a and fixes dlopen(nullptr) It's enabled for the following .so libraries libicuuc.so libicui18n.so This CL does not move the .so files into a APEX. Thus, no visible effect before moving .so files. Bug: 121248172 Test: dlfcn#dlopen_from_nullptr Test: Perform the following test after moving libicuuc to /apex dlopen("/system/lib64/libicuuc.so") for targetSdkVersion < Q Change-Id: Ia310ea566485fe00ca28e2203f4bffbd92243638
2019-02-06Merge "Revert "Allow dlopen("/system/lib/<soname>") for pre-Q""vichang
2019-02-06Revert "Allow dlopen("/system/lib/<soname>") for pre-Q"vichang
This reverts commit f6e4cfd933ec94f830b2d5074d9737ae236e3bf4. Reason for revert: b/123972211 Change-Id: I1ea199c27e224bbd27dee7692f9f448ca9c2b6d1
2019-02-05Merge "Allow dlopen("/system/lib/<soname>") for pre-Q"vichang