Skip to content

Commit 00ab6fb

Browse files
committed
Add DemangleFunctionName for backtracing on NetBSD
Summary: NetBSD uses indirection for old threading functions for historical reasons The mangled names are internal implementation detail and should not be exposed even in backtraces. Sponsored by <The NetBSD Foundation> Reviewers: joerg, vitalybuka, dvyukov Reviewed By: dvyukov Subscribers: kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40251 llvm-svn: 318671
1 parent f03f1fe commit 00ab6fb

File tree

1 file changed

+79
-2
lines changed

1 file changed

+79
-2
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_printer.cc

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,80 @@ static const char *StripFunctionName(const char *function, const char *prefix) {
2929
return function;
3030
}
3131

32+
static const char *DemangleFunctionName(const char *function) {
33+
if (!function) return nullptr;
34+
35+
// NetBSD uses indirection for old threading functions for historical reasons
36+
// The mangled names are internal implementation detail and should not be
37+
// exposed even in backtraces.
38+
#if SANITIZER_NETBSD
39+
if (!internal_strcmp(function, "__libc_mutex_init"))
40+
return "pthread_mutex_init";
41+
if (!internal_strcmp(function, "__libc_mutex_lock"))
42+
return "pthread_mutex_lock";
43+
if (!internal_strcmp(function, "__libc_mutex_trylock"))
44+
return "pthread_mutex_trylock";
45+
if (!internal_strcmp(function, "__libc_mutex_unlock"))
46+
return "pthread_mutex_unlock";
47+
if (!internal_strcmp(function, "__libc_mutex_destroy"))
48+
return "pthread_mutex_destroy";
49+
if (!internal_strcmp(function, "__libc_mutexattr_init"))
50+
return "pthread_mutexattr_init";
51+
if (!internal_strcmp(function, "__libc_mutexattr_settype"))
52+
return "pthread_mutexattr_settype";
53+
if (!internal_strcmp(function, "__libc_mutexattr_destroy"))
54+
return "pthread_mutexattr_destroy";
55+
if (!internal_strcmp(function, "__libc_cond_init"))
56+
return "pthread_cond_init";
57+
if (!internal_strcmp(function, "__libc_cond_signal"))
58+
return "pthread_cond_signal";
59+
if (!internal_strcmp(function, "__libc_cond_broadcast"))
60+
return "pthread_cond_broadcast";
61+
if (!internal_strcmp(function, "__libc_cond_wait"))
62+
return "pthread_cond_wait";
63+
if (!internal_strcmp(function, "__libc_cond_timedwait"))
64+
return "pthread_cond_timedwait";
65+
if (!internal_strcmp(function, "__libc_cond_destroy"))
66+
return "pthread_cond_destroy";
67+
if (!internal_strcmp(function, "__libc_rwlock_init"))
68+
return "pthread_rwlock_init";
69+
if (!internal_strcmp(function, "__libc_rwlock_rdlock"))
70+
return "pthread_rwlock_rdlock";
71+
if (!internal_strcmp(function, "__libc_rwlock_wrlock"))
72+
return "pthread_rwlock_wrlock";
73+
if (!internal_strcmp(function, "__libc_rwlock_tryrdlock"))
74+
return "pthread_rwlock_tryrdlock";
75+
if (!internal_strcmp(function, "__libc_rwlock_trywrlock"))
76+
return "pthread_rwlock_trywrlock";
77+
if (!internal_strcmp(function, "__libc_rwlock_unlock"))
78+
return "pthread_rwlock_unlock";
79+
if (!internal_strcmp(function, "__libc_rwlock_destroy"))
80+
return "pthread_rwlock_destroy";
81+
if (!internal_strcmp(function, "__libc_thr_keycreate"))
82+
return "pthread_key_create";
83+
if (!internal_strcmp(function, "__libc_thr_setspecific"))
84+
return "pthread_setspecific";
85+
if (!internal_strcmp(function, "__libc_thr_getspecific"))
86+
return "pthread_getspecific";
87+
if (!internal_strcmp(function, "__libc_thr_keydelete"))
88+
return "pthread_key_delete";
89+
if (!internal_strcmp(function, "__libc_thr_once"))
90+
return "pthread_once";
91+
if (!internal_strcmp(function, "__libc_thr_self"))
92+
return "pthread_self";
93+
if (!internal_strcmp(function, "__libc_thr_exit"))
94+
return "pthread_exit";
95+
if (!internal_strcmp(function, "__libc_thr_setcancelstate"))
96+
return "pthread_setcancelstate";
97+
if (!internal_strcmp(function, "__libc_thr_equal"))
98+
return "pthread_equal";
99+
if (!internal_strcmp(function, "__libc_thr_curcpu"))
100+
return "pthread_curcpu_np";
101+
#endif
102+
103+
return function;
104+
}
105+
32106
static const char kDefaultFormat[] = " #%n %p %F %L";
33107

34108
void RenderFrame(InternalScopedString *buffer, const char *format, int frame_no,
@@ -60,7 +134,9 @@ void RenderFrame(InternalScopedString *buffer, const char *format, int frame_no,
60134
buffer->append("0x%zx", info.module_offset);
61135
break;
62136
case 'f':
63-
buffer->append("%s", StripFunctionName(info.function, strip_func_prefix));
137+
buffer->append("%s",
138+
DemangleFunctionName(
139+
StripFunctionName(info.function, strip_func_prefix)));
64140
break;
65141
case 'q':
66142
buffer->append("0x%zx", info.function_offset != AddressInfo::kUnknown
@@ -81,7 +157,8 @@ void RenderFrame(InternalScopedString *buffer, const char *format, int frame_no,
81157
// Function name and offset, if file is unknown.
82158
if (info.function) {
83159
buffer->append("in %s",
84-
StripFunctionName(info.function, strip_func_prefix));
160+
DemangleFunctionName(
161+
StripFunctionName(info.function, strip_func_prefix)));
85162
if (!info.file && info.function_offset != AddressInfo::kUnknown)
86163
buffer->append("+0x%zx", info.function_offset);
87164
}

0 commit comments

Comments
 (0)