Newton came up with a fairly simple way to estimate how far a projectile can travel through a medium.
Newtons approximation for impact depth
The formula is Depth=Projectile length*projectile density/medium density
So we need some information about our asteroid. Lets assume a nickle-iron asteroid with a density of 7g/cm^3, and a diameter of 10 km.
The density of the sun averages to 1.4g/cm^3, so if the sun had uniformed density the asteroid would stop after traveling 50 km. Clearly not far enough.
But, the density of the sun depends strongly on how deep into the sun you are. At the core the density is 150g/cm^3 - our asteroid would penetrate 466 meters.
Fortunately the outer layers of the sun has much smaller densities.
So the question becomes what do you mean by "going through the sun"? - As established your asteroid will not pass through the sun core, but what about the outer layers? A natural way to view passing through the sun is passing through the photosphere, the point at which the sun becomes opaque to visible light. Here the density is 0,2g/cm^3; Our asteroid can penetrate 350 km through this density. The photosphere is about 100km thick, and we would need to traverse it twice and at an angle. - So the photosphere is on it's own almost enough to stop our asteroid. While the densities outside the photosphere drops quickly, and as such contributes less to slowing our asteroid this is probably enough that our asteroid will fail to penetrate.
Since we almost penetrates the photosphere we should be able to penetrate the chromosphere. I would definitely describe this more as a gracing the sun than going through the sun though. Alternatively we could change the asteroid; An asteroid with a diameter of 100km would penetrate easily.
Considerations that the above ignores;
- Melting and evaporation of the asteroid. While the sun is very hot, the densities we are travelling through is low enough that heating effects from contact is limited. We are also going fast enough that there is not all that much time for heating to occur.
- Xkcd style fusion effects from asteroid impacting the gasses of the sun. I do not think this will affect much; the asteroid is imparting momentum to the gas in front of it. The mechanism of this momentum transfer is not all that interesting.
- Re-shaping of the asteroid; the sun is going to act on the asteroid slowing it down. This force acts on the front of the asteroid. This could cause the asteroid to flatten, lessening the length of projectile term in the approximation above. How much of an effect this has is not a question I am qualified to answer; but I think it's more of a concern if the asteroid barely penetrates, than if it penetrates easily.
- Exit speed. The asteroid will impart momentum to the gasses it is travelling through, thus leave the sun with less speed than it arrived with. I do not know how to calculate how much speed is lost.
- Relativistic mass - traveling at relativistic speeds the asteroid has more momentum than indicated by newtonian physics. This breaks the assumption of the approximation and will mean that you can go further than you would otherwise expect.
Impact on earth.
A 10 km diameter nickle-iron asteroid has a mass of 3.665×10^9 kg. Traveling at 0.1c gives a relativistic energy of 1.659×10^24 joules. WolframAlpha tells us that this is about 3.3 times the energy that was released from the Chicxulub meteor impact. The conclusion is that this would be a mass-extinction event.
The gravitational binding energy of the earth is 2x10^32, so the impact is nowhere near powerful enough to destroy the planet.
If instead we look at 0.9c we get an energy of 4.263×10^26, 100 times more powerful - but still not close to destroying the earth.
The 100 km diameter asteroid that could actually penetrate the photosphere would produce impacts 1000 times more powerful, so at 0.9c would be within 1% of the gravitational binding energy of the earth.