Skip to content

Commit ecc4124

Browse files
committed
Print a useful error message if we can't interpose libstdc++ symbols correctly because the library was likely loaded with RTLD_LOCAL.
Fixes #3304
1 parent 21ec75e commit ecc4124

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/preload/overrides.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ uid_t geteuid(void) {
242242
#endif
243243
}
244244

245+
static void libstdcpp_not_found(void) {
246+
const char msg[] = "[rr] Interposition for libstdc++ called but symbol lookups into libstdc++ failed.\n"
247+
"Was libstdc++ loaded with RTLD_LOCAL? Try recording with `-v LD_PRELOAD=libstdc++.so.6`.\n"
248+
"About to crash! ";
249+
syscall(SYS_write, STDERR_FILENO, msg, sizeof(msg));
250+
}
251+
245252
/**
246253
* libstdc++3 uses RDRAND. Bypass that with this incredible hack.
247254
*/
@@ -252,10 +259,16 @@ void _ZNSt13random_device7_M_initERKNSt7__cxx1112basic_stringIcSt11char_traitsIc
252259
if (!assign_string) {
253260
assign_string = (void (*)(void *, char*))dlsym(RTLD_NEXT,
254261
"_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE6assignEPKc");
262+
if (!assign_string) {
263+
libstdcpp_not_found();
264+
}
255265
}
256266
assign_string(token, "/dev/urandom");
257267
if (!random_init) {
258268
random_init = (void (*)(void *, void*))dlsym(RTLD_NEXT, __func__);
269+
if (!random_init) {
270+
libstdcpp_not_found();
271+
}
259272
}
260273
random_init(this, token);
261274
}
@@ -270,10 +283,16 @@ void _ZNSt13random_device7_M_initERKSs(void* this,
270283
if (!assign_string) {
271284
assign_string = (void (*)(void *, char*))dlsym(RTLD_NEXT,
272285
"_ZNSs6assignEPKc");
286+
if (!assign_string) {
287+
libstdcpp_not_found();
288+
}
273289
}
274290
assign_string(token, "/dev/urandom");
275291
if (!random_init) {
276292
random_init = (void (*)(void *, void*))dlsym(RTLD_NEXT, __func__);
293+
if (!random_init) {
294+
libstdcpp_not_found();
295+
}
277296
}
278297
random_init(this, token);
279298
}

0 commit comments

Comments
 (0)