* [PATCH] Allow dwarf2 debug info for function at address 0
@ 2006-07-21 14:23 Frederic RISS
2006-07-24 20:05 ` Daniel Jacobowitz
0 siblings, 1 reply; 5+ messages in thread
From: Frederic RISS @ 2006-07-21 14:23 UTC (permalink / raw)
To: gdb-patches; +Cc: Steven Johnson
[-- Attachment #1: Type: text/plain, Size: 1363 bytes --]
Hi,
This is a follow-up to the "Problems with startup code symbols (Copious
warnings)" gdb@ thread found here:
http://sources.redhat.com/ml/gdb/2006-06/msg00051.html
The attached patch replaces the HAS_RELOC checks in dwarf2read.c with a
per-objfile lookup for a section loaded at 0. With this modification,
non-relocatable files that have a code at address 0 should be handled
better (no discarded debug information).
As Daniel pointed out in the referenced thread, this solution isn't
perfect because you can have valid code at 0 and at the same time
'orphaned' debug info that seemingly references the 0 address. However
in the long run tools should correctly handle things like .gnu.linkonce,
and with correct debug info this patch looks like the right thing. (BTW,
was my testing defficient, or do recent GNU toolchains handle linkonce
sections and associated debug info correctly?)
I regression tested this on native i686-pc-linux-gnu.
Steven, by re-reading the thread that initiated this proposal I'm not
sure that this will really change something for you because the subject
had a bit diverged from your particular problem. Nevertheless could you
still give it a try to see if it helps with your warning issue?
:ADDPATCH Dwarf2:
(Nice side-effect of the patch tracker: It reminded me that I needed to
actually attach the patch :-) )
Cheers,
Fred
[-- Attachment #2: dwarf2_use_vma.patch --]
[-- Type: text/x-patch, Size: 2704 bytes --]
2006-07-21 Frederic Riss <frederic.riss@st.com>
* dwarf2read.c (struct dwarf2_per_objfile): Add has_section_at_zero
field.
(dwarf2_has_info): Initialize dwarf2_per_objfile->has_section_at_zero.
(dwarf2_get_pc_bounds): Use dwarf2_per_objfile->has_section_at_zero
instead of HAS_RELOC test.
(read_partial_die): Ditto.
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.200
diff -u -p -r1.200 dwarf2read.c
--- dwarf2read.c 12 Jul 2006 21:14:57 -0000 1.200
+++ dwarf2read.c 20 Jul 2006 16:24:42 -0000
@@ -180,6 +180,10 @@ struct dwarf2_per_objfile
/* A chain of compilation units that are currently read in, so that
they can be freed later. */
struct dwarf2_per_cu_data *read_in_chain;
+
+ /* A flag indicating wether this objfile has a section loaded at a
+ VMA of 0. */
+ int has_section_at_zero;
};
static struct dwarf2_per_objfile *dwarf2_per_objfile;
@@ -1083,6 +1087,7 @@ int
dwarf2_has_info (struct objfile *objfile)
{
struct dwarf2_per_objfile *data;
+ asection *lower_sect = NULL;
/* Initialize per-objfile state. */
data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data));
@@ -1090,6 +1095,10 @@ dwarf2_has_info (struct objfile *objfile
set_objfile_data (objfile, dwarf2_objfile_data_key, data);
dwarf2_per_objfile = data;
+ bfd_map_over_sections (objfile->obfd, find_lowest_section, &lower_sect);
+ if (lower_sect && bfd_section_vma (objfile->obfd, lower_sect) == 0)
+ data->has_section_at_zero = 1;
+
dwarf_info_section = 0;
dwarf_abbrev_section = 0;
dwarf_line_section = 0;
@@ -1099,7 +1108,7 @@ dwarf2_has_info (struct objfile *objfile
dwarf_eh_frame_section = 0;
dwarf_ranges_section = 0;
dwarf_loc_section = 0;
-
+
bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL);
return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL);
}
@@ -3177,7 +3186,7 @@ dwarf2_get_pc_bounds (struct die_info *d
labels are not in the output, so the relocs get a value of 0.
If this is a discarded function, mark the pc bounds as invalid,
so that GDB will ignore it. */
- if (low == 0 && (bfd_get_file_flags (obfd) & HAS_RELOC) == 0)
+ if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
return 0;
*lowpc = low;
@@ -5505,7 +5514,7 @@ read_partial_die (struct partial_die_inf
if (has_low_pc_attr && has_high_pc_attr
&& part_die->lowpc < part_die->highpc
&& (part_die->lowpc != 0
- || (bfd_get_file_flags (abfd) & HAS_RELOC)))
+ || dwarf2_per_objfile->has_section_at_zero))
part_die->has_pc_info = 1;
return info_ptr;
}
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] Allow dwarf2 debug info for function at address 0
2006-07-21 14:23 [PATCH] Allow dwarf2 debug info for function at address 0 Frederic RISS
@ 2006-07-24 20:05 ` Daniel Jacobowitz
2006-07-24 21:39 ` Frédéric Riss
0 siblings, 1 reply; 5+ messages in thread
From: Daniel Jacobowitz @ 2006-07-24 20:05 UTC (permalink / raw)
To: Frederic RISS; +Cc: gdb-patches, Steven Johnson
On Fri, Jul 21, 2006 at 04:23:13PM +0200, Frederic RISS wrote:
> The attached patch replaces the HAS_RELOC checks in dwarf2read.c with a
> per-objfile lookup for a section loaded at 0. With this modification,
> non-relocatable files that have a code at address 0 should be handled
> better (no discarded debug information).
> As Daniel pointed out in the referenced thread, this solution isn't
> perfect because you can have valid code at 0 and at the same time
> 'orphaned' debug info that seemingly references the 0 address. However
> in the long run tools should correctly handle things like .gnu.linkonce,
> and with correct debug info this patch looks like the right thing. (BTW,
> was my testing defficient, or do recent GNU toolchains handle linkonce
> sections and associated debug info correctly?)
It can be pretty hard to trigger this sort of problem. No, GNU
handling for linkonce debug info has not really changed in a while.
> 2006-07-21 Frederic Riss <frederic.riss@st.com>
>
> * dwarf2read.c (struct dwarf2_per_objfile): Add has_section_at_zero
> field.
> (dwarf2_has_info): Initialize dwarf2_per_objfile->has_section_at_zero.
> (dwarf2_get_pc_bounds): Use dwarf2_per_objfile->has_section_at_zero
> instead of HAS_RELOC test.
> (read_partial_die): Ditto.
This patch is OK.
One possible improvement; there's already a walk over all sections.
You could set this flag directly in dwarf2_locate_sections, I think.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Allow dwarf2 debug info for function at address 0
2006-07-24 20:05 ` Daniel Jacobowitz
@ 2006-07-24 21:39 ` Frédéric Riss
2006-07-24 22:02 ` Daniel Jacobowitz
0 siblings, 1 reply; 5+ messages in thread
From: Frédéric Riss @ 2006-07-24 21:39 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: Frederic RISS, gdb-patches, Steven Johnson
[-- Attachment #1: Type: text/plain, Size: 1307 bytes --]
Le lundi 24 juillet 2006 à 16:04 -0400, Daniel Jacobowitz a écrit :
> On Fri, Jul 21, 2006 at 04:23:13PM +0200, Frederic RISS wrote:
> > (BTW,
> > was my testing defficient, or do recent GNU toolchains handle linkonce
> > sections and associated debug info correctly?)
>
> It can be pretty hard to trigger this sort of problem. No, GNU
> handling for linkonce debug info has not really changed in a while.
OK; so my testing was deficient... but maybe we're not speaking of the
same 'correct handling'?
I thought that we had issues with relocating the debug information
coming from different linkonce sections against the only one kept in the
linked file... but that definitely works for me on a simple example.
So I guess that we're referring to more deeply broken cases (for example
when debug info is generated for a linkonce section of which all
instances will get discarded). And I indeed have no idea how to generate
such a case even by resorting to my more convoluted template-fu :-)
> This patch is OK.
>
> One possible improvement; there's already a walk over all sections.
> You could set this flag directly in dwarf2_locate_sections, I think.
You're right, it's much nicer like this. I checked the attached in.
(Oh, and thanks for fixing the date in my previous ChangeLog entry)
[-- Attachment #2: dwarf2_use_vma.patch --]
[-- Type: text/x-patch, Size: 2409 bytes --]
2006-07-24 Frederic Riss <frederic.riss@st.com>
* dwarf2read.c (struct dwarf2_per_objfile): Add has_section_at_zero
field.
(dwarf2_locate_sections): Initialize
dwarf2_per_objfile->has_section_at_zero.
(dwarf2_get_pc_bounds): Use dwarf2_per_objfile->has_section_at_zero
instead of HAS_RELOC test.
(read_partial_die): Ditto.
Index: dwarf2read.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2read.c,v
retrieving revision 1.200
diff -u -p -r1.200 dwarf2read.c
--- dwarf2read.c 12 Jul 2006 21:14:57 -0000 1.200
+++ dwarf2read.c 24 Jul 2006 21:17:33 -0000
@@ -180,6 +180,10 @@ struct dwarf2_per_objfile
/* A chain of compilation units that are currently read in, so that
they can be freed later. */
struct dwarf2_per_cu_data *read_in_chain;
+
+ /* A flag indicating wether this objfile has a section loaded at a
+ VMA of 0. */
+ int has_section_at_zero;
};
static struct dwarf2_per_objfile *dwarf2_per_objfile;
@@ -1109,7 +1113,7 @@ dwarf2_has_info (struct objfile *objfile
in. */
static void
-dwarf2_locate_sections (bfd *ignore_abfd, asection *sectp, void *ignore_ptr)
+dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr)
{
if (strcmp (sectp->name, INFO_SECTION) == 0)
{
@@ -1170,6 +1174,10 @@ dwarf2_locate_sections (bfd *ignore_abfd
dwarf2_per_objfile->ranges_size = bfd_get_section_size (sectp);
dwarf_ranges_section = sectp;
}
+
+ if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD)
+ && bfd_section_vma (abfd, sectp) == 0)
+ dwarf2_per_objfile->has_section_at_zero = 1;
}
/* Build a partial symbol table. */
@@ -3177,7 +3185,7 @@ dwarf2_get_pc_bounds (struct die_info *d
labels are not in the output, so the relocs get a value of 0.
If this is a discarded function, mark the pc bounds as invalid,
so that GDB will ignore it. */
- if (low == 0 && (bfd_get_file_flags (obfd) & HAS_RELOC) == 0)
+ if (low == 0 && !dwarf2_per_objfile->has_section_at_zero)
return 0;
*lowpc = low;
@@ -5505,7 +5513,7 @@ read_partial_die (struct partial_die_inf
if (has_low_pc_attr && has_high_pc_attr
&& part_die->lowpc < part_die->highpc
&& (part_die->lowpc != 0
- || (bfd_get_file_flags (abfd) & HAS_RELOC)))
+ || dwarf2_per_objfile->has_section_at_zero))
part_die->has_pc_info = 1;
return info_ptr;
}
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] Allow dwarf2 debug info for function at address 0
2006-07-24 21:39 ` Frédéric Riss
@ 2006-07-24 22:02 ` Daniel Jacobowitz
2006-07-24 22:30 ` Frédéric Riss
0 siblings, 1 reply; 5+ messages in thread
From: Daniel Jacobowitz @ 2006-07-24 22:02 UTC (permalink / raw)
To: Frédéric Riss; +Cc: Frederic RISS, gdb-patches, Steven Johnson
On Mon, Jul 24, 2006 at 11:39:42PM +0200, Frédéric Riss wrote:
> OK; so my testing was deficient... but maybe we're not speaking of the
> same 'correct handling'?
>
> I thought that we had issues with relocating the debug information
> coming from different linkonce sections against the only one kept in the
> linked file... but that definitely works for me on a simple example.
It depends what version of binutils you've got installed. At least one
of HJ's "Linux binutils" releases does this, but it's actually even
more wrong to point multiple copies of the debug information at
the same code address; you can get very confusing mismatches if they
were e.g. compiled by different compilers.
Thanks for the revised patch; it looks great.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Allow dwarf2 debug info for function at address 0
2006-07-24 22:02 ` Daniel Jacobowitz
@ 2006-07-24 22:30 ` Frédéric Riss
0 siblings, 0 replies; 5+ messages in thread
From: Frédéric Riss @ 2006-07-24 22:30 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: Frederic RISS, gdb-patches, Steven Johnson
Le lundi 24 juillet 2006 à 18:02 -0400, Daniel Jacobowitz a écrit :
> > I thought that we had issues with relocating the debug information
> > coming from different linkonce sections against the only one kept in
> > the linked file... but that definitely works for me on a simple
> > example.
>
> It depends what version of binutils you've got installed. At least
> one of HJ's "Linux binutils" releases does this,
That could be it I think... My home box, on which I tested, runs Ubuntu
Dapper. I didn't know it used HJ's linux-only binutils though. I like to
learn something every day. Thanks for the pointer!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-07-24 22:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-21 14:23 [PATCH] Allow dwarf2 debug info for function at address 0 Frederic RISS
2006-07-24 20:05 ` Daniel Jacobowitz
2006-07-24 21:39 ` Frédéric Riss
2006-07-24 22:02 ` Daniel Jacobowitz
2006-07-24 22:30 ` Frédéric Riss
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox