How do Tour de France riders go to the toilet? Generally, they pull over to the side of the road, stop, and shed liquid ballast in the usual way.
Sometime in the first couple of hours of the race, a senior rider (a team leader) will organize a comfort break and the whole peloton will slow down enough that riders can stop for a break and easily catch up afterwards.
A rider should not attack while a large-scale comfort break is in progress, and you certainly don't attack the yellow jersey when he's taking a break. If the stage is short, fast or very hot it may simply not be necessary, but on a cold morning at the beginning of a long day's trek will almost certainly happen.
If a rider needs to go outside of an organized stop, that's another situation where team-work comes into play.
Along with a couple of team-mates, the rider will drop back in the peloton, and move to the side of the road. While his team-mates push him along at the back of the bunch, he'll take a mobile comfort break.
It's considered extremely rude if photographers and TV shoot this whole process which is why we never see it on TV or in pictures.
It seems also, that on a not day, perspiration takes care of the whole process.