[PATCH, cygwin] Internal error when loading dlls without .data section.
Pedro Alves
pedro_alves@portugalmail.pt
Thu Dec 21 21:54:00 GMT 2006
Hi all,
Now that shlib tests run on cygwin (with binutils-cvs), the
gdb.base/shreloc.exp
test caught a dll loading bug. There is an attempt to get to
SECT_OFF_DATA (objfile),
in an objfile without the sect_index_data set.
Here is what happens:
The dlls built from shreloc1.c and shreloc2.c don't have .data sections.
Also, they are both compiled into the same preferred load address using
-Wl,--image-base,0x04000000. Since only one can load at that image-base,
the other dll will be relocated.
When the first dll is loaded, in symfile.c:init_objfile_sect_indices
there is code that
sets objfile->sect_index_data to 0 if no section was found.
symfile.c:init_objfile_sect_indices:
for (i = 0; i < objfile->num_sections; i++)
{
if (ANOFFSET (objfile->section_offsets, i) != 0)
{
break;
}
}
if (i == objfile->num_sections)
{
if (objfile->sect_index_text == -1)
objfile->sect_index_text = 0;
if (objfile->sect_index_data == -1)
objfile->sect_index_data = 0;
if (objfile->sect_index_bss == -1)
objfile->sect_index_bss = 0;
if (objfile->sect_index_rodata == -1)
objfile->sect_index_rodata = 0;
}
But, when the second dll is loaded, and since it was relocated,
the 'ANOFFSET (objfile->section_offsets, i) != 0' will be true, thus
skipping
the initialization to zero afterwards, thus leaving
objfile->sect_index_data with
the default of -1. The internal_error then is called on
coffread.c:coff_symtab_read,
while reading the minsyms, where there is code like this:
else if (sec == SECT_OFF_DATA (objfile))
{
ms_type =
cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXT ?
mst_data : mst_file_data;
}
The attached patch fixes it by not depending on the SECT_OFF_* macros to
determine
the minimal_symbol_type of the minsymbol, but using bfd_section flags.
In the process I noted that bss symbols where recorded with mst_data or
mst_file_data
types. Fixed that too.
The shreloc.exp needs a little tweak since passing
-Wl,--image-base,0x04000000 on
additional_flags when building the .o files ends up giving the
unfiltered warning:
"linker input file unused because linking not done"
which causes the test to end up being untested.
Tested on i686-pc-cygwin, where it fixes the crash, makes shreloc.exp
pass perfectly, and
introduces no new regressions.
Please review and commit,
Cheers,
Pedro Alves
----
gdb/
2006-12-21 Pedro Alves <pedro_alves@portugalmail.pt>
* coffread.c (cs_to_section): If bfd_section is found, always
return it's section index.
(coff_symtab_read): Determine the minimal_symbol_type using the
bfd_section flags.
gdb/testsuite/
2006-12-21 Pedro Alves <pedro_alves@portugalmail.pt>
* gdb.base/shreloc.exp: Use ldflags instead of additional_flags to
pass --image-base to linker.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: dllfix.diff
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20061221/2e771263/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: shreloc.exp.diff
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20061221/2e771263/attachment-0001.ksh>
More information about the Gdb-patches
mailing list