[PATCH v7 02/19] gas: move code for object attribute parsing into obj-elf-attr.c

Matthieu Longo matthieu.longo@arm.com
Tue Jul 15 10:53:56 GMT 2025


On 2025-07-15 09:53, Jan Beulich wrote:
> On 14.07.2025 18:58, Matthieu Longo wrote:
>> Gas, contrarilly to others binutils tools, is compiled for a specific
>> target. Some targets don't support Object Attributes (OAs). For those
>> cases, today the OA directive ".gnu_attribute" is still enabled but the
>> processing would probably fail in most of cases because the named tag
>> would be unknown. Most of the parsing code on such a target can be
>> considered as dead code.
>>
>> This patch aims at removing this dead code from Gas when the target does
>> not support the OAs by:
>> - moving the code of OA parsing into a separate file under gas/config
>>    which is only included for the relevant targets supporting OAs.
>> - disabling the code related to OAs on non-OA target via a TC_OBJ_ATTR
>>    macro.
>>
>> Adding/removing the OA feature from Gas for a specific target can easilly
>> be done from tc-<arch>.h by changing the values of TC_OBJ_ATTR: 1 enabled,
>> 0 disabled. You might also want to guard the enablement of OAs only for
>> ELF targets with OBJ_ELF (see example below).
>>
>> \#ifdef OBJ_ELF
>> /* The target supports Object Attributes.  */
>> \#define TC_OBJ_ATTR 1
>> \#endif
> 
> In principle okay, but see below.
> 
>> --- a/gas/config/tc-mips.h
>> +++ b/gas/config/tc-mips.h
>> @@ -217,4 +217,9 @@ extern bfd_reloc_code_real_type mips_cfi_reloc_for_encoding (int encoding);
>>   #define CONVERT_SYMBOLIC_ATTRIBUTE(name) mips_convert_symbolic_attribute (name)
>>   extern int mips_convert_symbolic_attribute (const char *);
>>   
>> +#ifdef OBJ_ELF
>> +/* The target supports Object Attributes.  */
>> +#define TC_OBJ_ATTR 1
>> +#endif
> 
> Taking this as an example: On the same basis that using OBJ_MAYBE_ELF isn't
> necessary here (MIPS only supporting ELF targets, and hence not supporting
> a mix of object formats through emulation) you don't really need to check
> OBJ_ELF here then as well.
> 
> IOW - I'd prefer if all unnecessary checks of OBJ_ELF would be stripped off
> this patch.
> 

I had a look at ./gas/configure.tgt and found the following supported 
formats for the platforms supporting object attributes.

- ARC: ELF only.
- AArch32: ELF & COFF.
- AArch64: ELF & COFF.
- CSky: ELF only.
- m68k: ELF only.
- msp430: ELF only.
- MIPS: ELF only.
- PowerPC: ELF & COFF.
- RISC-V: ELF only.
- S390: ELF only.
- SPARC: ELF only.
- TI C6X: ELF only.

Which means that, in the next revision, I will remove the OBJ_ELF guard 
in all the tc-<arch>.h, except for AArch32, AArch64, and PowerPC.

>> --- a/gas/configure.ac
>> +++ b/gas/configure.ac
>> @@ -454,6 +454,19 @@ changequote([,])dnl
>>   	;;
>>       esac
>>   
>> +    # Does the target support Object Attributes ?
>> +    case ${cpu_type} in
>> +      arc* | arm* | csky | m68k | mips* | msp430 | powerpc* \
>> +      | riscv* | s390* | sparc* | tic6x)
>> +	for f in config/obj-elf-attr.o; do
>> +	  case " $extra_objects " in
>> +	    *" $f "*) ;;
>> +	    *) extra_objects="$extra_objects $f" ;;
>> +	  esac
>> +	done
>> +	;;
>> +    esac
> 
> The okay is further based on the assumption that my earlier understanding
> was wrong, and Arm64 in fact didn't / doesn't support v1 object attributes.
> 
> Jan

Yes, as replied in another thread, AArch64 has never supported OAv1.

Matthieu


More information about the Binutils mailing list