If a gun sits on a table in a room and a dog walks in alone, will he still freak out at the gun? If you were accosted by an armed man they certainly would strike. If you took them to the shooting range they would lose their minds. Dog's do not seem to like guns but the question still stands, if it was a lone gun in a room with your lone dog, would they still lose it? It is a good question because it would determine whether or not dogs have some innate fear of guns, like a cat to a cucumber, or if the hate of guns we see is more situational.
The Root of the Behavior
As it turns out, a dog would not likely be afraid of a stationary gun alone in a room. Canine's seemingly have an issue with firearms but it is more specifically a fear of the situation they are in or the lights and sounds generated by a weapon in use. Canine's communicate through body language. To them, it is their first language. So when you see someone approach you with a gun, the little guy in the back of your mind might say "Oh crap, he has a gun, I could get hurt". Your dog see's you. Your eyes widening and pupils dilating, your hands raising in front of your eyes for some innate form of protection, your skin going flush and your heart rate accelerating. To them, this is as clear as if someone pulled a weapon on you. It is a simple form of communication, but easy to understand. They recognize your fear, and what you are afraid of. That is their apparent hate for guns, it is a mirror of your own hate of guns, just a bit more fearless as they do not have an understanding of what a gun is or does.
Dog owners who have firearms themselves go through something similar, but from a different cause. If you take your dog to the range, whenever you fire off a round, your dog is likely to lose their cool. This is due to the auditory and visual effects of the weapon. The loud bang, violent weapon flash and the force of the recoil. These are the things your dog is reacting to, and not necessarily the gun itself. After they understand that the gun is and where this frightful sound and force comes from, then whenever you go to fire it they may react before hand. They have learned that after you take aim, that sound and flash are sure to follow, and so their behavior is to prevent you from firing the weapon.
Encouraging the Behavior
You can change this behavior in some ways, but it really depends on what you want. If you want to be able to take your dog to the range and they do not lose their minds, this can be done through some training. However, do you want your dog to be ambivalent about firearms? If they see a gun raised, would you not want them to lose their minds and go after the attacker? Unfortunately, these things kind of go hand in hand. If you teach your dog that a gun is nothing to be afraid of, they will not be afraid or cautious of them. This behavior may come from simply a fear of the loud noise. If your dog is afraid of thunder, they won't react much better to a rifle firing. The sense of hearing they have is much above our own, and so through the discharge of a weapon is deafening to us, it can excruciating to their heightened sense of sound. You should be able to tell if this is the case because they react in fear rather then aggression. If they cower and whimper, then you have scared them. These reactions will reduce with more frequent exposure. Once they understand the weapon is not harming you or them, then their fear around weapons will reduce.
Other Solutions and Considerations
Contacting a dog trainer or behavioral specialist will give you a big leg up into understanding your canine's reaction and behavior. They will also help you establish the practices you need to get them to react in the way you would like. A dog with attack training is likely going to have a different perspective on firearms and will likely engage anyone with a firearm due to their training. That being said, they will have had instilled behavioral triggers to get them to stand down. They are not likely reacting out of any sense of fear, but purely based on the behaviors they learned through that type of training.