It is not at all that cut and dried.
Engaging in sham business activity for the specific purpose of tax avoidance is not legal. Many of these tax schemes could be declared invalid at the discretion of the IRS (or other governments - the EU already has in some cases).
These companies are not complying with tax law. They are cheating and paying bribes or doing favors to get away with it, and everyone knows it.