Hilbert's irreducibility theorem and $G$-functions