Ignore:
Timestamp:
Apr 21, 2023, 5:36:12 PM (2 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, master
Children:
28f8f15, 6e4c44d
Parents:
2ed94a9 (diff), 699a97d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/interpose_thread.cfa

    r2ed94a9 rb110bcc  
    1414//
    1515
    16 #include <stdarg.h>                                                                             // va_start, va_end
    17 #include <stdio.h>
    18 #include <string.h>                                                                             // strlen
     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
    1921#include <signal.h>
    2022#include <pthread.h>
     23#include <signal.h>
    2124extern "C" {
    2225#include <dlfcn.h>                                                                              // dlopen, dlsym
    23 #include <execinfo.h>                                                                   // backtrace, messages
    2426}
    2527
    26 #include "bits/debug.hfa"
    2728#include "bits/defs.hfa"
    28 #include <assert.h>
    2929
    3030//=============================================================================================
     
    3434typedef void (* generic_fptr_t)(void);
    3535
    36 generic_fptr_t interpose_symbol(
     36generic_fptr_t libcfa_public 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 ) libcfa_public {
    41         const char * error;
     40) {
     41        void * library;
    4242
    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
     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() );
    5550        } // if
     51        #endif // RTLD_NEXT
    5652
    57         return do_interpose_symbol(library, symbol, version);
     53        return do_interpose_symbol( library, symbol, version );
    5854}
    5955
     
    8379#pragma GCC diagnostic push
    8480#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
    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 );
     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 );
    9591#pragma GCC diagnostic pop
    9692        }
Note: See TracChangeset for help on using the changeset viewer.