Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc sanitizer: unmap_shadow_on_exit not honored with custom SIGSEGV handler

GCC sanitizer on 64 bit systems creates huge core files of about 17TB.

If you want a core for post-mortal analysis you need to pass the following options to sanitizer:

  • unmap_shadow_on_exit = 1 - unmaps the huge memory, used for house keeping at exit

  • disable_core = 0 - created core files on 64bit system

    However, if you handle SIGSEGV with your own signal handler, unmap_shadow_on_exit doesn't work and a huge core file is created.

Any ideas how force unmap_shadow_on_exit to do it's job?

like image 992
dimba Avatar asked May 05 '16 05:05

dimba


1 Answers

The regular signal handler is not lost but returned when you set your customer handler -- hence what might work would be to simply invoke that code as part of your own signal handler after after you are done with whatever functionality you have in your own handler.

So something like;

sighandler_t oldSigHandler = 0;
void mySigHandler(int sig) {
   ... your code ...
   if (oldSigHandler) oldSigHandler(sig);
}

void setMySignalHandler(int sig) {
   oldSigHandler = signal(sig, mySigHandler);
}

I generally think of signal handlers as evil, and try to avoid them -- but this may work for you.

Alternatively, if all you want is just to avoid the core dump file, you could try to restrict the allowed size of the core dump using ulimit -c from the shell or programmatic from within your own code -- however core files truncated this way does not always work with gdb that is a need you have.

like image 165
Soren Avatar answered Dec 07 '22 13:12

Soren