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.cfa

    r2ed94a9 rb110bcc  
    1010// Created On       : Wed Mar 29 16:10:31 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jan  5 22:23:57 2023
    13 // Update Count     : 180
    14 //
    15 
    16 #include <stdarg.h>                                                                             // va_start, va_end
     12// Last Modified On : Mon Mar 27 21:09:03 2023
     13// Update Count     : 196
     14//
     15
    1716#include <stdio.h>
    18 #include <string.h>                                                                             // strlen
    1917#include <unistd.h>                                                                             // _exit, getpid
    20 #include <signal.h>
    2118extern "C" {
    2219#include <dlfcn.h>                                                                              // dlopen, dlsym
     
    2421}
    2522
    26 #include "bits/debug.hfa"
    2723#include "bits/defs.hfa"
    2824#include "bits/signal.hfa"                                                              // sigHandler_?
     
    4036
    4137typedef void (* generic_fptr_t)(void);
     38
    4239static generic_fptr_t do_interpose_symbol( void * library, const char symbol[], const char version[] ) {
    43         const char * error;
    44 
    4540        union { generic_fptr_t fptr; void * ptr; } originalFunc;
    4641
    4742        #if defined( _GNU_SOURCE )
    48                 if ( version ) {
    49                         originalFunc.ptr = dlvsym( library, symbol, version );
    50                 } else {
    51                         originalFunc.ptr = dlsym( library, symbol );
    52                 }
     43        if ( version ) {
     44                originalFunc.ptr = dlvsym( library, symbol, version );
     45        } else {
     46                originalFunc.ptr = dlsym( library, symbol );
     47        } // if
    5348        #else
    54                 originalFunc.ptr = dlsym( library, symbol );
     49        originalFunc.ptr = dlsym( library, symbol );
    5550        #endif // _GNU_SOURCE
    5651
    57         error = dlerror();
    58         if ( error ) abort( "interpose_symbol : internal error, %s\n", error );
    59 
     52        if ( ! originalFunc.ptr ) {                                                     // == nullptr
     53                abort( "interpose_symbol : internal error, %s\n", dlerror() );
     54        } // if
    6055        return originalFunc.fptr;
    6156}
    6257
    6358static generic_fptr_t interpose_symbol( const char symbol[], const char version[] ) {
    64         const char * error;
    65 
    66         static void * library;
    67         static void * pthread_library;
    68         if ( ! library ) {
    69                 #if defined( RTLD_NEXT )
    70                         library = RTLD_NEXT;
    71                 #else
    72                         // missing RTLD_NEXT => must hard-code library name, assuming libstdc++
    73                         library = dlopen( "libc.so.6", RTLD_LAZY );
    74                         error = dlerror();
    75                         if ( error ) {
    76                                 abort( "interpose_symbol : failed to open libc, %s\n", error );
    77                         }
    78                 #endif
     59        void * library;
     60
     61        #if defined( RTLD_NEXT )
     62        library = RTLD_NEXT;
     63        #else
     64        // missing RTLD_NEXT => must hard-code library name, assuming libstdc++
     65        library = dlopen( "libc.so.6", RTLD_LAZY );
     66        if ( ! library ) {                                                                      // == nullptr
     67                abort( "interpose_symbol : failed to open libc, %s\n", dlerror() );
    7968        } // if
    80         if ( ! pthread_library ) {
    81                 #if defined( RTLD_NEXT )
    82                         pthread_library = RTLD_NEXT;
    83                 #else
    84                         // missing RTLD_NEXT => must hard-code library name, assuming libstdc++
    85                         pthread_library = dlopen( "libpthread.so", RTLD_LAZY );
    86                         error = dlerror();
    87                         if ( error ) {
    88                                 abort( "interpose_symbol : failed to open libpthread, %s\n", error );
    89                         }
    90                 #endif
    91         } // if
    92 
    93         return do_interpose_symbol(library, symbol, version);
     69        #endif // RTLD_NEXT
     70
     71        return do_interpose_symbol( library, symbol, version );
    9472}
    9573
     
    12199                preload_libgcc();
    122100
    123 #pragma GCC diagnostic push
    124 #pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
     101                #pragma GCC diagnostic push
     102                #pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
    125103                INTERPOSE_LIBC( abort, version );
    126104                INTERPOSE_LIBC( exit , version );
    127 #pragma GCC diagnostic pop
     105                #pragma GCC diagnostic pop
    128106
    129107                if(__cfathreadabi_interpose_startup) __cfathreadabi_interpose_startup( do_interpose_symbol );
     108
     109                // SKULLDUGGERY: In Ubuntu 22.04, someone augmented signal.h to allow SIGSTKSZ to be "sysconf(_SC_SIGSTKSZ)" in
     110                // sigstksz.h, as well as 8192 in sigstack.h. HOWEVER, they forgot to provide a mechanism to tell signal.h to
     111                // use sigstack.h rather than sigstksz.h. (I'm not happy.) By undefining _GNU_SOURCE before signal.h and
     112                // redefining it afterwards, you can get 8192, but then nothing works correctly inside of signal.h without
     113                // _GNU_SOURCE defined.  So what is needed is a way to get signal.h to use sigstack.h WITH _GNU_SOURCE defined.
     114                // Basically something is wrong with features.h and its use in signal.h.
     115
     116                #undef SIGSTKSZ
     117                #define SIGSTKSZ 8192
    130118
    131119                // As a precaution (and necessity), errors that result in termination are delivered on a separate stack because
     
    293281        va_start( args, fmt );
    294282        __abort( false, fmt, args );
    295     // CONTROL NEVER REACHES HERE!
     283        // CONTROL NEVER REACHES HERE!
    296284        va_end( args );
    297285}
    298286
    299287void abort( bool signalAbort, const char fmt[], ... ) {
    300     va_list args;
    301     va_start( args, fmt );
    302     __abort( signalAbort, fmt, args );
    303     // CONTROL NEVER REACHES HERE!
    304     va_end( args );
     288        va_list args;
     289        va_start( args, fmt );
     290        __abort( signalAbort, fmt, args );
     291        // CONTROL NEVER REACHES HERE!
     292        va_end( args );
    305293}
    306294
Note: See TracChangeset for help on using the changeset viewer.