From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9964 invoked by alias); 7 Jan 2014 11:15:15 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 9954 invoked by uid 89); 7 Jan 2014 11:15:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.2 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,MSGID_MULTIPLE_AT autolearn=no version=3.3.2 X-HELO: mailhost.u-strasbg.fr Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.222.214) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 07 Jan 2014 11:15:12 +0000 Received: from mailhost.u-strasbg.fr (localhost [127.0.0.1]) by antispam (Postfix) with ESMTP id 4BA4A1A0462; Tue, 7 Jan 2014 12:15:09 +0100 (CET) Received: from mailhost.u-strasbg.fr (localhost [127.0.0.1]) by antivirus (Postfix) with ESMTP id 3C9F31A09DD; Tue, 7 Jan 2014 12:15:09 +0100 (CET) Received: from md15.u-strasbg.fr (md15.u-strasbg.fr [130.79.200.204]) by mr4.u-strasbg.fr (Postfix) with ESMTP id EAD1D1A0462; Tue, 7 Jan 2014 12:15:05 +0100 (CET) Received: from ms17.u-strasbg.fr (ms17.u-strasbg.fr [130.79.204.117]) by md15.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id s07BF5cG017395 ; Tue, 7 Jan 2014 12:15:05 +0100 (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from E6510Muller (gw-ics.u-strasbg.fr [130.79.210.225]) (Authenticated sender: mullerp) by ms17.u-strasbg.fr (Postfix) with ESMTPSA id B26681FD95; Tue, 7 Jan 2014 12:15:02 +0100 (CET) From: "Pierre Muller" To: "'Pedro Alves'" Cc: "'Joel Brobecker'" , References: <004801cef65e$cb82d1b0$62887510$@muller@ics-cnrs.unistra.fr> <20131211170204.GD3227@adacore.com> <52ab7ec0.c8da420a.12c6.ffffb3f4SMTPIN_ADDED_BROKEN@mx.google.com> <52B48A28.2000402@redhat.com> <52b76e14.8886420a.29e6.ffffddb2SMTPIN_ADDED_BROKEN@mx.google.com> <52CAF71D.3050008@redhat.com> In-Reply-To: <52CAF71D.3050008@redhat.com> Subject: [RFA-v3] Fix PR 16201: internal error on a cygwin program linked against a DLL with no .data section Date: Tue, 07 Jan 2014 11:15:00 -0000 Message-ID: <002101cf0b99$b630d870$22928950$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-SW-Source: 2014-01/txt/msg00134.txt.bz2 > -----Message d'origine----- > De=A0: gdb-patches-owner@sourceware.org [mailto:gdb-patches- > owner@sourceware.org] De la part de Pedro Alves > Envoy=E9=A0: lundi 6 janvier 2014 19:34 > =C0=A0: Pierre Muller > Cc=A0: 'Joel Brobecker'; gdb-patches@sourceware.org > Objet=A0: Re: [RFA-v2] Fix PR 16201: internal error on a cygwin program > linked against a DLL with no .data section >=20 > Hi Pierre, >=20 > Sorry for the slow reply. Been away on vacation. >=20 > On 12/22/2013 10:55 PM, Pierre Muller wrote: > > @@ -455,17 +458,34 @@ read_pe_exported_syms (struct objfile *objfile) > > unsigned long characteristics =3D pe_get32 (dll, secptr1 + 36); > > char sec_name[SCNNMLEN + 1]; > > int sectix; > > + unsigned int bfd_section_index; > > + asection *section; > > > > bfd_seek (dll, (file_ptr) secptr1 + 0, SEEK_SET); > > bfd_bread (sec_name, (bfd_size_type) SCNNMLEN, dll); > > sec_name[SCNNMLEN] =3D '\0'; > > > > sectix =3D read_pe_section_index (sec_name); > > + section =3D bfd_get_section_by_name (dll, sec_name); >=20 > Can't coff have sections with duplicate names?=20 I did not find anything in the PE COFF description that explicitly said that each section should have a unique name=20 but I always assumed that the assembler/linker would=20 always group all sections with the same name. Is there some object merge utility that could=20 group objects without merging? > If so, > then it'd be better to match the section some other way, > I guess by address? I would not know how to do this... =20 > > + if (section) > > + bfd_section_index =3D section->index; > > + else > > + bfd_section_index =3D -1; > > > > if (sectix !=3D PE_SECTION_INDEX_INVALID) > > { > > section_data[sectix].rva_start =3D vaddr; > > section_data[sectix].rva_end =3D vaddr + vsize; > > + /* For .text, .data and .bss section > > + set corresponding sect_index_XXX, > > + even if it was already set before. */ > > + if (sectix =3D=3D PE_SECTION_INDEX_TEXT) > > + objfile->sect_index_text =3D sectix; > > + if (sectix =3D=3D PE_SECTION_INDEX_DATA) > > + objfile->sect_index_data =3D sectix; > > + if (sectix =3D=3D PE_SECTION_INDEX_BSS) > > + objfile->sect_index_bss =3D sectix; > > + section_data[sectix].index =3D bfd_section_index; >=20 > Do you still need this part? This is still an improvement as it sets these sect_index_XXX fields that might be needed elsewhere in the code. Remember that the bug comes from the fact that those fields were not set. However, I agree that the exact source of the bug should be removed even without this part. I would prefer to leave it inside this patch, as it still reduces a potential problem elsewhere. Here is an update, which also handles the forwarded symbol by retrieving the section index of the minimal symbol. =20=20 Pierre Muller 2014-01-07 Pierre Muller Fix PR16201. * coff-pe-read.c (struct read_pe_section_data): Add index field. (add_pe_exported_sym): Use SECTION_DATA->INDEX for call to prim_record_mininal_symbol_and_info. (add_pe_forwarded_sym): Use known section number of forwarded symbol in call to prim_record_minimal_symbol_and_info. (read_pe_exported_syms): Set index field of section_data. diff --git a/gdb/coff-pe-read.c b/gdb/coff-pe-read.c index 749c109..01d6c69 100644 --- a/gdb/coff-pe-read.c +++ b/gdb/coff-pe-read.c @@ -53,6 +53,7 @@ struct read_pe_section_data unsigned long rva_end; /* End offset within the pe. */ enum minimal_symbol_type ms_type; /* Type to assign symbols in section. */ + unsigned int index; /* Section number. */ char *section_name; /* Recorded section name. */ }; =20 @@ -175,11 +176,13 @@ add_pe_exported_sym (const char *sym_name, " for entry \"%s\" in dll \"%s\"\n"), section_data->section_name, sym_name, dll_name); =20 - prim_record_minimal_symbol (qualified_name, vma, - section_data->ms_type, objfile); + prim_record_minimal_symbol_and_info (qualified_name, vma, + section_data->ms_type, + section_data->index, objfile); =20 /* Enter the plain name as well, which might not be unique. */ - prim_record_minimal_symbol (bare_name, vma, section_data->ms_type, objfile); + prim_record_minimal_symbol_and_info (bare_name, vma, section_data->ms_type, + section_data->index, objfile); if (debug_coff_pe_read > 1) fprintf_unfiltered (gdb_stdlog, _("Adding exported symbol \"%s\"" " in dll \"%s\"\n"), sym_name, dll_name); @@ -209,6 +212,7 @@ add_pe_forwarded_sym (const char *sym_name, const char *forward_dll_name, int forward_func_name_len =3D strlen (forward_func_name); int forward_len =3D forward_dll_name_len + forward_func_name_len + 2; char *forward_qualified_name =3D alloca (forward_len); + short section; =20 xsnprintf (forward_qualified_name, forward_len, "%s!%s", forward_dll_name, forward_func_name); @@ -242,6 +246,7 @@ add_pe_forwarded_sym (const char *sym_name, const char *forward_dll_name, =20 vma =3D SYMBOL_VALUE_ADDRESS (msymbol.minsym); msymtype =3D MSYMBOL_TYPE (msymbol.minsym); + section =3D SYMBOL_SECTION (msymbol.minsym); =20 /* Generate a (hopefully unique) qualified name using the first part of the dll name, e.g. KERNEL32!AddAtomA. This matches the style @@ -254,10 +259,12 @@ add_pe_forwarded_sym (const char *sym_name, const char *forward_dll_name, =20 qualified_name =3D xstrprintf ("%s!%s", dll_name, bare_name); =20 - prim_record_minimal_symbol (qualified_name, vma, msymtype, objfile); + prim_record_minimal_symbol_and_info (qualified_name, vma, msymtype, + section, objfile); =20 /* Enter the plain name as well, which might not be unique. */ - prim_record_minimal_symbol (bare_name, vma, msymtype, objfile); + prim_record_minimal_symbol_and_info (bare_name, vma, msymtype, + section, objfile); xfree (qualified_name); xfree (bare_name); =20 @@ -455,17 +462,34 @@ read_pe_exported_syms (struct objfile *objfile) unsigned long characteristics =3D pe_get32 (dll, secptr1 + 36); char sec_name[SCNNMLEN + 1]; int sectix; + unsigned int bfd_section_index; + asection *section; =20 bfd_seek (dll, (file_ptr) secptr1 + 0, SEEK_SET); bfd_bread (sec_name, (bfd_size_type) SCNNMLEN, dll); sec_name[SCNNMLEN] =3D '\0'; =20 sectix =3D read_pe_section_index (sec_name); + section =3D bfd_get_section_by_name (dll, sec_name); + if (section) + bfd_section_index =3D section->index; + else + bfd_section_index =3D -1; =20 if (sectix !=3D PE_SECTION_INDEX_INVALID) { section_data[sectix].rva_start =3D vaddr; section_data[sectix].rva_end =3D vaddr + vsize; + /* For .text, .data and .bss section + set corresponding sect_index_XXX, + even if it was already set before. */ + if (sectix =3D=3D PE_SECTION_INDEX_TEXT) + objfile->sect_index_text =3D sectix; + if (sectix =3D=3D PE_SECTION_INDEX_DATA) + objfile->sect_index_data =3D sectix; + if (sectix =3D=3D PE_SECTION_INDEX_BSS) + objfile->sect_index_bss =3D sectix; + section_data[sectix].index =3D bfd_section_index; } else { @@ -479,6 +503,7 @@ read_pe_exported_syms (struct objfile *objfile) section_data[otherix].rva_start =3D vaddr; section_data[otherix].rva_end =3D vaddr + vsize; section_data[otherix].vma_offset =3D 0; + section_data[otherix].index =3D bfd_section_index; if (characteristics & IMAGE_SCN_CNT_CODE) section_data[otherix].ms_type =3D mst_text; else if (characteristics & IMAGE_SCN_CNT_INITIALIZED_DATA)