Check if the symbol exists before checking its visibility.

Should fix #1348.