Make LD_PRELOAD failures just warnings.

This matches glibc and makes life easier for developers who want to
sometimes preload a library from init (which has no conditionals); they
can simply move/remove the library to disable.

Change-Id: I579b8633f958235af6e46bb53b378b9e363afb1f
This commit is contained in:
Elliott Hughes 2013-06-18 13:15:00 -07:00
parent 977a33137d
commit 7e5a8cc523
2 changed files with 18 additions and 8 deletions

View File

@ -1492,18 +1492,19 @@ static bool soinfo_link_image(soinfo* si) {
return false; return false;
} }
/* if this is the main executable, then load all of the preloads now */ // If this is the main executable, then load all of the libraries from LD_PRELOAD now.
if (si->flags & FLAG_EXE) { if (si->flags & FLAG_EXE) {
memset(gLdPreloads, 0, sizeof(gLdPreloads)); memset(gLdPreloads, 0, sizeof(gLdPreloads));
size_t preload_count = 0;
for (size_t i = 0; gLdPreloadNames[i] != NULL; i++) { for (size_t i = 0; gLdPreloadNames[i] != NULL; i++) {
soinfo* lsi = find_library(gLdPreloadNames[i]); soinfo* lsi = find_library(gLdPreloadNames[i]);
if (lsi == NULL) { if (lsi != NULL) {
strlcpy(tmp_err_buf, linker_get_error_buffer(), sizeof(tmp_err_buf)); gLdPreloads[preload_count++] = lsi;
DL_ERR("could not load library \"%s\" needed by \"%s\"; caused by %s", } else {
gLdPreloadNames[i], si->name, tmp_err_buf); // As with glibc, failure to load an LD_PRELOAD library is just a warning.
return false; DL_WARN("could not load library \"%s\" from LD_PRELOAD for \"%s\"; caused by %s",
gLdPreloadNames[i], si->name, linker_get_error_buffer());
} }
gLdPreloads[i] = lsi;
} }
} }

View File

@ -43,7 +43,16 @@
__libc_format_buffer(linker_get_error_buffer(), linker_get_error_buffer_size(), fmt, ##x); \ __libc_format_buffer(linker_get_error_buffer(), linker_get_error_buffer_size(), fmt, ##x); \
/* If LD_DEBUG is set high enough, log every dlerror(3) message. */ \ /* If LD_DEBUG is set high enough, log every dlerror(3) message. */ \
DEBUG("%s\n", linker_get_error_buffer()); \ DEBUG("%s\n", linker_get_error_buffer()); \
} while(0) } while (false)
#define DL_WARN(fmt, x...) \
do { \
__libc_format_log(ANDROID_LOG_WARN, "linker", fmt, ##x); \
__libc_format_fd(2, "WARNING: linker: "); \
__libc_format_fd(2, fmt, ##x); \
__libc_format_fd(2, "\n"); \
} while (false)
// Returns the address of the page containing address 'x'. // Returns the address of the page containing address 'x'.
#define PAGE_START(x) ((x) & PAGE_MASK) #define PAGE_START(x) ((x) & PAGE_MASK)