Move libc_log code into libasync_safe.
This library is used by a number of different libraries in the system.
Make it easy for platform libraries to use this library and create
an actual exported include file.
Change the names of the functions to reflect the new name of the library.
Run clang_format on the async_safe_log.cpp file since the formatting is
all over the place.
Bug: 31919199
Test: Compiled for angler/bullhead, and booted.
Test: Ran bionic unit tests.
Test: Ran the malloc debug tests.
Change-Id: I8071bf690c17b0ea3bc8dc5749cdd5b6ad58478a
diff --git a/linker/linker.cpp b/linker/linker.cpp
index afd990a..0b4490d 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -46,6 +46,8 @@
#include <android-base/scopeguard.h>
+#include <async_safe/log.h>
+
// Private C library headers.
#include "linker.h"
@@ -344,7 +346,7 @@
static bool realpath_fd(int fd, std::string* realpath) {
std::vector<char> buf(PATH_MAX), proc_self_fd(PATH_MAX);
- __libc_format_buffer(&proc_self_fd[0], proc_self_fd.size(), "/proc/self/fd/%d", fd);
+ async_safe_format_buffer(&proc_self_fd[0], proc_self_fd.size(), "/proc/self/fd/%d", fd);
if (readlink(&proc_self_fd[0], &buf[0], buf.size()) == -1) {
PRINT("readlink(\"%s\") failed: %s [fd=%d]", &proc_self_fd[0], strerror(errno), fd);
return false;
@@ -493,7 +495,7 @@
}
if (ref_count_ == 0) { // overflow
- __libc_fatal("Too many nested calls to dlopen()");
+ async_safe_fatal("Too many nested calls to dlopen()");
}
}
@@ -992,7 +994,7 @@
}
static bool format_path(char* buf, size_t buf_size, const char* path, const char* name) {
- int n = __libc_format_buffer(buf, buf_size, "%s/%s", path, name);
+ int n = async_safe_format_buffer(buf, buf_size, "%s/%s", path, name);
if (n < 0 || n >= static_cast<int>(buf_size)) {
PRINT("Warning: ignoring very long library path: %s/%s", path, name);
return false;
@@ -1781,7 +1783,7 @@
}
} else {
#if !defined(__work_around_b_24465209__)
- __libc_fatal("soinfo for \"%s\"@%p has no version", si->get_realpath(), si);
+ async_safe_fatal("soinfo for \"%s\"@%p has no version", si->get_realpath(), si);
#else
PRINT("warning: soinfo for \"%s\"@%p has no version", si->get_realpath(), si);
for_each_dt_needed(si, [&] (const char* library_name) {
@@ -1855,8 +1857,8 @@
}
if (buffer_size < required_size) {
- __libc_fatal("android_get_LD_LIBRARY_PATH failed, buffer too small: "
- "buffer len %zu, required len %zu", buffer_size, required_size);
+ async_safe_fatal("android_get_LD_LIBRARY_PATH failed, buffer too small: "
+ "buffer len %zu, required len %zu", buffer_size, required_size);
}
char* end = buffer;