On Mon, 12 Oct 2026, Matt Turner wrote:
> Alexander also suggested doing this in varasm.cc:mark_weak. I kept it
> in apply_pragma_weak because it needs the tls_model attribute, whose
> parsing lives in c-family, and because __attribute__((weak)) already
> sets DECL_WEAK before the model is chosen, so the pragma is the only
> path that gets the order wrong. apply_pragma_weak is shared by the C
> and C++ front ends, so one change covers both. I can move it if you
> would rather have it in mark_weak.
With the necessity to use parse_tls_model from the new code, it is quite
reasonable to keep it in apply_pragma_weak.
FWIW, the patch looks perfect to me except for one issue below, thank you!
Still needs review and approval from a relevant maintainer.
> --- a/gcc/c-family/c-attribs.cc
> +++ b/gcc/c-family/c-attribs.cc
> @@ -3010,6 +3010,29 @@ handle_weakref_attribute (tree *node, tree name, tree
> args,
> return NULL_TREE;
> }
>
> +/* If ID, the argument of a "tls_model" attribute, names a TLS access model,
> + store that model in *KIND and return true. Otherwise return false. */
> +
> +bool
> +parse_tls_model (const_tree id, enum tls_model *kind)
> +{
> + if (TREE_CODE (id) != STRING_CST)
> + return false;
I think this needs to be
gcc_checking_assert (TREE_CODE (id) == STRING_CST);
to properly catch misuse. The defensive 'if' looks like an anti-pattern for GCC.
Sorry for not catching it earlier.
Alexander