Skip to content

Commit

Permalink
Print a useful error message if we can't interpose libstdc++ symbols …
Browse files Browse the repository at this point in the history
…correctly because the library was likely loaded with RTLD_LOCAL.

Fixes #3304
  • Loading branch information
khuey committed Jul 8, 2022
1 parent 21ec75e commit ecc4124
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/preload/overrides.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ uid_t geteuid(void) {
#endif
}

static void libstdcpp_not_found(void) {
const char msg[] = "[rr] Interposition for libstdc++ called but symbol lookups into libstdc++ failed.\n"
"Was libstdc++ loaded with RTLD_LOCAL? Try recording with `-v LD_PRELOAD=libstdc++.so.6`.\n"
"About to crash! ";
syscall(SYS_write, STDERR_FILENO, msg, sizeof(msg));
}

/**
* libstdc++3 uses RDRAND. Bypass that with this incredible hack.
*/
Expand All @@ -252,10 +259,16 @@ void _ZNSt13random_device7_M_initERKNSt7__cxx1112basic_stringIcSt11char_traitsIc
if (!assign_string) {
assign_string = (void (*)(void *, char*))dlsym(RTLD_NEXT,
"_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6assignEPKc");
if (!assign_string) {
libstdcpp_not_found();
}
}
assign_string(token, "/dev/urandom");
if (!random_init) {
random_init = (void (*)(void *, void*))dlsym(RTLD_NEXT, __func__);
if (!random_init) {
libstdcpp_not_found();
}
}
random_init(this, token);
}
Expand All @@ -270,10 +283,16 @@ void _ZNSt13random_device7_M_initERKSs(void* this,
if (!assign_string) {
assign_string = (void (*)(void *, char*))dlsym(RTLD_NEXT,
"_ZNSs6assignEPKc");
if (!assign_string) {
libstdcpp_not_found();
}
}
assign_string(token, "/dev/urandom");
if (!random_init) {
random_init = (void (*)(void *, void*))dlsym(RTLD_NEXT, __func__);
if (!random_init) {
libstdcpp_not_found();
}
}
random_init(this, token);
}
Expand Down

0 comments on commit ecc4124

Please sign in to comment.