Skip to content

Instantly share code, notes, and snippets.

@romainthomas
Last active September 12, 2023 02:12
Show Gist options
  • Save romainthomas/c10298387a921df730c1556c2ee9cecb to your computer and use it in GitHub Desktop.
Save romainthomas/c10298387a921df730c1556c2ee9cecb to your computer and use it in GitHub Desktop.
Bionic's linker runs ELF constructors
// Mangled as __dl__ZL10call_arrayIPFviPPcS1_EEvPKcPT_mbS5_ in /system/bin/linker64
template <typename F>
static void call_array(const char* array_name __unused,
F* functions,
size_t count,
bool reverse,
const char* realpath) {
if (functions == nullptr) {
return;
}
TRACE("[ Calling %s (size %zd) @ %p for '%s' ]", array_name, count, functions, realpath);
int begin = reverse ? (count - 1) : 0;
int end = reverse ? -1 : count;
int step = reverse ? -1 : 1;
for (int i = begin; i != end; i += step) {
TRACE("[ %s[%d] == %p ]", array_name, i, functions[i]);
call_function("function", functions[i], realpath);
}
TRACE("[ Done calling %s for '%s' ]", array_name, realpath);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment