[PATCH v11 23/25] gnu directives: gas/readelf tests for gnu attributes v2
Jan Beulich
jbeulich@suse.com
Fri Jan 9 09:19:32 GMT 2026
On 31.12.2025 00:05, Matthieu Longo wrote:
> --- a/binutils/testsuite/lib/binutils-common.exp
> +++ b/binutils/testsuite/lib/binutils-common.exp
> @@ -507,6 +507,36 @@ proc gas_sframe_check {} {
> return $check_as_sframe_result
> }
>
> +# Whether a target support Object Attributes v1
> +proc supports_oa_v1 {} {
> + if { ! [is_elf_format] } {
> + return 0
> + }
> + if { [istarget arc-*-*]
> + || [istarget arm*-*-*]
> + || [istarget csky*-*-*]
> + || [istarget loongarch*-*-*]
> + || [istarget m68*-*-*]
> + || [istarget mips*-*-*]
> + || [istarget msp*-*-*]
> + || [istarget powerpc*-*-*]
> + || [istarget riscv*-*-*]
> + || [istarget s390*-*-*]
> + || [istarget sparc*-*-*]
> + || [istarget tic6x*-*-*] } {
> + return 1
> + }
> + return 0
> +}
> +
> +# Whether a target support Object Attributes v2
> +proc supports_oa_v2 {} {
> + if { [is_elf_format] && [istarget aarch64*-*-*] } {
Can this please be split right away like you have now done in
supports_oa_v1?
Also, nit: In the comment both here and above, it wants to be "supports".
> + return 1
> + }
> + return 0
> +}
More generally: Rather than re-enumerating all relevant targets in both
of these helpers, we can't e.g. probe gas? I wonder what would happen if
some tc-*.h defined TC_OBJ_ATTR_v{1,2} dependent upon particular TE_*
settings. Afaict the enumerations here would then need to become yet
more complex.
> --- /dev/null
> +++ b/gas/testsuite/gas/gnu-attributes/oa-gnu-attribute-directive.d
> @@ -0,0 +1,4 @@
> +# name: GNU attributes v1/v2: no support for directive .gnu_attribute
> +# notarget: [supports_oa_v1] [supports_oa_v2]
> +# error: \A[^\n]+: Assembler messages:
> +# error: \n[^\n]+: Error: unknown pseudo-op: `\.gnu_attribute'\Z
> --- /dev/null
> +++ b/gas/testsuite/gas/gnu-attributes/oa-gnu-attribute-directive.s
> @@ -0,0 +1 @@
> + .gnu_attribute 0, 1
> --- /dev/null
> +++ b/gas/testsuite/gas/gnu-attributes/oa-gnu-subsection-directive.d
> @@ -0,0 +1,4 @@
> +# name: GNU attributes v2: no support for directive .gnu_subsection
> +# notarget: [supports_oa_v2]
> +# error: \A[^\n]+: Assembler messages:
> +# error: \n[^\n]+: Error: unknown pseudo-op: `\.gnu_subsection'\Z
> --- /dev/null
> +++ b/gas/testsuite/gas/gnu-attributes/oa-gnu-subsection-directive.s
> @@ -0,0 +1 @@
> + .gnu_subsection gnu_foo_1, optional, ULEB128
For all of the above I consider the file names misleading: These don't test
the directives, but they test that the directives are invalid / unrecognized.
> --- /dev/null
> +++ b/gas/testsuite/gas/gnu-attributes/oav2-failures-1.l
> @@ -0,0 +1,44 @@
> +.*: Assembler messages:
> +.*: Error: declaration of an attribute outside the scope of an attribute subsection
> +.*: Error: attribute 1 cannot be redefined
> +.*: Error: unexpected value -1, expected `unsigned integer' instead
> +.*: Error: could not parse attribute tag
> +.*: Error: unknown identifier 'Tag_Unknown' in this context
> +.*: Error: could not parse attribute tag
> +.*: Error: unknown identifier 'Tag_Unknown' in this context
> +.*: Error: could not parse attribute tag
> +.*: Error: unexpected `string' "plop", expected `unsigned integer' instead
> +.*: Error: could not parse attribute value
> +.*: Error: unexpected value -1, expected `unsigned integer' instead
> +.*: Error: could not parse attribute value
> +.*: Error: unexpected `string' "foo", expected `unsigned integer' instead
> +.*: Error: could not parse attribute value
> +.*: Error: unexpected integer 1, expected `string' instead
> +.*: Error: could not parse attribute value
> +.*: Error: attribute 4 cannot be redefined
> +.*: Error: comprehension and encoding of a subsection cannot be omitted on the first declaration
> +.*: Error: incompatible redeclaration of subsection vendor_1_subsection_3
> +.*: Info: previous declaration had properties: comprehension=required, encoding=NTBS
> +.*: Error: incompatible redeclaration of subsection vendor_1_subsection_3
> +.*: Info: previous declaration had properties: comprehension=required, encoding=NTBS
> +.*: Error: incompatible redeclaration of subsection vendor_1_subsection_3
> +.*: Info: previous declaration had properties: comprehension=required, encoding=NTBS
> +.*: Error: unknown identifier 'ntbs' in this context
> +.*: Error: unknown identifier 'uleb128' in this context
> +.*: Error: expression '.vendor' does not resolve to an integer literal
> +.*: Error: fell back to integer literal extraction from expression, but expected `identifier' instead
> +.*: Error: expected <subsection_name>, <comprehension>, <encoding>
> +.*: Error: unknown identifier 'uleb128' in this context
> +.*: Error: unknown identifier 'optial' in this context
> +.*: Error: unknown identifier 'ul128' in this context
> +.*: Error: invalid value 2, expected values for <comprehension> are 0 \(=`required'\) or 1 \(=`optional'\)
> +.*: Error: invalid value 2, expected values for <encoding> are 0 \(=`ULEB128'\) or 1 \(=`NTBS'\)
> +.*: Error: unexpected comma before parameter 2
> +.*: Error: junk at end of line, first unrecognized character is `,'
> +.*: Error: unexpected comma before parameter 1
> +.*: Error: missing comma after parameter 2
> +.*: Error: unexpected comma before parameter 2
> +.*: Error: junk at end of line, first unrecognized character is `,'
> +.*: Error: unexpected comma before parameter 1
> +.*: Error: junk at end of line, first unrecognized character is `1'
> +.*: Error: attribute 1 cannot be redefined
Repeating a question already raised on v10: Is the exact wording really relevant
in every one of the cases? My suggestion to split off some parts into info
diagnostics was in part to then possibly have the respective expectation perhaps
as short as
.*: Info: .*
i.e. merely demanding that there is some further explanatory info.
Another example would be
.*: Error: invalid value 2, expected values for <comprehension> are .*
Further many of the "junk at end of line" look to be secondary errors. Ideally
these would be avoided altogether (as a rule of thumb there should be just one
diagnostic per statement; see a respective comment I mad on an earlier patch),
but if that's not feasible for some reason, then their presence is entirely
irrelevant in this test, I would say.
> --- /dev/null
> +++ b/gas/testsuite/gas/gnu-attributes/oav2-interleaved-subsections.d
> @@ -0,0 +1,34 @@
> +# name: GNU attributes v2: correct context switching between interleaved subsections
> +# target: [supports_oa_v2]
> +# readelf: -A
> +
> +Subsections:
> + - Name: foo_1
> + Scope: private
> + Length: 20
> + Comprehension: optional
> + Encoding: ULEB128
> + Values:
> + Tag_unknown_1: 1 \(0x1\)
> + Tag_unknown_2: 0 \(0x0\)
> + Tag_unknown_3: 0 \(0x0\)
> + Tag_unknown_4: 0 \(0x0\)
> +
> + - Name: gnu_abi
> + Scope: public
> + Length: 18
> + Comprehension: required
> + Encoding: ULEB128
> + Values:
> + Tag_unknown_1: 1 \(0x1\)
> + Tag_unknown_2: 1 \(0x1\)
> +
> + - Name: gnu_feature_and_bits
> + Scope: public
> + Length: 33
> + Comprehension: optional
> + Encoding: ULEB128
> + Values:
> + Tag_unknown_0: 1 \(0x1\)
> + Tag_unknown_1: 0 \(0x0\)
> + Tag_unknown_2: 1 \(0x1\)
Similar remark here (applicable elsewhere as well): This looks to be a verbatim
copy of readelf output, just with backslashes added as needed. I don't think it
needs to be as tight for the purpose of the test. E.g. the secondary (hex)
printing of numbers could be matched by .* instead. Whether e.g. the precise
values for Length: are a required part of the test I can't tell. The exact way
blank padding is effected also doesn't look to be relevant for the test.
Jan
More information about the Binutils
mailing list