libdl: better checking and logging for ctors/dtors