Handle NULL return value from dlopen

This commit is contained in:
EbsHirani 2024-04-18 17:39:44 -07:00 committed by Noah Lev
parent 2ffc5b2798
commit 44d46432c4
2 changed files with 9 additions and 0 deletions

7
coz
View File

@ -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)

View File

@ -6,6 +6,7 @@
*/
#include "real.h"
#include "ccutil/log.h"
#include <dlfcn.h>
@ -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);
}