From 41548b781df4054ffc56b43cdbddbe3506a02549 Mon Sep 17 00:00:00 2001 From: sanfengAndroid <976372587@qq.com> Date: Wed, 4 Dec 2024 17:14:24 +0800 Subject: [PATCH] feat: adapt to Android 15 linker symbols --- library/src/main/cpp/include/linker_macros.h | 2 ++ .../src/main/cpp/linker/linker_globals.cpp | 3 +++ library/src/main/cpp/linker/linker_symbol.cpp | 16 +++++++++--- library/src/main/cpp/linker/linker_symbol.h | 25 ++++++++++++++++++- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/library/src/main/cpp/include/linker_macros.h b/library/src/main/cpp/include/linker_macros.h index 90cd2d6..bd3ce22 100644 --- a/library/src/main/cpp/include/linker_macros.h +++ b/library/src/main/cpp/include/linker_macros.h @@ -19,6 +19,8 @@ #define ANDROID_LE_L1 #define ANDROID_LE_O1 #define ANDROID_LE_S +#define ANDROID_LE_U +#define ANDROID_LE_V #define MEMORY_FREE #define ONLY_READ diff --git a/library/src/main/cpp/linker/linker_globals.cpp b/library/src/main/cpp/linker/linker_globals.cpp index 2be0975..54826d3 100644 --- a/library/src/main/cpp/linker/linker_globals.cpp +++ b/library/src/main/cpp/linker/linker_globals.cpp @@ -545,6 +545,9 @@ bool ProxyLinker::SetLdDebugVerbosity(int level) { if (int *p = linker_symbol.g_ld_debug_verbosity.Get()) { *p = level; return true; + } else if (auto *config = linker_symbol.g_linker_debug_config.Get()) { + config->any = true; + return true; } return false; } diff --git a/library/src/main/cpp/linker/linker_symbol.cpp b/library/src/main/cpp/linker/linker_symbol.cpp index 295fe08..9f561db 100644 --- a/library/src/main/cpp/linker/linker_symbol.cpp +++ b/library/src/main/cpp/linker/linker_symbol.cpp @@ -1,6 +1,8 @@ #include "linker_symbol.h" -#include "elf_reader.h" +#include +#include + #include "linker_globals.h" #if defined(__LP64__) @@ -15,8 +17,13 @@ LinkerSymbol linker_symbol; void LinkerSymbol::InitSymbolName() { solist.name = "__dl__ZL6solist"; g_ld_debug_verbosity.name = "__dl_g_ld_debug_verbosity"; + g_linker_debug_config.name = "__dl_g_linker_debug_config"; g_linker_logger.name = "__dl_g_linker_logger"; - g_dl_mutex.name = "__dl__ZL10g_dl_mutex"; + if (android_api >= __ANDROID_API_V__) { + g_dl_mutex.name = "__dl_g_dl_mutex"; + } else { + g_dl_mutex.name = "__dl__ZL10g_dl_mutex"; + } linker_dl_err_buf.name = "__dl__ZL19__linker_dl_err_buf"; if (android_api >= __ANDROID_API_R__) { @@ -127,6 +134,7 @@ bool LinkerSymbol::LoadSymbol() { APPEND_SYMBOL(solist); APPEND_SYMBOL(g_ld_debug_verbosity); + APPEND_SYMBOL(g_linker_debug_config); APPEND_SYMBOL(g_linker_logger); APPEND_SYMBOL(g_dl_mutex); APPEND_SYMBOL(linker_dl_err_buf); @@ -165,12 +173,13 @@ bool LinkerSymbol::LoadSymbol() { if (!reader.LoadFromDisk(library)) { return false; } - internalAddresses = reader.FindInternalSymbols(internalSymbols); + internalAddresses = reader.FindInternalSymbols(internalSymbols, android_api >= __ANDROID_API_V__); if (internalAddresses.size() != internalSymbols.size()) { LOGE("find linker internal symbols failed."); return false; } if (!solist.Set(internalAddresses[0])) { + LOGE("find linker solist symbol failed."); return false; } } @@ -190,6 +199,7 @@ bool LinkerSymbol::LoadSymbol() { ASSIGN_SYMBOL(solist); ASSIGN_SYMBOL(g_ld_debug_verbosity); + ASSIGN_SYMBOL(g_linker_debug_config); ASSIGN_SYMBOL(g_linker_logger); ASSIGN_SYMBOL(g_dl_mutex); ASSIGN_SYMBOL(linker_dl_err_buf); diff --git a/library/src/main/cpp/linker/linker_symbol.h b/library/src/main/cpp/linker/linker_symbol.h index 822288e..95ebf9f 100644 --- a/library/src/main/cpp/linker/linker_symbol.h +++ b/library/src/main/cpp/linker/linker_symbol.h @@ -70,9 +70,32 @@ struct LibrarySymbol : SymbolItem { static constexpr int type = 2; }; +ANDROID_GE_V struct LinkerDebugConfig { + // Set automatically if any of the more specific options are set. + bool any; + + // Messages relating to calling ctors/dtors/ifuncs. + bool calls; + // Messages relating to CFI. + bool cfi; + // Messages relating to the dynamic section. + bool dynamic; + // Messages relating to symbol lookup. + bool lookup; + // Messages relating to relocation processing. + bool reloc; + // Messages relating to ELF properties. + bool props; + // TODO: "config" and "zip" seem likely to want to be separate? + + bool timing; + bool statistics; +}; + struct LinkerSymbol { InternalSymbol solist; - InternalSymbol g_ld_debug_verbosity{{.force = false}}; + ANDROID_LE_U InternalSymbol g_ld_debug_verbosity{{.force = false}}; + ANDROID_GE_V InternalSymbol g_linker_debug_config{{.force = false}}; InternalSymbol g_linker_logger{{.force = false}}; InternalSymbol g_dl_mutex; InternalSymbol linker_dl_err_buf;