Skip to content

Commit

Permalink
feat: adapt to Android 15 linker symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
sanfengAndroid committed Dec 4, 2024
1 parent 13e5519 commit 41548b7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
2 changes: 2 additions & 0 deletions library/src/main/cpp/include/linker_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions library/src/main/cpp/linker/linker_globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 13 additions & 3 deletions library/src/main/cpp/linker/linker_symbol.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "linker_symbol.h"

#include "elf_reader.h"
#include <android_level_compat.h>
#include <elf_reader.h>

#include "linker_globals.h"

#if defined(__LP64__)
Expand All @@ -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__) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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);
Expand Down
25 changes: 24 additions & 1 deletion library/src/main/cpp/linker/linker_symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,32 @@ struct LibrarySymbol : SymbolItem<soinfo, false> {
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<soinfo, true> solist;
InternalSymbol<int> g_ld_debug_verbosity{{.force = false}};
ANDROID_LE_U InternalSymbol<int> g_ld_debug_verbosity{{.force = false}};
ANDROID_GE_V InternalSymbol<LinkerDebugConfig> g_linker_debug_config{{.force = false}};
InternalSymbol<uint32_t> g_linker_logger{{.force = false}};
InternalSymbol<pthread_mutex_t> g_dl_mutex;
InternalSymbol<char> linker_dl_err_buf;
Expand Down

0 comments on commit 41548b7

Please sign in to comment.