From 44d46432c41ddbb85e4a4d8395ad7a30d7e5a36e Mon Sep 17 00:00:00 2001 From: EbsHirani Date: Thu, 18 Apr 2024 17:39:44 -0700 Subject: [PATCH] Handle NULL return value from dlopen --- coz | 7 +++++++ libcoz/real.cpp | 2 ++ 2 files changed, 9 insertions(+) diff --git a/coz b/coz index b195eca..f7654cc 100755 --- a/coz +++ b/coz @@ -106,6 +106,9 @@ def _coz_run(args): if args.fixed_speedup != None: env['COZ_FIXED_SPEEDUP'] = str(args.fixed_speedup) + if args.debug_libraries: + env['LD_DEBUG'] = 'libs' + try: result = subprocess.call(args.remaining_args, env=env) except KeyboardInterrupt: @@ -185,6 +188,10 @@ _run_parser.add_argument('--fixed-speedup', type=int, choices=list(range(0, 101)), default=None, help='Evaluate optimizations of a specific amount') +_run_parser.add_argument('--debug-libraries', + action='store_true', default=False, + help='Debug shared libraries (LD_DEBUG=libs)') + # Use defaults to recover handler function and parser object from parser output _run_parser.set_defaults(func=_coz_run, parser=_run_parser) diff --git a/libcoz/real.cpp b/libcoz/real.cpp index 8e7c063..057acd9 100644 --- a/libcoz/real.cpp +++ b/libcoz/real.cpp @@ -6,6 +6,7 @@ */ #include "real.h" +#include "ccutil/log.h" #include @@ -37,6 +38,7 @@ static void* pthread_handle = NULL; //< The `dlopen` handle to libpthread static void* get_pthread_handle() { if(pthread_handle == NULL && !__atomic_exchange_n(&in_dlopen, true, __ATOMIC_ACQ_REL)) { pthread_handle = dlopen("libpthread.so.0", RTLD_NOW | RTLD_GLOBAL); + REQUIRE(pthread_handle != NULL) << dlerror(); __atomic_store_n(&in_dlopen, false, __ATOMIC_RELEASE); }