Empty section flags
Fangrui Song
i@maskray.me
Mon Apr 13 21:32:53 GMT 2020
On 2020-04-04, H.J. Lu wrote:
>On Sat, Apr 4, 2020 at 9:38 AM Fangrui Song <i@maskray.me> wrote:
>>
>> On 2020-04-04, H.J. Lu wrote:
>> >On Tue, Mar 3, 2020 at 1:20 PM Fangrui Song <i@maskray.me> wrote:
>> >>
>> >> On Sun, Feb 9, 2020 at 9:21 PM Alan Modra <amodra@gmail.com> wrote:
>> >> >
>> >> > On Thu, Feb 06, 2020 at 05:25:33PM +0000, bd1976 llvm wrote:
>> >> > > Hi Alan, thanks for the input here. I wonder if it wouldn't be more
>> >> > > consistent to error in all cases - even in the case of different group
>> >> > > signatures. The only exception would need to be for the special section
>> >> > > names (.text, .debug_str, etc...) that the assembler has special knowledge
>> >> > > of (as you explained).
>> >> >
>> >> > Yes, let's see how that goes.
>> >> > https://sourceware.org/ml/binutils/2020-02/msg00129.html
>> >> >
>> >> > > I wonder why creating multiple sections with the
>> >> > > same name for section directives with different group signatures was
>> >> > > implemented - why not just require the use of a distinct section name for
>> >> > > these?
>> >> >
>> >> > I think plain ".text" for a group's text section is fine. Distict
>> >> > names would just be yet another thing to track for a group.
>> >> >
>> >> > > Or, now that GNU has the ",unique,N" assembly extension (
>> >> > > https://sourceware.org/ml/binutils/2020-02/msg00028.html) that could be
>> >> > > used if the section name is fixed - it would then be explicit in the source
>> >> > > code that another section with the same name will be created.
>> >> >
>> >> > Perhaps, but we aren't designing a new toolchain. Backwards
>> >> > compatibility can't be discarded without compelling reasons.
>> >> >
>> >> > --
>> >> > Alan Modra
>> >> > Australia Development Lab, IBM
>> >>
>> >> For empty flags, should there be an error as well?
>> >>
>> >> .section .foo,"ax",@progbits; .byte 1
>> >> .section .foo,"",@progbits; .byte 2 # no diagnostic
>> >> .section .foo,"a",@progbits; .byte 3 # Error: changed section
>> >> attributes for .foo
>> >>
>> >> Context: https://github.com/ClangBuiltLinux/linux/issues/913
>> >>
>> >> I lean toward an error for consistency, and I will try making the LLVM
>> >> MC side rule stick.
>> >
>> >[hjl@gnu-cfl-2 tmp]$ cat x.s
>> >.section .foo,"",@progbits; .byte 2
>> >[hjl@gnu-cfl-2 tmp]$ gcc -c x.s
>> >[hjl@gnu-cfl-2 tmp]$ readelf -SW x.o | grep foo
>> > [ 4] .foo PROGBITS 0000000000000000 000040
>> >000001 00 0 0 1
>> >[hjl@gnu-cfl-2 tmp]$
>> >
>> >Unless it is disallowed by gABI/psABI, assembler should allow it.
>> >Sometimes, I found a need to create odd object files, like zero-sized
>> >relocation section, for linker test. Assembler should have more
>> >flexibilities within gABI/psABI.
>> >
>> >--
>> >H.J.
>>
>> Declaring a section with empty flags is fine.
>> My question is about re-declaring with empty flags when the first declaration has other flags:
>>
>> .section .foo,"ax",@progbits; .byte 1
>> .section .foo,"",@progbits; .byte 2 # no diagnostic
>> .section .foo,"a",@progbits; .byte 3 # Error: changed section
>>
>> This is about the follow-up of
>> https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=33176d912add7680277ad5e18af0e6303d9a7af8
>
>[hjl@gnu-cfl-2 tmp]$ cat y.s
>.section .foo,"ax",@progbits
>.byte 1
>.section .foo
>.byte 2
>.section .foo,"",@progbits
>.byte 3
>.section .foo,"ax"
>.byte 3
>[hjl@gnu-cfl-2 tmp]$ gcc -c y.s
>[hjl@gnu-cfl-2 tmp]$ readelf -SW y.o | grep foo
> [ 4] .foo PROGBITS 0000000000000000 000040
>000004 00 AX 0 0 1
>[hjl@gnu-cfl-2 tmp]$
>
>If section flags or type is unspecified/empty, GNU assembler uses the
>previous one if it exists. I think this behavior is quite reasonable.
>
>--
>H.J.
When sh_flags is unspecified, I can accept that it will use the
previous one (ideally I hope it does not do this)
.section .foo
But when sh_flags is specified as an empty string, I find it quite
unintuitive to be different from a non-empty string
.section .foo,""
# different from .section .foo,"a" , which checks compatibility
More information about the Binutils
mailing list