Bug 25333 - GAS is slow processing units compiled with -fdebug-types-sections containing many types
Summary: GAS is slow processing units compiled with -fdebug-types-sections containing ...
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: 2.43
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-01-01 22:52 UTC by Jan Hubicka
Modified: 2024-02-24 04:31 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
Project(s) to access:
ssh public key:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Hubicka 2020-01-01 22:52:25 UTC
jan@skylake:~> cat t.c
#define def(name) struct name {int name;} name;
#define def2(name) def(name##a) def(name##b)
#define def3(name) def2(name##a) def2(name##b)
#define def4(name) def3(name##a) def3(name##b)
#define def5(name) def4(name##a) def4(name##b)
#define def6(name) def5(name##a) def5(name##b)
#define def7(name) def6(name##a) def6(name##b)
#define def8(name) def7(name##a) def7(name##b)
#define def9(name) def8(name##a) def8(name##b)
#define def10(name) def9(name##a) def9(name##b)
#define def11(name) def10(name##a) def10(name##b)
#define def12(name) def11(name##a) def11(name##b)
#define def13(name) def12(name##a) def12(name##b)
#define def14(name) def13(name##a) def13(name##b)
#define def15(name) def14(name##a) def14(name##b)
#define def16(name) def15(name##a) def15(name##b)
#define def17(name) def16(name##a) def16(name##b)
#define def18(name) def17(name##a) def17(name##b)
def18(a);
main()
{
}
jan@skylake:~> gcc t.c -fdebug-types-section  -O2 -g 

takes really long time mostly in
  45.79%  libc-2.30.so                   [.] __strcmp_avx2
   8.66%  as                             [.] 0x000000000000d2d9
   6.30%  libbfd-2.33.1.20191023-2.so    [.] bfd_get_section_by_name_if
Comment 1 Alan Modra 2020-01-02 09:36:39 UTC
Huh, 131072 .debug_types sections with different group signatures.  Yes, that will take a while to process in obj_elf_change_section.  We can look up a section by name fairly quickly via the section hash table to see whether assembly should append to an existing section, but there is no quick lookup of sections matching a group signature.
Comment 2 hubicka 2020-01-02 09:43:12 UTC
The testcase was based on real world one - in C++ it is quite easy to
create many types. So it would be nice to do something about it.
Comment 3 Sourceware Commits 2024-02-24 04:29:43 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=bc45bfd25984a709dec4236daf412c58a127633a

commit bc45bfd25984a709dec4236daf412c58a127633a
Author: Alan Modra <amodra@gmail.com>
Date:   Sat Feb 24 11:30:02 2024 +1030

    xtensa: move xtensa_make_property_section from bfd to gas
    
    This function is only used by gas, so move it there.  Necessary for
    gas to keep track of group sections as they are created.
    
            PR 25333
    bfd/
            * elf32-xtensa.c (xtensa_make_property_section): Delete.
            (xtensa_property_section_name): Make public.
    include/
            * elf/xtensa.h (xtensa_make_property_section): Delete.
            (xtensa_property_section_name): Declare
    gas/
            * config/tc-xtensa.c (xtensa_make_property_section): New,
            moved from elf32-xtensa.c.
Comment 4 Sourceware Commits 2024-02-24 04:29:48 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=086c8f406d82ce171d5867eed93f1308e07252c5

commit 086c8f406d82ce171d5867eed93f1308e07252c5
Author: Alan Modra <amodra@gmail.com>
Date:   Sat Feb 24 11:38:57 2024 +1030

    PR25333, GAS is slow processing -fdebug-types-sections
    
    gas needs to build lists of sections for each group.  This arranges to
    build the lists earlier, so they can be used when looking for sections
    that belong to a group.  Using the section hash table to find sections
    by name, then by group isn't efficient when there are numerous groups
    with the same section names.  Using a hash table to quickly find a
    group, then searching by section name on a list for the group results
    in a 100-fold speed improvement assembling the testcase in this PR.
    
    To reduce the number of times we traverse the section list, the patch
    also moves some processing done in elf_adjust_symtab for linked-to
    section, to elf_frob_file.  This requires a testsuite change because
    processing will stop before elf_frob_file if there is a parse error in
    section21.s, ie. you'll only get the "junk at end of line" error, not
    the "undefined linked-to symbol" errors.
    
            PR 25333
            * config/obj-elf.c (struct group_list, groups): Move earlier.
            (match_section): New function, extracted from..
            (get_section_by_match): ..here.
            (free_section_idx): Move earlier.
            (group_section_find, group_section_insert): New functions.
            (change_section): Use the above.
            (elf_set_group_name): New function.
            (obj_elf_attach_to_group): Use elf_set_group_name.
            (set_additional_section_info): Handle linked_to_symbol_name and
            stabs code, extracted from..
            (adjust_stab_sections): ..here,..
            (build_additional_section_info): ..and here.
            (elf_adjust_symtab): Don't call build_additional_section_info.
            (elf_frob_file): Adjust.
            * config/obj-elf.h (elf_set_group_name): Declare.
            * config/tc-xtensa.c (cache_literal_section): Use elf_set_group_name.
            (xtensa_make_property_section): Likewise.
            * testsuite/gas/elf/attach-1.d: Stricter group section matching,
            and changed group section ordering.
            * testsuite/gas/elf/attach-2.d: Stricter group section matching.
            * testsuite/gas/elf/attach-2.s: Provide section bar type.
            * testsuite/gas/elf/elf.exp: Run attach-2.
            * testsuite/gas/elf/section21.l: Update.
            * testsuite/gas/elf/section21.s: Don't check for a parse error.
Comment 5 Alan Modra 2024-02-24 04:31:19 UTC
Fixed.