[PATCH v10 25/28] gnu directives: add support for .gnu_attribute and .gnu_subsection in OAv2 context

Jan Beulich jbeulich@suse.com
Fri Dec 19 09:08:34 GMT 2025
On 20.11.2025 18:59, Matthieu Longo wrote:
> --- a/bfd/elf-attrs.c
> +++ b/bfd/elf-attrs.c
> @@ -605,12 +605,13 @@ obj_attr_subsection_scope_v2_t
>  bfd_elf_obj_attr_subsection_v2_scope (const bfd *abfd, const char *subsec_name)
>  {
>    const char *vendor_name = get_elf_backend_data (abfd)->obj_attrs_vendor;
> +  obj_attr_subsection_scope_v2_t scope = OA_SUBSEC_PRIVATE;
>    size_t vendor_name_len = strlen (vendor_name);
> -  obj_attr_subsection_scope_v2_t scope
> -    = (strncmp (subsec_name, vendor_name, vendor_name_len) == 0
> -       && subsec_name[vendor_name_len] == '_'
> -       ? OA_SUBSEC_PUBLIC
> -       : OA_SUBSEC_PRIVATE);
> +  if ((strncmp (subsec_name, vendor_name, vendor_name_len) == 0
> +       && subsec_name[vendor_name_len] == '_')
> +      || (strncmp (subsec_name, "gnu_", 4) == 0
> +	  && !gnu_testing_namespace (subsec_name)))
> +    scope = OA_SUBSEC_PUBLIC;
>    return scope;
>  }

Please have this change focus on what is actually in need of changing. I.e.
either stick to using a conditional expression, or avoid use of one right
when the function is first introduced. There really is no value in such
extra churn.

> --- a/gas/config/obj-elf-attr.c
> +++ b/gas/config/obj-elf-attr.c
> @@ -1272,4 +1272,38 @@ obj_elf_gnu_attribute (int ignored ATTRIBUTE_UNUSED)
>    obj_attr_process_attribute (OBJ_ATTR_GNU);
>  }
>  
> +#if (TC_OBJ_ATTR_v2)
> +/* Return True if the VERSION of object attributes supports subsections, False
> +   otherwise.  */
> +
> +static inline bool
> +attr_fmt_has_subsections (obj_attr_version_t version)
> +{
> +  switch (version)
> +  {
> +  case OBJ_ATTR_V1:
> +    return false;
> +  case OBJ_ATTR_V2:
> +    return true;
> +  default:
> +    abort ();  /* Unsupported format.  */
> +  }

Is it really guaranteed that OBJ_ATTR_VERSION_NONE and OBJ_ATTR_VERSION_UNSUPPORTED
can't make it here, e.g. ...

> +}
> +
> +/* Parse a .gnu_subsection directive.  */
> +
> +void
> +obj_elf_gnu_subsection (int ignored ATTRIBUTE_UNUSED)
> +{
> +  obj_attr_version_t version = elf_obj_attr_version (stdoutput);
> +  if (! attr_fmt_has_subsections (version))

... when coming from here? Patch 05 sets it from ->default_obj_attr_version,
but what is unclear to me is whether that default setting can't later be
overridden. After all the comment there only says "recommended".

Jan


More information about the Binutils mailing list