gas: Document @ and % as interchangeable for type argument in .section

Message ID 20260516003806.456403-1-hawkinsw@obs.cr
State New
Headers
Series gas: Document @ and % as interchangeable for type argument in .section |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Will Hawkins May 16, 2026, 12:38 a.m. UTC
  In the .section Assembler Directive for the ELF format, both the % and
the @ can be used when writing the type argument. Clarify the documentation.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
---
 gas/doc/as.texi | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
  

Comments

Jan Beulich May 17, 2026, 6:50 a.m. UTC | #1
On 16.05.2026 02:38, Will Hawkins wrote:
> In the .section Assembler Directive for the ELF format, both the % and
> the @ can be used when writing the type argument.

That's not exactly true (the two aren't fully interchangeable), and hence ...

> Clarify the documentation.
> 
> Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
> ---
>  gas/doc/as.texi | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/gas/doc/as.texi b/gas/doc/as.texi
> index 3e1d2d0e254..201d9c26b7d 100644
> --- a/gas/doc/as.texi
> +++ b/gas/doc/as.texi
> @@ -7118,13 +7118,12 @@ a numeric value to be set as the ELF section header's type field.
>  some targets extend this list with their own types
>  @end table
>  
> +Note - the @code{%} character may be used instead of the @code{@@} character
> +when writing the @var{type} argument constant.
> +
>  Many targets only support the first three section types.  The type may be
>  enclosed in double quotes if necessary.
>  
> -Note on targets where the @code{@@} character is the start of a comment (eg
> -ARM) then another character is used instead.  For example the ARM port uses the
> -@code{%} character.

... removing this paragraph loses information. I'd suggest adding something like
"For example the Arm port uses @code{@@} as comment character." to the new paragraph
you add. (MMIX is the other way around, using % as comment char.)

Jan
  
Will Hawkins May 17, 2026, 11:27 a.m. UTC | #2
On Sunday, May 17, 2026, Jan Beulich <jbeulich@suse.com> wrote:

> On 16.05.2026 02:38, Will Hawkins wrote:
> > In the .section Assembler Directive for the ELF format, both the % and
> > the @ can be used when writing the type argument.
>
> That's not exactly true (the two aren't fully interchangeable), and hence
> ...



In obj-elf.c, I saw

else if (c == '@' || c == '%')

which I must have misinterpreted?



>
> > Clarify the documentation.
> >
> > Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
> > ---
> >  gas/doc/as.texi | 7 +++----
> >  1 file changed, 3 insertions(+), 4 deletions(-)
> >
> > diff --git a/gas/doc/as.texi b/gas/doc/as.texi
> > index 3e1d2d0e254..201d9c26b7d 100644
> > --- a/gas/doc/as.texi
> > +++ b/gas/doc/as.texi
> > @@ -7118,13 +7118,12 @@ a numeric value to be set as the ELF section
> header's type field.
> >  some targets extend this list with their own types
> >  @end table
> >
> > +Note - the @code{%} character may be used instead of the @code{@@}
> character
> > +when writing the @var{type} argument constant.
> > +
> >  Many targets only support the first three section types.  The type may
> be
> >  enclosed in double quotes if necessary.
> >
> > -Note on targets where the @code{@@} character is the start of a
> comment (eg
> > -ARM) then another character is used instead.  For example the ARM port
> uses the
> > -@code{%} character.
>
> ... removing this paragraph loses information. I'd suggest adding
> something like
> "For example the Arm port uses @code{@@} as comment character." to the
> new paragraph
> you add. (MMIX is the other way around, using % as comment char.)
>
> Jan
>
  
Will Hawkins May 17, 2026, 11:35 a.m. UTC | #3
On Sunday, May 17, 2026, Will Hawkins <hawkinsw@obs.cr> wrote:

>
>
> On Sunday, May 17, 2026, Jan Beulich <jbeulich@suse.com> wrote:
>
>> On 16.05.2026 02:38, Will Hawkins wrote:
>> > In the .section Assembler Directive for the ELF format, both the % and
>> > the @ can be used when writing the type argument.
>>
>> That's not exactly true (the two aren't fully interchangeable), and hence
>> ...
>
>
>
> In obj-elf.c, I saw
>
> else if (c == '@' || c == '%')
>
> which I must have misinterpreted?
>


I guess that they are only treated equivalently in code on platforms where
the @ and % do not have implications for the code in earlier processing
before reaching obj_elf_section.

>
>
>
>>
>> > Clarify the documentation.
>> >
>> > Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
>> > ---
>> >  gas/doc/as.texi | 7 +++----
>> >  1 file changed, 3 insertions(+), 4 deletions(-)
>> >
>> > diff --git a/gas/doc/as.texi b/gas/doc/as.texi
>> > index 3e1d2d0e254..201d9c26b7d 100644
>> > --- a/gas/doc/as.texi
>> > +++ b/gas/doc/as.texi
>> > @@ -7118,13 +7118,12 @@ a numeric value to be set as the ELF section
>> header's type field.
>> >  some targets extend this list with their own types
>> >  @end table
>> >
>> > +Note - the @code{%} character may be used instead of the @code{@@}
>> character
>> > +when writing the @var{type} argument constant.
>> > +
>> >  Many targets only support the first three section types.  The type may
>> be
>> >  enclosed in double quotes if necessary.
>> >
>> > -Note on targets where the @code{@@} character is the start of a
>> comment (eg
>> > -ARM) then another character is used instead.  For example the ARM port
>> uses the
>> > -@code{%} character.
>>
>> ... removing this paragraph loses information. I'd suggest adding
>> something like
>> "For example the Arm port uses @code{@@} as comment character." to the
>> new paragraph
>> you add. (MMIX is the other way around, using % as comment char.)
>>
>> Jan
>>
>
  
Jan Beulich May 18, 2026, 5:57 a.m. UTC | #4
On 17.05.2026 13:35, Will Hawkins wrote:
> On Sunday, May 17, 2026, Will Hawkins <hawkinsw@obs.cr> wrote:
>> On Sunday, May 17, 2026, Jan Beulich <jbeulich@suse.com> wrote:
>>> On 16.05.2026 02:38, Will Hawkins wrote:
>>>> In the .section Assembler Directive for the ELF format, both the % and
>>>> the @ can be used when writing the type argument.
>>>
>>> That's not exactly true (the two aren't fully interchangeable), and hence
>>> ...
>>
>>
>>
>> In obj-elf.c, I saw
>>
>> else if (c == '@' || c == '%')
>>
>> which I must have misinterpreted?
> 
> I guess that they are only treated equivalently in code on platforms where
> the @ and % do not have implications for the code in earlier processing
> before reaching obj_elf_section.

Correct, comments are being removed much earlier. (If they were fully
equivalent, in that testcase of yours you also wouldn't have had to
switch from @ to %.)

Jan
  
Will Hawkins May 18, 2026, 1 p.m. UTC | #5
On Mon, May 18, 2026 at 1:57 AM Jan Beulich <jbeulich@suse.com> wrote:
>
> On 17.05.2026 13:35, Will Hawkins wrote:
> > On Sunday, May 17, 2026, Will Hawkins <hawkinsw@obs.cr> wrote:
> >> On Sunday, May 17, 2026, Jan Beulich <jbeulich@suse.com> wrote:
> >>> On 16.05.2026 02:38, Will Hawkins wrote:
> >>>> In the .section Assembler Directive for the ELF format, both the % and
> >>>> the @ can be used when writing the type argument.
> >>>
> >>> That's not exactly true (the two aren't fully interchangeable), and hence
> >>> ...
> >>
> >>
> >>
> >> In obj-elf.c, I saw
> >>
> >> else if (c == '@' || c == '%')
> >>
> >> which I must have misinterpreted?
> >
> > I guess that they are only treated equivalently in code on platforms where
> > the @ and % do not have implications for the code in earlier processing
> > before reaching obj_elf_section.
>
> Correct, comments are being removed much earlier. (If they were fully

I am glad that my reading of the code was not wildly inaccurate: _If_
there were no preprocessor implications for those characters, then
they would be equivalent.

> equivalent, in that testcase of yours you also wouldn't have had to
> switch from @ to %.)

Yes, I agree.

Before I propose an alternate, I figured it might be worth describing
why I wanted to make the change in the first place:

My local system is an x86-64. When I started developing a test case
for objdump and I was running the testsuite, the test in objdump.exp
based on the code in dw5-op.S passed. I could read the documentation
and see that @progbits should be the syntax.

I interpreted the existing note to imply mutually exclusive options
for @ vs %. And yet the test was passing. I used as to compile it --
just to be sure. Once I dug into the code and saw the aforementioned
if statement, I realized _why_ the test author used %: because % is
not a comment indicator on x86-64, using the % means that one version
of the test code works for both x86-64 and ARM platforms.

I proposed the change so that others would not have to search as much
as I did. With that as background, would you be amenable to rewriting

Note on targets where the @ character is the start of a comment (eg
ARM) then another character is used instead. For example the ARM port
uses the % character.

to

Note - certain targets treat @ as the start of a comment (e.g., ARM).
On such platforms, % is used instead. On platforms where neither @ nor
% indicate the start of a comment, @ and % may be used
interchangeably.

I hope that my (albeit modest) efforts at helping "future me" by
updating the docs are helpful. If they are not, please tell me!

Will

>
> Jan
  
Jan Beulich May 18, 2026, 1:17 p.m. UTC | #6
On 18.05.2026 15:00, Will Hawkins wrote:
> On Mon, May 18, 2026 at 1:57 AM Jan Beulich <jbeulich@suse.com> wrote:
>> On 17.05.2026 13:35, Will Hawkins wrote:
>>> On Sunday, May 17, 2026, Will Hawkins <hawkinsw@obs.cr> wrote:
>>>> On Sunday, May 17, 2026, Jan Beulich <jbeulich@suse.com> wrote:
>>>>> On 16.05.2026 02:38, Will Hawkins wrote:
>>>>>> In the .section Assembler Directive for the ELF format, both the % and
>>>>>> the @ can be used when writing the type argument.
>>>>>
>>>>> That's not exactly true (the two aren't fully interchangeable), and hence
>>>>> ...
>>>>
>>>>
>>>>
>>>> In obj-elf.c, I saw
>>>>
>>>> else if (c == '@' || c == '%')
>>>>
>>>> which I must have misinterpreted?
>>>
>>> I guess that they are only treated equivalently in code on platforms where
>>> the @ and % do not have implications for the code in earlier processing
>>> before reaching obj_elf_section.
>>
>> Correct, comments are being removed much earlier. (If they were fully
> 
> I am glad that my reading of the code was not wildly inaccurate: _If_
> there were no preprocessor implications for those characters, then
> they would be equivalent.
> 
>> equivalent, in that testcase of yours you also wouldn't have had to
>> switch from @ to %.)
> 
> Yes, I agree.
> 
> Before I propose an alternate, I figured it might be worth describing
> why I wanted to make the change in the first place:
> 
> My local system is an x86-64. When I started developing a test case
> for objdump and I was running the testsuite, the test in objdump.exp
> based on the code in dw5-op.S passed. I could read the documentation
> and see that @progbits should be the syntax.
> 
> I interpreted the existing note to imply mutually exclusive options
> for @ vs %. And yet the test was passing. I used as to compile it --
> just to be sure. Once I dug into the code and saw the aforementioned
> if statement, I realized _why_ the test author used %: because % is
> not a comment indicator on x86-64, using the % means that one version
> of the test code works for both x86-64 and ARM platforms.
> 
> I proposed the change so that others would not have to search as much
> as I did. With that as background, would you be amenable to rewriting
> 
> Note on targets where the @ character is the start of a comment (eg
> ARM) then another character is used instead. For example the ARM port
> uses the % character.
> 
> to
> 
> Note - certain targets treat @ as the start of a comment (e.g., ARM).
> On such platforms, % is used instead. On platforms where neither @ nor
> % indicate the start of a comment, @ and % may be used
> interchangeably.

This reads okay to me.

Jan
  
Will Hawkins May 18, 2026, 1:20 p.m. UTC | #7
On Mon, May 18, 2026 at 9:17 AM Jan Beulich <jbeulich@suse.com> wrote:
>
> On 18.05.2026 15:00, Will Hawkins wrote:
> > On Mon, May 18, 2026 at 1:57 AM Jan Beulich <jbeulich@suse.com> wrote:
> >> On 17.05.2026 13:35, Will Hawkins wrote:
> >>> On Sunday, May 17, 2026, Will Hawkins <hawkinsw@obs.cr> wrote:
> >>>> On Sunday, May 17, 2026, Jan Beulich <jbeulich@suse.com> wrote:
> >>>>> On 16.05.2026 02:38, Will Hawkins wrote:
> >>>>>> In the .section Assembler Directive for the ELF format, both the % and
> >>>>>> the @ can be used when writing the type argument.
> >>>>>
> >>>>> That's not exactly true (the two aren't fully interchangeable), and hence
> >>>>> ...
> >>>>
> >>>>
> >>>>
> >>>> In obj-elf.c, I saw
> >>>>
> >>>> else if (c == '@' || c == '%')
> >>>>
> >>>> which I must have misinterpreted?
> >>>
> >>> I guess that they are only treated equivalently in code on platforms where
> >>> the @ and % do not have implications for the code in earlier processing
> >>> before reaching obj_elf_section.
> >>
> >> Correct, comments are being removed much earlier. (If they were fully
> >
> > I am glad that my reading of the code was not wildly inaccurate: _If_
> > there were no preprocessor implications for those characters, then
> > they would be equivalent.
> >
> >> equivalent, in that testcase of yours you also wouldn't have had to
> >> switch from @ to %.)
> >
> > Yes, I agree.
> >
> > Before I propose an alternate, I figured it might be worth describing
> > why I wanted to make the change in the first place:
> >
> > My local system is an x86-64. When I started developing a test case
> > for objdump and I was running the testsuite, the test in objdump.exp
> > based on the code in dw5-op.S passed. I could read the documentation
> > and see that @progbits should be the syntax.
> >
> > I interpreted the existing note to imply mutually exclusive options
> > for @ vs %. And yet the test was passing. I used as to compile it --
> > just to be sure. Once I dug into the code and saw the aforementioned
> > if statement, I realized _why_ the test author used %: because % is
> > not a comment indicator on x86-64, using the % means that one version
> > of the test code works for both x86-64 and ARM platforms.
> >
> > I proposed the change so that others would not have to search as much
> > as I did. With that as background, would you be amenable to rewriting
> >
> > Note on targets where the @ character is the start of a comment (eg
> > ARM) then another character is used instead. For example the ARM port
> > uses the % character.
> >
> > to
> >
> > Note - certain targets treat @ as the start of a comment (e.g., ARM).
> > On such platforms, % is used instead. On platforms where neither @ nor
> > % indicate the start of a comment, @ and % may be used
> > interchangeably.
>
> This reads okay to me.

Thank you! I will send a v2!
Will


>
> Jan
  

Patch

diff --git a/gas/doc/as.texi b/gas/doc/as.texi
index 3e1d2d0e254..201d9c26b7d 100644
--- a/gas/doc/as.texi
+++ b/gas/doc/as.texi
@@ -7118,13 +7118,12 @@  a numeric value to be set as the ELF section header's type field.
 some targets extend this list with their own types
 @end table
 
+Note - the @code{%} character may be used instead of the @code{@@} character
+when writing the @var{type} argument constant.
+
 Many targets only support the first three section types.  The type may be
 enclosed in double quotes if necessary.
 
-Note on targets where the @code{@@} character is the start of a comment (eg
-ARM) then another character is used instead.  For example the ARM port uses the
-@code{%} character.
-
 Note - some sections, eg @code{.text} and @code{.data} are considered to be
 special and have fixed types.  Any attempt to declare them with a different
 type will generate an error from the assembler.