summaryrefslogtreecommitdiff
path: root/linker/linker_main.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_main.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_main.cpp')
-rw-r--r--linker/linker_main.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/linker/linker_main.cpp b/linker/linker_main.cpp
index 59e803665..0b501a7b1 100644
--- a/linker/linker_main.cpp
+++ b/linker/linker_main.cpp
@@ -725,6 +725,13 @@ __linker_init_post_relocation(KernelArgumentBlock& args, soinfo& tmp_linker_so)
// Initialize the linker's own global variables
tmp_linker_so.call_constructors();
+ // Setting the linker soinfo's soname can allocate heap memory, so delay it until here.
+ for (const ElfW(Dyn)* d = tmp_linker_so.dynamic; d->d_tag != DT_NULL; ++d) {
+ if (d->d_tag == DT_SONAME) {
+ tmp_linker_so.set_soname(tmp_linker_so.get_string(d->d_un.d_val));
+ }
+ }
+
// When the linker is run directly rather than acting as PT_INTERP, parse
// arguments and determine the executable to load. When it's instead acting
// as PT_INTERP, AT_ENTRY will refer to the loaded executable rather than the