In chapter 19 of An Introduction to Quantum Field Theory by Peskin & Schroeder, they discuss spontaneous symmetry breaking (SSB) at low energies in massless (or nearly massless) QCD, given by $$\mathcal{L}_{\text{QCD}} = \bar{Q} (i\gamma^{\mu}D_{\mu}) Q - m\bar{Q}Q,$$ where $Q = \left( \begin{matrix} u \\ d \end{matrix}\right)$ is an $SU(2)$ quark doublet.
Due to quark-antiquark pairs being produced from the vacuum at low energies (the $q\bar{q}$ condensate), we have a non-zero vacuum expectation value (vev), which results in SSB of the global $SU(2)_A$ symmetry. For massless QCD, this is an exact symmetry so 3 goldstone bosons [one for each generator of $SU(2)$] appear. For massive QCD (where the quark masses are small), the mass term in $\mathcal{L}_{\text{QCD}}$ demotes this to an approximate symmetry, and so we obtain 3 massive pseudo-Goldstone bosons.
If we take the quark masses to be small (and so we have an approximate symmetry), they show (eq 19.92) that we have a partially conserved axial current (PCAC relation) from pion production from the vev, via $$ \langle 0 | \partial_{\mu} j^{\mu,a}_5 | \pi^b(p) \rangle = - p^2 f_{\pi} \delta^{ab} \quad \Rightarrow \quad \partial_{\mu} j^{\mu,a}_5 \propto m_{\pi}^2,$$ where $m_{\pi}$ is the mass of the pseudo-Goldstone bosons produced from SSB.
So if we have massive quarks in $\mathcal{L}_{\text{QCD}}$, then we have an approximate symmetry and obtain 3 massive pseudo-Goldstone bosons through SSB. If we have massless quarks in $\mathcal{L}_{\text{QCD}}$, then we have an exact symmetry and obtain 3 massless Goldstone bosons.
Now, here is the problem I am struggling to answer. In the text, they refer to these goldstones as being the three pions $\pi^+$, $\pi^-$, and $\pi^0$. From measurements, we know pions are massive particles. From the above reasoning, if the goldstones from SSB of QCD are in fact pions, there must be non-zero quark masses in the QCD Lagrangian. However, the usual Dirac mass terms violate the electroweak gauge symmetry $SU(2)_L \times U(1)_Y$, so it's not possible to have these mass terms appear in the Standard Model, and quarks must obtain their mass via the Higgs mechanism from SSB of the electroweak gauge group.
So, to preserve gauge invariance in the Standard Model $SU(3)_c \times SU(2)_L \times U(1)_Y$, we must then have that there are no quark mass terms and the global axial symmetry is exact, meaning our Goldstone bosons are massless and cannot be the same particles as pions. This seems to be a complete contradiction, and I really don't understand how we can have both massive pions that correspond to pseudo-goldstones and not break gauge invariance in the SM Lagrangian.
As a side question, I don't understand the logical jump made associating pions with the Goldstone fields in the first place. Pions are composite particles consisting of $u$ and $d$ quarks, so why should/can they even be candidates to Goldstone/pseudo-Goldstones bosons? It makes sense that they are related to the $q\bar{q}$ condensate in QCD due to the nature of their composition, but other than this I fail to see the connection.