[PATCH] Support DWARF 2/3 on i?86 PE
Brian Ford
ford@vss.fsi.com
Fri Apr 16 03:36:00 GMT 2004
I guess the subject says it all.
After this and the previous .secrel32 patch are applied, I'll submit the
gcc patch to enable DWARF 2 on PE (Cygwin/Mingw) using them.
Just a friendly reminder :), the following three patches are still pending
and fix bugs uncovered by these patches.
http://sources.redhat.com/ml/binutils/2004-04/msg00279.html
http://sources.redhat.com/ml/binutils/2004-04/msg00279.html
Ok, this one isn't *that* related, but it's still pending ;-).
http://sources.redhat.com/ml/binutils/2004-04/msg00279.html
I know Nick has been out for some time and is probably trying to dig out
slowly. No rush :-).
Thanks in advance again for the review.
--
Brian Ford
Senior Realtime Software Engineer
VITAL - Visual Simulation Systems
FlightSafety International
Phone: 314-551-8460
Fax: 314-551-8444
-------------- next part --------------
bfd/ChangeLog:
2004-04-14 Brian Ford <ford@vss.fsi.com>
* bfd.c (bfd_get_sign_extend_vma): Add pe[i]-i386 case to DJGPP hack.
* coffcode.h (DOT_DEBUG, GNU_LINKONCE_WI): Define.
[!COFF_WITH_PE] (sec_to_styp_flags, styp_to_sec_flags): Use them.
(coff_compute_section_file_positions) [RS6000COFF_C]: Likewise.
[COFF_WITH_PE] (sec_to_styp_flags): Handle DWARF 2/3 .debug* and
.gnu.linkonce.wi. sections.
* pe-i386.c (COFF_SUPPORT_GNU_LINKONCE): Define.
(COFF_SECTION_ALIGNMENT_ENTRIES): Add entries for .debug and
.gnu.linkonce.wi..
* pei-i386.c (COFF_SUPPORT_GNU_LINKONCE): Likewise.
(COFF_SECTION_ALIGNMENT_ENTRIES): Likewise.
gas/ChangeLog:
2004-04-14 Brian Ford <ford@vss.fsi.com>
* dwarf2dbg.c (dwarf2_finish): Add SEC_DEBUGGING to section flags.
ld/ChangeLog:
2004-04-14 Brian Ford <ford@vss.fsi.com>
* scripttempl/pe.sc: Handle .debug* and .gnu.linkonce.wi.* sections
for DWARF 2/3. Update stab section's syntax.
-------------- next part --------------
Index: bfd/bfd.c
===================================================================
RCS file: /cvs/src/src/bfd/bfd.c,v
retrieving revision 1.56
diff -u -p -r1.56 bfd.c
--- bfd/bfd.c 15 Apr 2004 08:48:56 -0000 1.56
+++ bfd/bfd.c 16 Apr 2004 01:44:30 -0000
@@ -769,12 +769,14 @@ bfd_get_sign_extend_vma (bfd *abfd)
name = bfd_get_target (abfd);
- /* Return a proper value for DJGPP COFF (an x86 COFF variant).
+ /* Return a proper value for DJGPP & PE COFF (x86 COFF variants).
This function is required for DWARF2 support, but there is
no place to store this information in the COFF back end.
Should enough other COFF targets add support for DWARF2,
a place will have to be found. Until then, this hack will do. */
- if (strncmp (name, "coff-go32", sizeof ("coff-go32") - 1) == 0)
+ if (strncmp (name, "coff-go32", sizeof ("coff-go32") - 1) == 0
+ || strcmp (name, "pe-i386") == 0
+ || strcmp (name, "pei-i386") == 0)
return 1;
bfd_set_error (bfd_error_wrong_format);
Index: bfd/coffcode.h
===================================================================
RCS file: /cvs/src/src/bfd/coffcode.h,v
retrieving revision 1.101
diff -u -p -r1.101 coffcode.h
--- bfd/coffcode.h 19 Dec 2003 10:01:59 -0000 1.101
+++ bfd/coffcode.h 16 Apr 2004 01:44:32 -0000
@@ -309,6 +309,9 @@ CODE_FRAGMENT
#define STRING_SIZE_SIZE (4)
+#define DOT_DEBUG ".debug"
+#define GNU_LINKONCE_WI ".gnu.linkonce.wi."
+
static long sec_to_styp_flags
PARAMS ((const char *, flagword));
static bfd_boolean styp_to_sec_flags
@@ -428,7 +431,7 @@ sec_to_styp_flags (sec_name, sec_flags)
styp_flags = STYP_LIT;
#endif /* _LIT */
}
- else if (!strncmp (sec_name, ".debug", 6))
+ else if (!strncmp (sec_name, DOT_DEBUG, sizeof (DOT_DEBUG) - 1))
{
/* Handle the XCOFF debug section and DWARF2 debug sections. */
if (!sec_name[6])
@@ -441,7 +444,7 @@ sec_to_styp_flags (sec_name, sec_flags)
styp_flags = STYP_DEBUG_INFO;
}
#ifdef COFF_LONG_SECTION_NAMES
- else if (!strncmp (sec_name, ".gnu.linkonce.wi.", 17))
+ else if (!strncmp (sec_name, GNU_LINKONCE_WI, sizeof (GNU_LINKONCE_WI) - 1))
{
styp_flags = STYP_DEBUG_INFO;
}
@@ -518,7 +521,7 @@ sec_to_styp_flags (sec_name, sec_flags)
static long
sec_to_styp_flags (sec_name, sec_flags)
- const char *sec_name ATTRIBUTE_UNUSED;
+ const char *sec_name;
flagword sec_flags;
{
long styp_flags = 0;
@@ -531,6 +534,11 @@ sec_to_styp_flags (sec_name, sec_flags)
PE files. The STYP_* flags and the IMAGE_SCN_* flags overlap,
but there are more IMAGE_SCN_* flags. */
+ /* FIXME: There is no gas syntax to specify the debug section flag. */
+ if (strncmp(sec_name, DOT_DEBUG, sizeof (DOT_DEBUG) - 1) == 0
+ || strncmp(sec_name, GNU_LINKONCE_WI, sizeof (GNU_LINKONCE_WI) - 1) == 0)
+ sec_flags = SEC_READONLY | SEC_DEBUGGING;
+
/* skip LOAD */
/* READONLY later */
/* skip RELOC */
@@ -675,12 +683,12 @@ styp_to_sec_flags (abfd, hdr, name, sect
#endif
sec_flags |= SEC_ALLOC;
}
- else if (strncmp (name, ".debug", 6) == 0
+ else if (strncmp (name, DOT_DEBUG, sizeof (DOT_DEBUG) - 1) == 0
#ifdef _COMMENT
|| strcmp (name, _COMMENT) == 0
#endif
#ifdef COFF_LONG_SECTION_NAMES
- || strncmp (name, ".gnu.linkonce.wi.", 17) == 0
+ || strncmp (name, GNU_LINKONCE_WI, sizeof (GNU_LINKONCE_WI) - 1) == 0
#endif
|| strncmp (name, ".stab", 5) == 0)
{
@@ -3004,7 +3012,7 @@ coff_compute_section_file_positions (abf
{
asection *dsec;
- dsec = bfd_make_section_old_way (abfd, ".debug");
+ dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
if (dsec == NULL)
abort ();
dsec->_raw_size = sz;
Index: bfd/pe-i386.c
===================================================================
RCS file: /cvs/src/src/bfd/pe-i386.c,v
retrieving revision 1.6
diff -u -p -r1.6 pe-i386.c
--- bfd/pe-i386.c 30 Nov 2002 08:39:40 -0000 1.6
+++ bfd/pe-i386.c 16 Apr 2004 01:44:33 -0000
@@ -26,6 +26,7 @@
#define PCRELOFFSET TRUE
#define TARGET_UNDERSCORE '_'
#define COFF_LONG_SECTION_NAMES
+#define COFF_SUPPORT_GNU_LINKONCE
#define COFF_LONG_FILENAMES
#define COFF_SECTION_ALIGNMENT_ENTRIES \
@@ -38,6 +39,10 @@
{ COFF_SECTION_NAME_PARTIAL_MATCH (".idata"), \
COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
{ COFF_SECTION_NAME_EXACT_MATCH (".pdata"), \
- COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }
+ COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
+{ COFF_SECTION_NAME_PARTIAL_MATCH (".debug"), \
+ COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }, \
+{ COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.wi."), \
+ COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }
#include "coff-i386.c"
Index: bfd/pei-i386.c
===================================================================
RCS file: /cvs/src/src/bfd/pei-i386.c,v
retrieving revision 1.5
diff -u -p -r1.5 pei-i386.c
--- bfd/pei-i386.c 30 Nov 2002 08:39:40 -0000 1.5
+++ bfd/pei-i386.c 16 Apr 2004 01:44:33 -0000
@@ -27,6 +27,7 @@
#define PCRELOFFSET TRUE
#define TARGET_UNDERSCORE '_'
#define COFF_LONG_SECTION_NAMES
+#define COFF_SUPPORT_GNU_LINKONCE
#define COFF_LONG_FILENAMES
#define COFF_SECTION_ALIGNMENT_ENTRIES \
@@ -39,6 +40,10 @@
{ COFF_SECTION_NAME_PARTIAL_MATCH (".idata"), \
COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
{ COFF_SECTION_NAME_EXACT_MATCH (".pdata"), \
- COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }
+ COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
+{ COFF_SECTION_NAME_PARTIAL_MATCH (".debug"), \
+ COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }, \
+{ COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.wi."), \
+ COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 0 }
#include "coff-i386.c"
Index: gas/dwarf2dbg.c
===================================================================
RCS file: /cvs/src/src/gas/dwarf2dbg.c,v
retrieving revision 1.69
diff -u -p -r1.69 dwarf2dbg.c
--- gas/dwarf2dbg.c 13 Feb 2004 16:12:46 -0000 1.69
+++ gas/dwarf2dbg.c 16 Apr 2004 01:44:35 -0000
@@ -1371,7 +1371,7 @@ dwarf2_finish (void)
/* Create and switch to the line number section. */
line_seg = subseg_new (".debug_line", 0);
- bfd_set_section_flags (stdoutput, line_seg, SEC_READONLY);
+ bfd_set_section_flags (stdoutput, line_seg, SEC_READONLY | SEC_DEBUGGING);
/* For each subsection, chain the debug entries together. */
for (s = all_segs; s; s = s->next)
@@ -1400,9 +1400,12 @@ dwarf2_finish (void)
abbrev_seg = subseg_new (".debug_abbrev", 0);
aranges_seg = subseg_new (".debug_aranges", 0);
- bfd_set_section_flags (stdoutput, info_seg, SEC_READONLY);
- bfd_set_section_flags (stdoutput, abbrev_seg, SEC_READONLY);
- bfd_set_section_flags (stdoutput, aranges_seg, SEC_READONLY);
+ bfd_set_section_flags (stdoutput, info_seg,
+ SEC_READONLY | SEC_DEBUGGING);
+ bfd_set_section_flags (stdoutput, abbrev_seg,
+ SEC_READONLY | SEC_DEBUGGING);
+ bfd_set_section_flags (stdoutput, aranges_seg,
+ SEC_READONLY | SEC_DEBUGGING);
record_alignment (aranges_seg, ffs (2 * sizeof_address) - 1);
Index: ld/scripttempl/pe.sc
===================================================================
RCS file: /cvs/src/src/ld/scripttempl/pe.sc,v
retrieving revision 1.9
diff -u -p -r1.9 pe.sc
--- ld/scripttempl/pe.sc 10 Nov 2003 17:04:55 -0000 1.9
+++ ld/scripttempl/pe.sc 16 Apr 2004 01:44:44 -0000
@@ -159,13 +159,92 @@ SECTIONS
.stab ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
{
- [ .stab ]
+ *(.stab)
}
.stabstr ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
{
- [ .stabstr ]
+ *(.stabstr)
}
+ /* DWARF debug sections.
+ Symbols in the DWARF debugging sections are relative to the beginning
+ of the section. Unlike other targets that fake this by putting the
+ section VMA at 0, the PE format will not allow it.
+ */
+
+ /* DWARF 1.1 and DWARF 2 */
+ .debug_aranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
+ {
+ *(.debug_aranges)
+ }
+
+ .debug_pubnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
+ {
+ *(.debug_pubnames)
+ }
+
+ /* DWARF 2 */
+ .debug_info ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
+ {
+ *(.debug_info) *(.gnu.linkonce.wi.*)
+ }
+
+ .debug_abbrev ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
+ {
+ *(.debug_abbrev)
+ }
+
+ .debug_line ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
+ {
+ *(.debug_line)
+ }
+
+ .debug_frame ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
+ {
+ *(.debug_frame)
+ }
+
+ .debug_str ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
+ {
+ *(.debug_str)
+ }
+
+ .debug_loc ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
+ {
+ *(.debug_loc)
+ }
+
+ .debug_macinfo ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
+ {
+ *(.debug_macinfo)
+ }
+
+ /* SGI/MIPS DWARF 2 extensions. */
+ .debug_weaknames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
+ {
+ *(.debug_weaknames)
+ }
+
+ .debug_funcnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
+ {
+ *(.debug_funcnames)
+ }
+
+ .debug_typenames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
+ {
+ *(.debug_typenames)
+ }
+
+ .debug_varnames ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
+ {
+ *(.debug_varnames)
+ }
+
+ /* DWARF 3 */
+ .debug_ranges ${RELOCATING+BLOCK(__section_alignment__)} ${RELOCATING+(NOLOAD)} :
+ {
+ *(.debug_ranges)
+ }
}
EOF
More information about the Binutils
mailing list