Happened to me a few times - if you are transiting through GRU and are through checked, you clear passport, customs etc. at GRU. If the baggage can not be through checked because airlines do not interline (eg CO and RG), you will have to clear passport, customs at GRU, go through check in again, and go through passport control etc. once more at GIG as RG GRU-GIG is technically an international flight.
If there is interlining and your bags are through checked to GIG, you do passport control and customs at the final destination, i.e. GIG.