* emultempl/pe.em (debug_section_p): New bfd_map_over_sections hook.
authorDave Korn <dave.korn@artimi.com>
Tue, 3 Mar 2009 18:22:11 +0000 (18:22 +0000)
committerDave Korn <dave.korn@artimi.com>
Tue, 3 Mar 2009 18:22:11 +0000 (18:22 +0000)
(gld_${EMULATION_NAME}_after_open):  Use it to iterate all sections
of all input BFDs, looking for debug info.  Enable long section names
if any found.
* emultempl/pe.em (debug_section_p):  Likewise.
(gld_${EMULATION_NAME}_after_open):  Likewise.
* NEWS:  Retrospectively adjust news announcement.
* ld.texinfo:  Update documentation to mention new behaviour.

ld/ChangeLog
ld/NEWS
ld/emultempl/pe.em
ld/emultempl/pep.em
ld/ld.texinfo

index 1d0fea9015c671bd93364f0af1fde9cfa45c7b84..ba87342d8f3885a2fa1bd17482708bd11f57dff5 100644 (file)
@@ -1,3 +1,14 @@
+2009-03-03  Dave Korn  <dave.korn.cygwin@gmail.com>
+
+       * emultempl/pe.em (debug_section_p):  New bfd_map_over_sections hook.
+       (gld_${EMULATION_NAME}_after_open):  Use it to iterate all sections
+       of all input BFDs, looking for debug info.  Enable long section names
+       if any found.
+       * emultempl/pe.em (debug_section_p):  Likewise.
+       (gld_${EMULATION_NAME}_after_open):  Likewise.
+       * NEWS:  Retrospectively adjust news announcement.
+       * ld.texinfo:  Update documentation to mention new behaviour.
+
 2009-03-02  Sebastian Huber  <sebastian.huber@embedded-brains.de>
 
        * ldgram.y: Add support for REGION_ALIAS operator.
diff --git a/ld/NEWS b/ld/NEWS
index e4951572d80768127d003d57d199734532471e12..440534ac83fb2c4d0b24f8447e189bfabb607769 100644 (file)
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -5,7 +5,9 @@
 * PE targets no longer make use of the long section names PE extension to
   the COFF format when generating executable images, by default.  The old
   (slightly non-conformant) behaviour can still be invoked by using the
-  new '--enable-long-section-names' command-line option.
+  new '--enable-long-section-names' command-line option.  It is also enabled
+  automatically in the presence of un-stripped debug information, as GDB
+  needs to be able to find the debug info sections by their full names.
 
 * --as-needed now links in a dynamic library if it satisfies undefined
   symbols in regular objects, or in other dynamic libraries.  In the
index 46c4057433eeb4dae42054aab5aeb46c213b53d3..58ec809dfe20536f699baf492c5371bd0b81d07c 100644 (file)
@@ -1043,6 +1043,13 @@ pr_sym (struct bfd_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
 }
 #endif /* DLL_SUPPORT */
 
+static void 
+debug_section_p (bfd *abfd ATTRIBUTE_UNUSED, asection *sect, void *obj)
+{
+  int *found = (int *) obj;
+  if (strncmp (".debug_", sect->name, sizeof (".debug_") - 1) == 0)
+    *found = 1;
+}
 
 static void
 gld_${EMULATION_NAME}_after_open (void)
@@ -1076,6 +1083,29 @@ gld_${EMULATION_NAME}_after_open (void)
   pe_data (link_info.output_bfd)->pe_opthdr = pe;
   pe_data (link_info.output_bfd)->dll = init[DLLOFF].value;
   pe_data (link_info.output_bfd)->real_flags |= real_flags;
+
+  /* At this point we must decide whether to use long section names
+     in the output or not.  If the user hasn't explicitly specified
+     on the command line, we leave it to the default for the format
+     (object files yes, image files no), except if there is debug
+     information present; GDB relies on the long section names to
+     find it, so enable it in that case.  */
+  if (pe_use_coff_long_section_names < 0 && link_info.strip == strip_none)
+    {
+      /* Iterate over all sections of all input BFDs, checking
+         for any that begin 'debug_' and are long names.  */
+      LANG_FOR_EACH_INPUT_STATEMENT (is)
+       {
+         int found_debug = 0;
+         bfd_map_over_sections (is->the_bfd, debug_section_p, &found_debug);
+         if (found_debug)
+           {
+             pe_use_coff_long_section_names = 1;
+             break;
+           }
+       }
+    }
+
   pe_output_file_set_long_section_names (link_info.output_bfd);
 
 #ifdef DLL_SUPPORT
index 0ab913b3f1ad294b32b5e6ea9cbb78bc673f44ce..13180a01825be39020c52302fc20182271cee79f 100644 (file)
@@ -1020,6 +1020,13 @@ pr_sym (struct bfd_hash_entry *h, void *inf ATTRIBUTE_UNUSED)
 }
 #endif /* DLL_SUPPORT */
 
+static void 
+debug_section_p (bfd *abfd ATTRIBUTE_UNUSED, asection *sect, void *obj)
+{
+  int *found = (int *) obj;
+  if (strncmp (".debug_", sect->name, sizeof (".debug_") - 1) == 0)
+    *found = 1;
+}
 
 static void
 gld_${EMULATION_NAME}_after_open (void)
@@ -1053,6 +1060,29 @@ gld_${EMULATION_NAME}_after_open (void)
   pe_data (link_info.output_bfd)->pe_opthdr = pep;
   pe_data (link_info.output_bfd)->dll = init[DLLOFF].value;
   pe_data (link_info.output_bfd)->real_flags |= real_flags;
+
+  /* At this point we must decide whether to use long section names
+     in the output or not.  If the user hasn't explicitly specified
+     on the command line, we leave it to the default for the format
+     (object files yes, image files no), except if there is debug
+     information present; GDB relies on the long section names to
+     find it, so enable it in that case.  */
+  if (pep_use_coff_long_section_names < 0 && link_info.strip == strip_none)
+    {
+      /* Iterate over all sections of all input BFDs, checking
+         for any that begin 'debug_' and are long names.  */
+      LANG_FOR_EACH_INPUT_STATEMENT (is)
+       {
+         int found_debug = 0;
+         bfd_map_over_sections (is->the_bfd, debug_section_p, &found_debug);
+         if (found_debug)
+           {
+             pep_use_coff_long_section_names = 1;
+             break;
+           }
+       }
+    }
+
   pep_output_file_set_long_section_names (link_info.output_bfd);
 
 #ifdef DLL_SUPPORT
index 167df2838f91d919889c21452ba6526d7a995731..e2a70a8b7a91c7fd6f48389f216f9b1b26ff7777 100644 (file)
@@ -2124,7 +2124,13 @@ allow their use in executable images as well, or to (probably pointlessly!)
 disallow it in object files, by using these two options.  Executable images
 generated with these long section names are slightly non-standard, carrying
 as they do a string table, and may generate confusing output when examined
-with non-GNU PE-aware tools, such as file viewers and dumpers.
+with non-GNU PE-aware tools, such as file viewers and dumpers.  However, 
+GDB relies on the use of PE long section names to find Dwarf-2 debug 
+information sections in an executable image at runtime, and so if neither
+option is specified on the command-line, @command{ld} will enable long
+section names, overriding the default and technically correct behaviour,
+when it finds the presence of debug information while linking an executable
+image and not stripping symbols.
 [This option is valid for all PE targeted ports of the linker]
 
 @kindex --enable-stdcall-fixup
This page took 0.035713 seconds and 4 git commands to generate.