summaryrefslogtreecommitdiff
path: root/linker/linker.cpp
diff options
context:
space:
mode:
authorRyan Prichard <rprichard@google.com>2021-01-12 23:09:10 -0800
committerRyan Prichard <rprichard@google.com>2021-01-13 17:48:05 -0800
commitbb1e37358f142428714d829681f8e767d6170db3 (patch)
treedfeb40d49cfc271f9fe42a6108b0545d7734c9d8 /linker/linker.cpp
parentb4fd07297606de111c10d0f9a000fdb1e2280387 (diff)
Delay setting linker soname until post-reloc and post-ctor
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
Diffstat (limited to 'linker/linker.cpp')
-rw-r--r--linker/linker.cpp35
1 files changed, 18 insertions, 17 deletions
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 77824f615..c240c5639 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -3193,26 +3193,27 @@ bool soinfo::prelink_image() {
return false;
}
- // second pass - parse entries relying on strtab
- for (ElfW(Dyn)* d = dynamic; d->d_tag != DT_NULL; ++d) {
- switch (d->d_tag) {
- case DT_SONAME:
- set_soname(get_string(d->d_un.d_val));
- break;
- case DT_RUNPATH:
- set_dt_runpath(get_string(d->d_un.d_val));
- break;
+ // Second pass - parse entries relying on strtab. Skip this while relocating the linker so as to
+ // avoid doing heap allocations until later in the linker's initialization.
+ if (!relocating_linker) {
+ for (ElfW(Dyn)* d = dynamic; d->d_tag != DT_NULL; ++d) {
+ switch (d->d_tag) {
+ case DT_SONAME:
+ set_soname(get_string(d->d_un.d_val));
+ break;
+ case DT_RUNPATH:
+ set_dt_runpath(get_string(d->d_un.d_val));
+ break;
+ }
}
}
- // Before M release linker was using basename in place of soname.
- // In the case when dt_soname is absent some apps stop working
- // because they can't find dt_needed library by soname.
- // This workaround should keep them working. (Applies only
- // for apps targeting sdk version < M.) Make an exception for
- // the main executable and linker; they do not need to have dt_soname.
- // TODO: >= O the linker doesn't need this workaround.
- if (soname_.empty() && this != solist_get_somain() && (flags_ & FLAG_LINKER) == 0 &&
+ // Before M release, linker was using basename in place of soname. In the case when DT_SONAME is
+ // absent some apps stop working because they can't find DT_NEEDED library by soname. This
+ // workaround should keep them working. (Applies only for apps targeting sdk version < M.) Make
+ // an exception for the main executable, which does not need to have DT_SONAME. The linker has an
+ // DT_SONAME but the soname_ field is initialized later on.
+ if (soname_.empty() && this != solist_get_somain() && !relocating_linker &&
get_application_target_sdk_version() < 23) {
soname_ = basename(realpath_.c_str());
DL_WARN_documented_change(23, "missing-soname-enforced-for-api-level-23",