When a house is built, it has plywood put down called decking on to which the shingles are nailed. If its a tiled roof it has a water proof barrier put down then the tiles (the tiles don’t stop the rain, its the barrier under them.) Where there is a plumbing vent penetrating the decking or barrier, a square hole is usually cut and the vent is put through. Now a square hole isn’t going to be water tight, so there has to be a method to sealing it. This is the flashing. The attached picture shows what a lead flashing looks like prior to being installed. The flashing is put on the pipe prior to the shingles or tiles being put downs, the foot nailed in place with some sealant, and the top is folded over the pipe making a seal. Then the tiles or shingles are put on. Should last the life of the house, but then those squirrels show up.