Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/interpose_thread.cfa

    re10714a r7f81ef4  
    1414//
    1515
    16 // BUG in 32-bit gcc with interpose: fixed in >= gcc-9.5, gcc-10.4, gcc-12.2
    17 #ifdef __i386__                                                                                 // 32-bit architecture
    18 #undef _GNU_SOURCE
    19 #endif // __i386__
    20 
     16#include <stdarg.h>                                                                             // va_start, va_end
     17#include <stdio.h>
     18#include <string.h>                                                                             // strlen
    2119#include <signal.h>
    2220#include <pthread.h>
    23 #include <signal.h>
    2421extern "C" {
    2522#include <dlfcn.h>                                                                              // dlopen, dlsym
     23#include <execinfo.h>                                                                   // backtrace, messages
    2624}
    2725
     26#include "bits/debug.hfa"
    2827#include "bits/defs.hfa"
     28#include <assert.h>
    2929
    3030//=============================================================================================
     
    3434typedef void (* generic_fptr_t)(void);
    3535
    36 generic_fptr_t libcfa_public interpose_symbol(
     36generic_fptr_t interpose_symbol(
    3737        generic_fptr_t (*do_interpose_symbol)( void * library, const char symbol[], const char version[] ),
    3838        const char symbol[],
    3939        const char version[]
    40 ) {
    41         void * library;
     40) libcfa_public {
     41        const char * error;
    4242
    43         #if defined( RTLD_NEXT )
    44         library = RTLD_NEXT;
    45         #else
    46         // missing RTLD_NEXT => must hard-code library name, assuming libstdc++
    47         library = dlopen( "libpthread.so", RTLD_LAZY );
    48         if ( ! library ) {                                                                      // == nullptr
    49                 abort( "interpose_symbol : failed to open libpthread, %s\n", dlerror() );
     43        static void * library;
     44        if ( ! library ) {
     45                #if defined( RTLD_NEXT )
     46                        library = RTLD_NEXT;
     47                #else
     48                        // missing RTLD_NEXT => must hard-code library name, assuming libstdc++
     49                        library = dlopen( "libpthread.so", RTLD_LAZY );
     50                        error = dlerror();
     51                        if ( error ) {
     52                                abort( "interpose_symbol : failed to open libpthread, %s\n", error );
     53                        }
     54                #endif
    5055        } // if
    51         #endif // RTLD_NEXT
    5256
    53         return do_interpose_symbol( library, symbol, version );
     57        return do_interpose_symbol(library, symbol, version);
    5458}
    5559
     
    7983#pragma GCC diagnostic push
    8084#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
    81                 INTERPOSE( pthread_create, version );
    82                 INTERPOSE( pthread_join, version );
    83                 INTERPOSE( pthread_self, version );
    84                 INTERPOSE( pthread_attr_init, version );
    85                 INTERPOSE( pthread_attr_destroy, version );
    86                 INTERPOSE( pthread_attr_setstack, version );
    87                 INTERPOSE( pthread_attr_getstacksize, version );
    88                 INTERPOSE( pthread_sigmask, version );
    89                 INTERPOSE( pthread_sigqueue, version );
    90                 INTERPOSE( pthread_once, version );
     85                INTERPOSE( pthread_create , version );
     86                INTERPOSE( pthread_join , version );
     87                INTERPOSE( pthread_self , version );
     88                INTERPOSE( pthread_attr_init , version );
     89                INTERPOSE( pthread_attr_destroy , version );
     90                INTERPOSE( pthread_attr_setstack , version );
     91                INTERPOSE( pthread_attr_getstacksize , version );
     92                INTERPOSE( pthread_sigmask , version );
     93                INTERPOSE( pthread_sigqueue , version );
     94                INTERPOSE( pthread_once , version );
    9195#pragma GCC diagnostic pop
    9296        }
Note: See TracChangeset for help on using the changeset viewer.