summaryrefslogtreecommitdiff
path: root/linker/linker.cpp
diff options
context:
space:
mode:
authorRyan Prichard <rprichard@google.com>2019-11-01 17:18:28 -0700
committerRyan Prichard <rprichard@google.com>2019-11-05 13:37:51 -0800
commit249757bae2b45c845feddee2ba9f794a54d8ea14 (patch)
tree5e727eef8f9a29cbf52516b119c407cbfb7cb3a8 /linker/linker.cpp
parent80e40f01c83850d8d5f9753ed165bab310f9c865 (diff)
Use ifuncs in the linker
Using ifuncs allows the linker to select faster versions of libc functions like strcmp, making linking faster. The linker continues to first initialize TLS, then call the ifunc resolvers. There are small amounts of code in Bionic that need to avoid calling functions selected using ifuncs (generally string.h APIs). I've tried to compile those pieces with -ffreestanding. Maybe it's unnecessary, but maybe it could help avoid compiler-inserted memset calls, and maybe it will be useful later on. The ifuncs are called in a special early pass using special __rel[a]_iplt_start / __rel[a]_iplt_end symbols. The linker will encounter the ifuncs again as R_*_IRELATIVE dynamic relocations, so they're skipped on the second pass. Break linker_main.cpp into its own liblinker_main library so it can be compiled with -ffreestanding. On walleye, this change fixes a recent 2.3% linker64 start-up time regression (156.6ms -> 160.2ms), but it also helps the 32-bit time by about 1.9% on the same benchmark. I'm measuring the run-time using a synthetic benchmark based on loading libandroid_servers.so. Test: bionic unit tests, manual benchmarking Bug: none Merged-In: Ieb9446c2df13a66fc0d377596756becad0af6995 Change-Id: Ieb9446c2df13a66fc0d377596756becad0af6995 (cherry picked from commit 772bcbb0c2f7a87b18021849528240ef0c617d94)
Diffstat (limited to 'linker/linker.cpp')
-rw-r--r--linker/linker.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/linker/linker.cpp b/linker/linker.cpp
index eedce7029..1393eb521 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -3162,7 +3162,10 @@ bool soinfo::relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& r
TRACE_TYPE(RELO, "RELO IRELATIVE %16p <- %16p\n",
reinterpret_cast<void*>(reloc),
reinterpret_cast<void*>(load_bias + addend));
- {
+ // In the linker, ifuncs are called as soon as possible so that string functions work.
+ // We must not call them again. (e.g. On arm32, resolving an ifunc changes the meaning of
+ // the addend from a resolver function to the implementation.)
+ if (!is_linker()) {
#if !defined(__LP64__)
// When relocating dso with text_relocation .text segment is
// not executable. We need to restore elf flags for this