[RFC PATCH] gas .section directives with comdat inheritance

H.J. Lu hjl.tools@gmail.com
Wed Aug 11 21:06:00 GMT 2010


On Tue, Aug 10, 2010 at 11:31 PM, Roland McGrath <roland@redhat.com> wrote:
> This patch adds a new magic flag to .section directives.
> If ? appears among the "FLAGS" letters, then it means to
> imply any G flag and NAME[,comdat] from the current section
> to the new section.
>
> This scenario I'm trying to get at is using inline asm to emit annotation
> sections.  That is, C code will contain:
>
>        asm("0: someinstruction\n"
>            ".pushsection .annotations,\"\"\n"
>            ".long 0b\n"
>            ".popsection");
>
> This works fine in C and in lots of C++ code.  But when this appears inside
> C++ methods that are being compiled into comdat sections, it breaks down.
> We really need that to be doing:
>
>            .pushsection .annotations,"G",current_comdat_name,comdat
>
> for whatever "current_comdat_name" the compiler is compiling to.
> With this patch, it can do:
>
>        asm("0: someinstruction\n"
>            ".pushsection .annotations,\"?\"\n"
>            ".long 0b\n"
>            ".popsection");
>
> and this has the effect of either:
>            .pushsection .annotations,""
> or
>            .pushsection .annotations,"G",the_right_comdat_name,comdat
> as appropriate.
>
> There may be better ways to attack this on the compiler side.  But I
> haven't really thought of them.  OTOH, this gas change was really easy to
> get working.
>
>
> Thanks,
> Roland
>
>
> 2010-08-10  Roland McGrath  <roland@redhat.com>
>
>        * config/obj-elf.c (obj_elf_parse_section_letters): Take new
>        boolean result parameter CLONE; set it if '?' flag letter seen.
>        (obj_elf_section): Update caller.  Handle that flag by copying
>        the LINKONCE and GROUP_NAME state from NOW_SEG.
>        * doc/as.texinfo (Section): Document the ? flag.
>

You should include some testcases to show/make sure that
gas is doing the thing you intended.

H.J.



More information about the Binutils mailing list