Spontaneous scalarization of black holes and compact stars from a Gauss-Bonnet coupling