From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id B4A8F395C077; Fri, 13 May 2022 14:15:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B4A8F395C077 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Do not double-read minimal symbols for PE COFF X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 169692ce6c0fa21c4648d2862cb2bb94012a1cd9 X-Git-Newrev: 28c5801a94ea5943213b2a304a00a3eb1f2ef622 Message-Id: <20220513141533.B4A8F395C077@sourceware.org> Date: Fri, 13 May 2022 14:15:33 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 May 2022 14:15:33 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D28c5801a94ea= 5943213b2a304a00a3eb1f2ef622 commit 28c5801a94ea5943213b2a304a00a3eb1f2ef622 Author: Tom Tromey Date: Fri Apr 22 11:37:52 2022 -0600 Do not double-read minimal symbols for PE COFF =20 This changes coffread.c to avoid re-reading minimal symbols when possible. This only works when there are no COFF symbols to be read, but at least for my mingw builds of gdb, this seems to be the case. =20 Tested using the AdaCore internal test suite on Windows. I also did some local builds to ensure that no warnings crept in. Diff: --- gdb/coffread.c | 132 ++++++++++++++++++++++++++++++++---------------------= ---- 1 file changed, 75 insertions(+), 57 deletions(-) diff --git a/gdb/coffread.c b/gdb/coffread.c index c5e977330be..75cf646c980 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -525,6 +525,80 @@ find_linenos (bfd *abfd, struct bfd_section *asect, vo= id *vpinfo) } =20 =20 +/* A helper function for coff_symfile_read that reads minimal + symbols. It may also read other forms of symbol as well. */ + +static void +coff_read_minsyms (file_ptr symtab_offset, unsigned int nsyms, + struct objfile *objfile) + +{ + /* If minimal symbols were already read, and if we know we aren't + going to read any other kind of symbol here, then we can just + return. */ + if (objfile->per_bfd->minsyms_read && pe_file && nsyms =3D=3D 0) + return; + + minimal_symbol_reader reader (objfile); + + if (pe_file && nsyms =3D=3D 0) + { + /* We've got no debugging symbols, but it's a portable + executable, so try to read the export table. */ + read_pe_exported_syms (reader, objfile); + } + else + { + /* Now that the executable file is positioned at symbol table, + process it and define symbols accordingly. */ + coff_symtab_read (reader, symtab_offset, nsyms, objfile); + } + + /* Install any minimal symbols that have been collected as the + current minimal symbols for this objfile. */ + + reader.install (); + + if (pe_file) + { + for (minimal_symbol *msym : objfile->msymbols ()) + { + const char *name =3D msym->linkage_name (); + + /* If the minimal symbols whose name are prefixed by "__imp_" + or "_imp_", get rid of the prefix, and search the minimal + symbol in OBJFILE. Note that 'maintenance print msymbols' + shows that type of these "_imp_XXXX" symbols is mst_data. */ + if (msym->type () =3D=3D mst_data) + { + const char *name1 =3D NULL; + + if (startswith (name, "_imp_")) + name1 =3D name + 5; + else if (startswith (name, "__imp_")) + name1 =3D name + 6; + if (name1 !=3D NULL) + { + int lead =3D bfd_get_symbol_leading_char (objfile->obfd); + struct bound_minimal_symbol found; + + if (lead !=3D '\0' && *name1 =3D=3D lead) + name1 +=3D 1; + + found =3D lookup_minimal_symbol (name1, NULL, objfile); + + /* If found, there are symbols named "_imp_foo" and "foo" + respectively in OBJFILE. Set the type of symbol "foo" + as 'mst_solib_trampoline'. */ + if (found.minsym !=3D NULL + && found.minsym->type () =3D=3D mst_text) + found.minsym->set_type (mst_solib_trampoline); + } + } + } + } +} + /* The BFD for this file -- only good while we're actively reading symbols into a psymtab or a symtab. */ =20 @@ -625,56 +699,7 @@ coff_symfile_read (struct objfile *objfile, symfile_ad= d_flags symfile_flags) if (val < 0) error (_("\"%s\": can't get string table"), filename); =20 - minimal_symbol_reader reader (objfile); - - /* Now that the executable file is positioned at symbol table, - process it and define symbols accordingly. */ - - coff_symtab_read (reader, (long) symtab_offset, num_symbols, objfile); - - /* Install any minimal symbols that have been collected as the - current minimal symbols for this objfile. */ - - reader.install (); - - if (pe_file) - { - for (minimal_symbol *msym : objfile->msymbols ()) - { - const char *name =3D msym->linkage_name (); - - /* If the minimal symbols whose name are prefixed by "__imp_" - or "_imp_", get rid of the prefix, and search the minimal - symbol in OBJFILE. Note that 'maintenance print msymbols' - shows that type of these "_imp_XXXX" symbols is mst_data. */ - if (msym->type () =3D=3D mst_data) - { - const char *name1 =3D NULL; - - if (startswith (name, "_imp_")) - name1 =3D name + 5; - else if (startswith (name, "__imp_")) - name1 =3D name + 6; - if (name1 !=3D NULL) - { - int lead =3D bfd_get_symbol_leading_char (objfile->obfd); - struct bound_minimal_symbol found; - - if (lead !=3D '\0' && *name1 =3D=3D lead) - name1 +=3D 1; - - found =3D lookup_minimal_symbol (name1, NULL, objfile); - - /* If found, there are symbols named "_imp_foo" and "foo" - respectively in OBJFILE. Set the type of symbol "foo" - as 'mst_solib_trampoline'. */ - if (found.minsym !=3D NULL - && found.minsym->type () =3D=3D mst_text) - found.minsym->set_type (mst_solib_trampoline); - } - } - } - } + coff_read_minsyms (symtab_offset, num_symbols, objfile); =20 if (!(objfile->flags & OBJF_READNEVER)) bfd_map_over_sections (abfd, coff_locate_sections, (void *) info); @@ -1160,13 +1185,6 @@ coff_symtab_read (minimal_symbol_reader &reader, } } =20 - if ((nsyms =3D=3D 0) && (pe_file)) - { - /* We've got no debugging symbols, but it's a portable - executable, so try to read the export table. */ - read_pe_exported_syms (reader, objfile); - } - if (get_last_source_file ()) coff_end_compunit_symtab (objfile);