It depends. If your domestic flight is operated as an international flight, you don't even go through immigration at GRU.
It's very simple to verify if that is the case. Every international flight at TAM starts with an 8, so if the GRU-GIG flight is styled as JJ 8XXX, you will only need to go through immigration and customs at GIG. If your GRU-GIG flight is JJ 3XXX, then you will need to have everything done at GRU.