Skip to content

Commit 41548b7

Browse files
feat: adapt to Android 15 linker symbols
1 parent 13e5519 commit 41548b7

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

library/src/main/cpp/include/linker_macros.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#define ANDROID_LE_L1
2020
#define ANDROID_LE_O1
2121
#define ANDROID_LE_S
22+
#define ANDROID_LE_U
23+
#define ANDROID_LE_V
2224

2325
#define MEMORY_FREE
2426
#define ONLY_READ

library/src/main/cpp/linker/linker_globals.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,9 @@ bool ProxyLinker::SetLdDebugVerbosity(int level) {
545545
if (int *p = linker_symbol.g_ld_debug_verbosity.Get()) {
546546
*p = level;
547547
return true;
548+
} else if (auto *config = linker_symbol.g_linker_debug_config.Get()) {
549+
config->any = true;
550+
return true;
548551
}
549552
return false;
550553
}

library/src/main/cpp/linker/linker_symbol.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "linker_symbol.h"
22

3-
#include "elf_reader.h"
3+
#include <android_level_compat.h>
4+
#include <elf_reader.h>
5+
46
#include "linker_globals.h"
57

68
#if defined(__LP64__)
@@ -15,8 +17,13 @@ LinkerSymbol linker_symbol;
1517
void LinkerSymbol::InitSymbolName() {
1618
solist.name = "__dl__ZL6solist";
1719
g_ld_debug_verbosity.name = "__dl_g_ld_debug_verbosity";
20+
g_linker_debug_config.name = "__dl_g_linker_debug_config";
1821
g_linker_logger.name = "__dl_g_linker_logger";
19-
g_dl_mutex.name = "__dl__ZL10g_dl_mutex";
22+
if (android_api >= __ANDROID_API_V__) {
23+
g_dl_mutex.name = "__dl_g_dl_mutex";
24+
} else {
25+
g_dl_mutex.name = "__dl__ZL10g_dl_mutex";
26+
}
2027
linker_dl_err_buf.name = "__dl__ZL19__linker_dl_err_buf";
2128

2229
if (android_api >= __ANDROID_API_R__) {
@@ -127,6 +134,7 @@ bool LinkerSymbol::LoadSymbol() {
127134

128135
APPEND_SYMBOL(solist);
129136
APPEND_SYMBOL(g_ld_debug_verbosity);
137+
APPEND_SYMBOL(g_linker_debug_config);
130138
APPEND_SYMBOL(g_linker_logger);
131139
APPEND_SYMBOL(g_dl_mutex);
132140
APPEND_SYMBOL(linker_dl_err_buf);
@@ -165,12 +173,13 @@ bool LinkerSymbol::LoadSymbol() {
165173
if (!reader.LoadFromDisk(library)) {
166174
return false;
167175
}
168-
internalAddresses = reader.FindInternalSymbols(internalSymbols);
176+
internalAddresses = reader.FindInternalSymbols(internalSymbols, android_api >= __ANDROID_API_V__);
169177
if (internalAddresses.size() != internalSymbols.size()) {
170178
LOGE("find linker internal symbols failed.");
171179
return false;
172180
}
173181
if (!solist.Set(internalAddresses[0])) {
182+
LOGE("find linker solist symbol failed.");
174183
return false;
175184
}
176185
}
@@ -190,6 +199,7 @@ bool LinkerSymbol::LoadSymbol() {
190199

191200
ASSIGN_SYMBOL(solist);
192201
ASSIGN_SYMBOL(g_ld_debug_verbosity);
202+
ASSIGN_SYMBOL(g_linker_debug_config);
193203
ASSIGN_SYMBOL(g_linker_logger);
194204
ASSIGN_SYMBOL(g_dl_mutex);
195205
ASSIGN_SYMBOL(linker_dl_err_buf);

library/src/main/cpp/linker/linker_symbol.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,32 @@ struct LibrarySymbol : SymbolItem<soinfo, false> {
7070
static constexpr int type = 2;
7171
};
7272

73+
ANDROID_GE_V struct LinkerDebugConfig {
74+
// Set automatically if any of the more specific options are set.
75+
bool any;
76+
77+
// Messages relating to calling ctors/dtors/ifuncs.
78+
bool calls;
79+
// Messages relating to CFI.
80+
bool cfi;
81+
// Messages relating to the dynamic section.
82+
bool dynamic;
83+
// Messages relating to symbol lookup.
84+
bool lookup;
85+
// Messages relating to relocation processing.
86+
bool reloc;
87+
// Messages relating to ELF properties.
88+
bool props;
89+
// TODO: "config" and "zip" seem likely to want to be separate?
90+
91+
bool timing;
92+
bool statistics;
93+
};
94+
7395
struct LinkerSymbol {
7496
InternalSymbol<soinfo, true> solist;
75-
InternalSymbol<int> g_ld_debug_verbosity{{.force = false}};
97+
ANDROID_LE_U InternalSymbol<int> g_ld_debug_verbosity{{.force = false}};
98+
ANDROID_GE_V InternalSymbol<LinkerDebugConfig> g_linker_debug_config{{.force = false}};
7699
InternalSymbol<uint32_t> g_linker_logger{{.force = false}};
77100
InternalSymbol<pthread_mutex_t> g_dl_mutex;
78101
InternalSymbol<char> linker_dl_err_buf;

0 commit comments

Comments
 (0)