Hi !
When I am compiling Ngpsice with -fsanitize=address LD and C Flags I'm getting errors like ;
ngspice/src/misc/alloc.c:111: undefined reference to rpl_realloc
As a quick check I have just compiled ngspice with the -fsanitize=address flag on macOS Catalina, 10.15. It compiles and links out-of-the-box, and runnng ngspice yields some additional output. So it might be a question of an appropriate setup of the compile environment, not of additional tweaking ngspice.
Last edit: Holger Vogt 2020-01-03
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry for long pause
About Valgrind - it's external app , it's great possibility to check critical things like incorrect work with event_alloc or analog_allog "out-of-the-box".
So it just propose to see errors in terminal just in time.
Thanks for reply anyway
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have been able to compile ngspice on Linux (SUSE 15.1, 64 bit, at least for now until it started compiling the code models, when it detected a memory leak in cmpp and stopped) by editing ngspice/configure.ac lines 635 ff., commenting out #AC_FUNC_MALLOC and #AC_FUNC_REALLOC:
You can try to set ASAN_OPTIONS=halt_on_error=0 env variable.
But it's experimental thing, so it can be unstable.
I will try to do one thing with Ngspice cinfig file and place results here
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, it worked!
I've removed #define malloc rplmalloc and #define realloc rplrealloc from config.h to skip errors with "undefined reference". Is it dangerous or it's hard to tell?
To continue compiling during leaks just before compiling type : export ASAN_OPTIONS=halt_on_error=0
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
— Macro: AC_FUNC_MALLOC
If the malloc function is compatible with the GNU C library malloc (i.e., ‘malloc (0)’ returns a valid pointer), define HAVE_MALLOC to 1. Otherwise define HAVE_MALLOC to 0, ask for an AC_LIBOBJ replacement for ‘malloc’, and define malloc to rpl_malloc so that the native malloc is not used in the main project.
Typically, thereplacementfilemalloc.cshouldlooklike(notethe ‘#undefmalloc’):
#ifHAVE_CONFIG_H
# include<config.h>
#endif
#undefmalloc
#include<sys/types.h>void*malloc();/* Allocate an N-byte block of memory from the heap. If N is zero, allocate a 1-byte block. */void*rpl_malloc(size_tn)
{
if(n==0)n=1;returnmalloc(n);
}
We check for the GNU compatible malloc, and obviously normally (Linux, Cygwin, MINGW, macOS ...) it is. With the -fsanitize option, it seems to not be compatible, because the test fails. For this case we should have provided the function as cited from the website above. Same for realloc().
If we never use malloc(n) with n=0, then we do not need to do the AC_FUNC_MALLOC check. If we always have a GNU compatible malloc(), again we don't need it. If I look at alloc.c, we use tmalloc(n) which checks for n==0, returning NULL, so not being GNU compatible (and thus not needing AC_FUNC_MALLOC ). There are some spurious plain malloc() in the code (XSPICE, or newly added code from Jim). Probably we can skip AC_FUNC_MALLOC.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There are no plans to do so.
What about running ngspice wit valgrind? This is what I use to find memory leaks or check for read beyond bounds.
As a quick check I have just compiled ngspice with the -fsanitize=address flag on macOS Catalina, 10.15. It compiles and links out-of-the-box, and runnng ngspice yields some additional output. So it might be a question of an appropriate setup of the compile environment, not of additional tweaking ngspice.
Last edit: Holger Vogt 2020-01-03
Sorry for long pause
About Valgrind - it's external app , it's great possibility to check critical things like incorrect work with event_alloc or analog_allog "out-of-the-box".
So it just propose to see errors in terminal just in time.
Thanks for reply anyway
I have been able to compile ngspice on Linux (SUSE 15.1, 64 bit, at least for now until it started compiling the code models, when it detected a memory leak in cmpp and stopped) by editing ngspice/configure.ac lines 635 ff., commenting out
#AC_FUNC_MALLOC
and#AC_FUNC_REALLOC
:This has been reported in https://github.com/maxmind/libmaxminddb/issues/144.
Do you know a switch to tell sanitize just to move on, not to stop?
You can try to set ASAN_OPTIONS=halt_on_error=0 env variable.
But it's experimental thing, so it can be unstable.
I will try to do one thing with Ngspice cinfig file and place results here
Yes, it worked!
I've removed #define malloc rplmalloc and #define realloc rplrealloc from config.h to skip errors with "undefined reference". Is it dangerous or it's hard to tell?
To continue compiling during leaks just before compiling type :
export ASAN_OPTIONS=halt_on_error=0
Hi guys,
so, do we have a bug in NGSPICE to use this feature or not? I didn't understand the outcome here.
Thank you,
Fra
It is about AC_FUNC_MALLOC, see https://www.gnu.org/software/autoconf/manual/autoconf-2.60/html_node/Particular-Functions.html.
Cited from this manual:
— Macro: AC_FUNC_MALLOC
If the malloc function is compatible with the GNU C library malloc (i.e., ‘malloc (0)’ returns a valid pointer), define HAVE_MALLOC to 1. Otherwise define HAVE_MALLOC to 0, ask for an AC_LIBOBJ replacement for ‘malloc’, and define malloc to rpl_malloc so that the native malloc is not used in the main project.
We check for the GNU compatible malloc, and obviously normally (Linux, Cygwin, MINGW, macOS ...) it is. With the -fsanitize option, it seems to not be compatible, because the test fails. For this case we should have provided the function as cited from the website above. Same for realloc().
If we never use malloc(n) with n=0, then we do not need to do the AC_FUNC_MALLOC check. If we always have a GNU compatible malloc(), again we don't need it. If I look at alloc.c, we use tmalloc(n) which checks for n==0, returning NULL, so not being GNU compatible (and thus not needing AC_FUNC_MALLOC ). There are some spurious plain malloc() in the code (XSPICE, or newly added code from Jim). Probably we can skip AC_FUNC_MALLOC.
Hi Holger,
ok, but can we assume we don't enter into this case or do we force a code style to avoid such situation?
Thank you,
Fra