Today we are faced with an unusual phenomenon, a colleague called a normally functioning function in his code that called segfault in libc (gethostbyname). The mysterious thing was that the same function worked without problems in other source files at the same runtime. Surprisingly, segfault disappeared when valgrind was used, in fact it worked perfectly with valgrind, without errors.
After many sacrifices, in order to reassure the gods of the compiler, we finally realized that the header file declaring the function was not in the source file that called this function. Once we added this, everything works fine.
Why does gcc / ld not generate an error (or even a warning) indicating that the function was not recognized ?, why does it work with valgrind?
Thank.
source
share