Skip to content

Commit e887a6a

Browse files
committed
do not load libunwind symbols with dlopen + dlsym (libunwind is always present on os x)
1 parent f943707 commit e887a6a

1 file changed

Lines changed: 21 additions & 21 deletions

File tree

src/vmp_stack.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@
1515
#include "compat.h"
1616

1717
#ifdef VMP_SUPPORTS_NATIVE_PROFILING
18-
#include "unwind/vmprof_unwind.h"
1918

19+
#ifdef VMPROF_LINUX
20+
#include "unwind/vmprof_unwind.h"
2021
typedef mcontext_t unw_context_t;
2122

2223
// functions copied from libunwind using dlopen
23-
2424
static int (*unw_get_reg)(unw_cursor_t*, int, unw_word_t*) = NULL;
2525
static int (*unw_step)(unw_cursor_t*) = NULL;
2626
static int (*unw_init_local)(unw_cursor_t *, unw_context_t *) = NULL;
2727
static int (*unw_get_proc_info)(unw_cursor_t *, unw_proc_info_t *) = NULL;
2828
static int (*unw_get_proc_name)(unw_cursor_t *, char *, size_t, unw_word_t*) = NULL;
2929
static int (*unw_is_signal_frame)(unw_cursor_t *) = NULL;
3030
static int (*unw_getcontext)(unw_context_t *) = NULL;
31+
#else
32+
#include <libunwind.h>
33+
#endif
3134

3235
#endif
3336

@@ -508,53 +511,50 @@ static void * libhandle = NULL;
508511
#endif
509512
#define U_PREFIX "_U"
510513
#define UL_PREFIX "_UL"
511-
#else
512-
#define LIBUNWIND "/usr/lib/system/libunwind.dylib"
513-
#define PREFIX "unw"
514-
#define U_PREFIX ""
515-
#define UL_PREFIX ""
516514
#endif
517515

518516
int vmp_native_enable(void) {
519-
vmp_native_traces_enabled = 1;
520-
517+
#ifdef VMPROF_LINUX
521518
if (!unw_get_reg) {
522-
if (!(libhandle = dlopen(LIBUNWIND, RTLD_LAZY | RTLD_LOCAL))) {
519+
if ((libhandle = dlopen(LIBUNWIND, RTLD_LAZY | RTLD_LOCAL)) == NULL) {
523520
goto bail_out;
524521
}
525-
if (!(unw_get_reg = dlsym(libhandle, UL_PREFIX PREFIX "_get_reg"))) {
522+
if ((unw_get_reg = dlsym(libhandle, UL_PREFIX PREFIX "_get_reg")) == NULL) {
526523
goto bail_out;
527524
}
528-
if (!(unw_get_proc_info = dlsym(libhandle, UL_PREFIX PREFIX "_get_proc_info"))){
525+
if ((unw_get_proc_info = dlsym(libhandle, UL_PREFIX PREFIX "_get_proc_info")) == NULL){
529526
goto bail_out;
530527
}
531-
if (!(unw_get_proc_name = dlsym(libhandle, UL_PREFIX PREFIX "_get_proc_name"))){
528+
if ((unw_get_proc_name = dlsym(libhandle, UL_PREFIX PREFIX "_get_proc_name")) == NULL){
532529
goto bail_out;
533530
}
534-
if (!(unw_init_local = dlsym(libhandle, UL_PREFIX PREFIX "_init_local"))) {
531+
if ((unw_init_local = dlsym(libhandle, UL_PREFIX PREFIX "_init_local")) == NULL) {
535532
goto bail_out;
536533
}
537-
if (!(unw_step = dlsym(libhandle, UL_PREFIX PREFIX "_step"))) {
534+
if ((unw_step = dlsym(libhandle, UL_PREFIX PREFIX "_step")) == NULL) {
538535
goto bail_out;
539536
}
540-
if (!(unw_is_signal_frame = dlsym(libhandle, UL_PREFIX PREFIX "_is_signal_frame"))) {
537+
if ((unw_is_signal_frame = dlsym(libhandle, UL_PREFIX PREFIX "_is_signal_frame")) == NULL) {
541538
goto bail_out;
542539
}
543-
if (!(unw_getcontext = dlsym(libhandle, U_PREFIX PREFIX "_getcontext"))) {
540+
if ((unw_getcontext = dlsym(libhandle, U_PREFIX PREFIX "_getcontext")) == NULL) {
544541
goto bail_out;
545542
}
546543
}
544+
#endif
545+
546+
vmp_native_traces_enabled = 1;
547547

548-
#if defined(__unix__)
548+
#ifdef VMPROF_LINUX
549549
return vmp_read_vmaps("/proc/self/maps");
550-
#elif defined(__APPLE__)
551-
return vmp_read_vmaps(NULL);
552-
#endif
553550
bail_out:
554551
vmprof_error = dlerror();
555552
fprintf(stderr, "could not load libunwind at runtime. error: %s\n", vmprof_error);
556553
vmp_native_traces_enabled = 0;
557554
return 0;
555+
#else
556+
return vmp_read_vmaps(NULL);
557+
#endif
558558
}
559559

560560
void vmp_native_disable(void) {

0 commit comments

Comments
 (0)