It is known that certain symmetric gauge theories can only exist on the surface of a higher dimensional symmetry protected topological (SPT) state, in which case the symmetric gauge theory is termed anomalous. The anomaly class of such a gauge theory is represented by the bulk SPT index. Given an anomaly class, what kinds of symmetric gauge theories are allowed? Based on physical arguments and tensor-network constructions, we point out a sharp mathematical relationship between the symmetry properties of Abelian gauge theories and the anomaly class: the cup product. When the physical system hosts Lieb-Schultz-Mattis-type constraints, which is a specific type of anomaly class, our result sharply determines the physically allowed symmetric gauge theories as the preimage of the cup product. Various examples are given as an application, including the computation of physically allowed skyrmion quantum numbers in various Neel states in 2+1D, and gauge charge/monopole projective representations in U(1) quantum spin liquids in 3+1D.