summaryrefslogtreecommitdiffstats
path: root/linker
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-05-14 10:02:03 -0700
committerElliott Hughes <enh@google.com>2014-05-14 10:02:03 -0700
commit1728b2396591853345507a063ed6075dfd251706 (patch)
tree7083cd234073afa5179b94b3d978550c890af90c /linker
parentbac795586bbc5dcbe886d8d781710f60c4c19d9b (diff)
downloadbionic-1728b2396591853345507a063ed6075dfd251706.zip
bionic-1728b2396591853345507a063ed6075dfd251706.tar.gz
bionic-1728b2396591853345507a063ed6075dfd251706.tar.bz2
Switch to g_ for globals.
That's what the Google style guide recommends, and we're starting to get a mix. Change-Id: Ib0c53a890bb5deed5c679e887541a715faea91fc
Diffstat (limited to 'linker')
-rw-r--r--linker/debugger.cpp2
-rw-r--r--linker/dlfcn.cpp42
-rw-r--r--linker/linker.cpp81
-rw-r--r--linker/linker.h2
-rw-r--r--linker/linker_debug.h6
5 files changed, 66 insertions, 67 deletions
diff --git a/linker/debugger.cpp b/linker/debugger.cpp
index 272c16a..521a599 100644
--- a/linker/debugger.cpp
+++ b/linker/debugger.cpp
@@ -217,7 +217,7 @@ static void send_debuggerd_packet(siginfo_t* info) {
debugger_msg_t msg;
msg.action = DEBUGGER_ACTION_CRASH;
msg.tid = gettid();
- msg.abort_msg_address = reinterpret_cast<uintptr_t>(gAbortMessage);
+ msg.abort_msg_address = reinterpret_cast<uintptr_t>(g_abort_message);
msg.original_si_code = (info != NULL) ? info->si_code : 0;
int ret = TEMP_FAILURE_RETRY(write(s, &msg, sizeof(msg)));
if (ret == sizeof(msg)) {
diff --git a/linker/dlfcn.cpp b/linker/dlfcn.cpp
index 0292bdf..a3cad11 100644
--- a/linker/dlfcn.cpp
+++ b/linker/dlfcn.cpp
@@ -29,7 +29,7 @@
/* This file hijacks the symbols stubbed out in libdl.so. */
-static pthread_mutex_t gDlMutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
+static pthread_mutex_t g_dl_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
static const char* __bionic_set_dlerror(char* new_value) {
char** dlerror_slot = &reinterpret_cast<char**>(__get_tls())[TLS_SLOT_DLERROR];
@@ -56,18 +56,18 @@ const char* dlerror() {
}
void android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size) {
- ScopedPthreadMutexLocker locker(&gDlMutex);
+ ScopedPthreadMutexLocker locker(&g_dl_mutex);
do_android_get_LD_LIBRARY_PATH(buffer, buffer_size);
}
void android_update_LD_LIBRARY_PATH(const char* ld_library_path) {
- ScopedPthreadMutexLocker locker(&gDlMutex);
+ ScopedPthreadMutexLocker locker(&g_dl_mutex);
do_android_update_LD_LIBRARY_PATH(ld_library_path);
}
void* android_dlopen_ext(const char* filename, int flags, const android_dlextinfo* extinfo)
{
- ScopedPthreadMutexLocker locker(&gDlMutex);
+ ScopedPthreadMutexLocker locker(&g_dl_mutex);
soinfo* result = do_dlopen(filename, flags, extinfo);
if (result == NULL) {
__bionic_format_dlerror("dlopen failed", linker_get_error_buffer());
@@ -81,7 +81,7 @@ void* dlopen(const char* filename, int flags) {
}
void* dlsym(void* handle, const char* symbol) {
- ScopedPthreadMutexLocker locker(&gDlMutex);
+ ScopedPthreadMutexLocker locker(&g_dl_mutex);
if (handle == NULL) {
__bionic_format_dlerror("dlsym library handle is null", NULL);
@@ -125,7 +125,7 @@ void* dlsym(void* handle, const char* symbol) {
}
int dladdr(const void* addr, Dl_info* info) {
- ScopedPthreadMutexLocker locker(&gDlMutex);
+ ScopedPthreadMutexLocker locker(&g_dl_mutex);
// Determine if this address can be found in any library currently mapped.
soinfo* si = find_containing_library(addr);
@@ -150,7 +150,7 @@ int dladdr(const void* addr, Dl_info* info) {
}
int dlclose(void* handle) {
- ScopedPthreadMutexLocker locker(&gDlMutex);
+ ScopedPthreadMutexLocker locker(&g_dl_mutex);
return do_dlclose(reinterpret_cast<soinfo*>(handle));
}
@@ -187,7 +187,7 @@ int dlclose(void* handle) {
# error Unsupported architecture. Only arm, arm64, mips, mips64, x86 and x86_64 are presently supported.
#endif
-static ElfW(Sym) gLibDlSymtab[] = {
+static ElfW(Sym) g_libdl_symtab[] = {
// Total length of libdl_info.strtab, including trailing 0.
// This is actually the STH_UNDEF entry. Technically, it's
// supposed to have st_name == 0, but instead, it points to an index
@@ -209,20 +209,20 @@ static ElfW(Sym) gLibDlSymtab[] = {
// Fake out a hash table with a single bucket.
//
-// A search of the hash table will look through gLibDlSymtab starting with index 1, then
-// use gLibDlChains to find the next index to look at. gLibDlChains should be set up to
-// walk through every element in gLibDlSymtab, and then end with 0 (sentinel value).
+// A search of the hash table will look through g_libdl_symtab starting with index 1, then
+// use g_libdl_chains to find the next index to look at. g_libdl_chains should be set up to
+// walk through every element in g_libdl_symtab, and then end with 0 (sentinel value).
//
-// That is, gLibDlChains should look like { 0, 2, 3, ... N, 0 } where N is the number
-// of actual symbols, or nelems(gLibDlSymtab)-1 (since the first element of gLibDlSymtab is not
+// That is, g_libdl_chains should look like { 0, 2, 3, ... N, 0 } where N is the number
+// of actual symbols, or nelems(g_libdl_symtab)-1 (since the first element of g_libdl_symtab is not
// a real symbol). (See soinfo_elf_lookup().)
//
// Note that adding any new symbols here requires stubbing them out in libdl.
-static unsigned gLibDlBuckets[1] = { 1 };
+static unsigned g_libdl_buckets[1] = { 1 };
#if defined(__arm__)
-static unsigned gLibDlChains[] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0 };
+static unsigned g_libdl_chains[] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0 };
#else
-static unsigned gLibDlChains[] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
+static unsigned g_libdl_chains[] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
#endif
// This is used by the dynamic linker. Every process gets these symbols for free.
@@ -250,12 +250,12 @@ soinfo libdl_info = {
.flags = FLAG_LINKED,
.strtab = ANDROID_LIBDL_STRTAB,
- .symtab = gLibDlSymtab,
+ .symtab = g_libdl_symtab,
- .nbucket = sizeof(gLibDlBuckets)/sizeof(unsigned),
- .nchain = sizeof(gLibDlChains)/sizeof(unsigned),
- .bucket = gLibDlBuckets,
- .chain = gLibDlChains,
+ .nbucket = sizeof(g_libdl_buckets)/sizeof(unsigned),
+ .nchain = sizeof(g_libdl_chains)/sizeof(unsigned),
+ .bucket = g_libdl_buckets,
+ .chain = g_libdl_chains,
#if defined(USE_RELA)
.plt_rela = 0,
diff --git a/linker/linker.cpp b/linker/linker.cpp
index df53a84..86204de 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -71,13 +71,13 @@ static ElfW(Addr) get_elf_exec_load_bias(const ElfW(Ehdr)* elf);
// We can't use malloc(3) in the dynamic linker. We use a linked list of anonymous
// maps, each a single page in size. The pages are broken up into as many struct soinfo
// objects as will fit.
-static LinkerAllocator<soinfo> gSoInfoAllocator;
+static LinkerAllocator<soinfo> g_soinfo_allocator;
static soinfo* solist = &libdl_info;
static soinfo* sonext = &libdl_info;
static soinfo* somain; /* main process, always the one after libdl_info */
-static const char* const gDefaultLdPaths[] = {
+static const char* const kDefaultLdPaths[] = {
#if defined(__LP64__)
"/vendor/lib64",
"/system/lib64",
@@ -94,17 +94,17 @@ static const char* const gDefaultLdPaths[] = {
#define LDPRELOAD_BUFSIZE (LDPRELOAD_MAX*64)
#define LDPRELOAD_MAX 8
-static char gLdPathsBuffer[LDPATH_BUFSIZE];
-static const char* gLdPaths[LDPATH_MAX + 1];
+static char g_ld_library_paths_buffer[LDPATH_BUFSIZE];
+static const char* g_ld_library_paths[LDPATH_MAX + 1];
-static char gLdPreloadsBuffer[LDPRELOAD_BUFSIZE];
-static const char* gLdPreloadNames[LDPRELOAD_MAX + 1];
+static char g_ld_preloads_buffer[LDPRELOAD_BUFSIZE];
+static const char* g_ld_preload_names[LDPRELOAD_MAX + 1];
-static soinfo* gLdPreloads[LDPRELOAD_MAX + 1];
+static soinfo* g_ld_preloads[LDPRELOAD_MAX + 1];
-__LIBC_HIDDEN__ int gLdDebugVerbosity;
+__LIBC_HIDDEN__ int g_ld_debug_verbosity;
-__LIBC_HIDDEN__ abort_msg_t* gAbortMessage = NULL; // For debuggerd.
+__LIBC_HIDDEN__ abort_msg_t* g_abort_message = NULL; // For debuggerd.
enum RelocationKind {
kRelocAbsolute = 0,
@@ -179,11 +179,10 @@ size_t linker_get_error_buffer_size() {
*/
extern "C" void __attribute__((noinline)) __attribute__((visibility("default"))) rtld_db_dlactivity();
+static pthread_mutex_t g__r_debug_mutex = PTHREAD_MUTEX_INITIALIZER;
static r_debug _r_debug = {1, NULL, reinterpret_cast<uintptr_t>(&rtld_db_dlactivity), r_debug::RT_CONSISTENT, 0};
static link_map* r_debug_tail = 0;
-static pthread_mutex_t gDebugMutex = PTHREAD_MUTEX_INITIALIZER;
-
static void insert_soinfo_into_debug_map(soinfo* info) {
// Copy the necessary fields into the debug structure.
link_map* map = &(info->link_map_head);
@@ -229,7 +228,7 @@ static void notify_gdb_of_load(soinfo* info) {
return;
}
- ScopedPthreadMutexLocker locker(&gDebugMutex);
+ ScopedPthreadMutexLocker locker(&g__r_debug_mutex);
_r_debug.r_state = r_debug::RT_ADD;
rtld_db_dlactivity();
@@ -246,7 +245,7 @@ static void notify_gdb_of_unload(soinfo* info) {
return;
}
- ScopedPthreadMutexLocker locker(&gDebugMutex);
+ ScopedPthreadMutexLocker locker(&g__r_debug_mutex);
_r_debug.r_state = r_debug::RT_DELETE;
rtld_db_dlactivity();
@@ -270,7 +269,7 @@ static soinfo* soinfo_alloc(const char* name) {
return NULL;
}
- soinfo* si = gSoInfoAllocator.alloc();
+ soinfo* si = g_soinfo_allocator.alloc();
// Initialize the new element.
memset(si, 0, sizeof(soinfo));
@@ -310,7 +309,7 @@ static void soinfo_free(soinfo* si) {
sonext = prev;
}
- gSoInfoAllocator.free(si);
+ g_soinfo_allocator.free(si);
}
@@ -340,14 +339,14 @@ static void parse_path(const char* path, const char* delimiters,
}
static void parse_LD_LIBRARY_PATH(const char* path) {
- parse_path(path, ":", gLdPaths,
- gLdPathsBuffer, sizeof(gLdPathsBuffer), LDPATH_MAX);
+ parse_path(path, ":", g_ld_library_paths,
+ g_ld_library_paths_buffer, sizeof(g_ld_library_paths_buffer), LDPATH_MAX);
}
static void parse_LD_PRELOAD(const char* path) {
// We have historically supported ':' as well as ' ' in LD_PRELOAD.
- parse_path(path, " :", gLdPreloadNames,
- gLdPreloadsBuffer, sizeof(gLdPreloadsBuffer), LDPRELOAD_MAX);
+ parse_path(path, " :", g_ld_preload_names,
+ g_ld_preloads_buffer, sizeof(g_ld_preloads_buffer), LDPRELOAD_MAX);
}
#if defined(__arm__)
@@ -505,10 +504,10 @@ static ElfW(Sym)* soinfo_do_lookup(soinfo* si, const char* name, soinfo** lsi, s
}
/* Next, look for it in the preloads list */
- for (int i = 0; gLdPreloads[i] != NULL; i++) {
- s = soinfo_elf_lookup(gLdPreloads[i], elf_hash, name);
+ for (int i = 0; g_ld_preloads[i] != NULL; i++) {
+ s = soinfo_elf_lookup(g_ld_preloads[i], elf_hash, name);
if (s != NULL) {
- *lsi = gLdPreloads[i];
+ *lsi = g_ld_preloads[i];
goto done;
}
}
@@ -637,9 +636,9 @@ static int open_library(const char* name) {
}
// Otherwise we try LD_LIBRARY_PATH first, and fall back to the built-in well known paths.
- int fd = open_library_on_path(name, gLdPaths);
+ int fd = open_library_on_path(name, g_ld_library_paths);
if (fd == -1) {
- fd = open_library_on_path(name, gDefaultLdPaths);
+ fd = open_library_on_path(name, kDefaultLdPaths);
}
return fd;
}
@@ -756,7 +755,7 @@ static int soinfo_unload(soinfo* si) {
}
void do_android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size) {
- snprintf(buffer, buffer_size, "%s:%s", gDefaultLdPaths[0], gDefaultLdPaths[1]);
+ snprintf(buffer, buffer_size, "%s:%s", kDefaultLdPaths[0], kDefaultLdPaths[1]);
}
void do_android_update_LD_LIBRARY_PATH(const char* ld_library_path) {
@@ -774,19 +773,19 @@ soinfo* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo)
DL_ERR("invalid extended flags to android_dlopen_ext: %x", extinfo->flags);
return NULL;
}
- gSoInfoAllocator.protect_all(PROT_READ | PROT_WRITE);
+ g_soinfo_allocator.protect_all(PROT_READ | PROT_WRITE);
soinfo* si = find_library(name, extinfo);
if (si != NULL) {
si->CallConstructors();
}
- gSoInfoAllocator.protect_all(PROT_READ);
+ g_soinfo_allocator.protect_all(PROT_READ);
return si;
}
int do_dlclose(soinfo* si) {
- gSoInfoAllocator.protect_all(PROT_READ | PROT_WRITE);
+ g_soinfo_allocator.protect_all(PROT_READ | PROT_WRITE);
int result = soinfo_unload(si);
- gSoInfoAllocator.protect_all(PROT_READ);
+ g_soinfo_allocator.protect_all(PROT_READ);
return result;
}
@@ -1334,7 +1333,7 @@ void soinfo::CallFunction(const char* function_name __unused, linker_function_t
// The function may have called dlopen(3) or dlclose(3), so we need to ensure our data structures
// are still writable. This happens with our debug malloc (see http://b/7941716).
- gSoInfoAllocator.protect_all(PROT_READ | PROT_WRITE);
+ g_soinfo_allocator.protect_all(PROT_READ | PROT_WRITE);
}
void soinfo::CallPreInitConstructors() {
@@ -1688,16 +1687,16 @@ static bool soinfo_link_image(soinfo* si, const android_dlextinfo* extinfo) {
// If this is the main executable, then load all of the libraries from LD_PRELOAD now.
if (si->flags & FLAG_EXE) {
- memset(gLdPreloads, 0, sizeof(gLdPreloads));
+ memset(g_ld_preloads, 0, sizeof(g_ld_preloads));
size_t preload_count = 0;
- for (size_t i = 0; gLdPreloadNames[i] != NULL; i++) {
- soinfo* lsi = find_library(gLdPreloadNames[i], NULL);
+ for (size_t i = 0; g_ld_preload_names[i] != NULL; i++) {
+ soinfo* lsi = find_library(g_ld_preload_names[i], NULL);
if (lsi != NULL) {
- gLdPreloads[preload_count++] = lsi;
+ g_ld_preloads[preload_count++] = lsi;
} else {
// As with glibc, failure to load an LD_PRELOAD library is just a warning.
DL_WARN("could not load library \"%s\" from LD_PRELOAD for \"%s\"; caused by %s",
- gLdPreloadNames[i], si->name, linker_get_error_buffer());
+ g_ld_preload_names[i], si->name, linker_get_error_buffer());
}
}
}
@@ -1873,7 +1872,7 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(
// Get a few environment variables.
const char* LD_DEBUG = linker_env_get("LD_DEBUG");
if (LD_DEBUG != NULL) {
- gLdDebugVerbosity = atoi(LD_DEBUG);
+ g_ld_debug_verbosity = atoi(LD_DEBUG);
}
// Normally, these are cleaned by linker_env_init, but the test
@@ -1888,7 +1887,7 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(
// Linker does not call constructors for its own
// global variables so we need to initialize
// the allocator explicitly.
- gSoInfoAllocator.init();
+ g_soinfo_allocator.init();
INFO("[ android linker & debugger ]");
@@ -1982,8 +1981,8 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(
si->CallPreInitConstructors();
- for (size_t i = 0; gLdPreloads[i] != NULL; ++i) {
- gLdPreloads[i]->CallConstructors();
+ for (size_t i = 0; g_ld_preloads[i] != NULL; ++i) {
+ g_ld_preloads[i]->CallConstructors();
}
/* After the link_image, the si->load_bias is initialized.
@@ -2104,10 +2103,10 @@ extern "C" ElfW(Addr) __linker_init(void* raw_args) {
// We have successfully fixed our own relocations. It's safe to run
// the main part of the linker now.
- args.abort_message_ptr = &gAbortMessage;
+ args.abort_message_ptr = &g_abort_message;
ElfW(Addr) start_address = __linker_init_post_relocation(args, linker_addr);
- gSoInfoAllocator.protect_all(PROT_READ);
+ g_soinfo_allocator.protect_all(PROT_READ);
// Return the address that the calling assembly stub should jump to.
return start_address;
diff --git a/linker/linker.h b/linker/linker.h
index 93ab51d..645498a 100644
--- a/linker/linker.h
+++ b/linker/linker.h
@@ -203,7 +203,7 @@ ElfW(Sym)* dladdr_find_symbol(soinfo* si, const void* addr);
ElfW(Sym)* dlsym_handle_lookup(soinfo* si, const char* name);
void debuggerd_init();
-extern "C" abort_msg_t* gAbortMessage;
+extern "C" abort_msg_t* g_abort_message;
extern "C" void notify_gdb_of_libraries();
char* linker_get_error_buffer();
diff --git a/linker/linker_debug.h b/linker/linker_debug.h
index 7a5821a..3faa38e 100644
--- a/linker/linker_debug.h
+++ b/linker/linker_debug.h
@@ -55,17 +55,17 @@
#include "private/libc_logging.h"
-__LIBC_HIDDEN__ extern int gLdDebugVerbosity;
+__LIBC_HIDDEN__ extern int g_ld_debug_verbosity;
#if LINKER_DEBUG_TO_LOG
#define _PRINTVF(v, x...) \
do { \
- if (gLdDebugVerbosity > (v)) __libc_format_log(5-(v), "linker", x); \
+ if (g_ld_debug_verbosity > (v)) __libc_format_log(5-(v), "linker", x); \
} while (0)
#else /* !LINKER_DEBUG_TO_LOG */
#define _PRINTVF(v, x...) \
do { \
- if (gLdDebugVerbosity > (v)) { __libc_format_fd(1, x); write(1, "\n", 1); } \
+ if (g_ld_debug_verbosity > (v)) { __libc_format_fd(1, x); write(1, "\n", 1); } \
} while (0)
#endif /* !LINKER_DEBUG_TO_LOG */