Here a cop can only search if he has probable cause, and he can only search where he thinks where something is hidden. Like if they think you have drugs, they can search wherever the **** they want, but if they think you have like an assault rifle, they cannot search your glovebox (since an assault rifle wont' fit), but if he is searching due to weed or something that can fit, they can very well search your glovebox.
If the police arrest the driver for something, (say for having warrants or a DWI) then they automatically have the right to search the passenger compartment including the glovebox but not the trunk.