This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Sequel to PR40521 -- -g causes GCC to generate .eh_frame


Hello!

On 2010-03-30 14:52, Daniel Jacobowitz wrote:
> On Thu, Mar 25, 2010 at 02:34:26PM +0100, Thomas Schwinge wrote:
>> Here is a sequel to PR40521 -- -g causes GCC to generate .eh_frame.
>> 
>> On arm-none-linux-gnueabi, if -fexceptions /
>> -fasynchronous-unwind-tables / -funwind-tables is in effect, GCC will
>> now *always* emit CFI statements -- and .cfi_sections .debug_frame
>> additionally *only* if -g is specified.
>
> This is IMO a serious problem; it generates a lot of extra data for
> C++ on ARM (a primary platform).


> I couldn't figure out the existing logic, so I've simplified it and
> attached another possible solution (untested).  It does have some
> related changes in behavior, because the existing checks are
> inconsistent; some are:
>
>   flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS),
>
> Others are:
>
>   ! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions)

I couldn't find anything obviously wrong with these simplifications.


>> Defining gcc/config/arm/arm.h:DWARF2_UNWIND_INFO to 0 instead of 1 has
>> the desired effect, but I'm not really sure that is correct to do?
>
> By comparison with IA64, I think this is (surprisingly, to me) the
> right solution.  In fact, delete the definition.  Then non-EABI ARM
> configurations will allow DWARF2_UNWIND_INFO via defaults.h.

So, my original idea was not wrong, which is relieving.

Deleting the definition is different from defining it to zero, as this is
sort of a tri-state thing: undefined meaning that the DWARF unwinding
machinery is not implemented, zero meaning that it is implemented but
shall not be used, and one meaning that it shall be used.  (See my
documentation update, too.)  For example, compare with this use in
gcc/c-cppbuiltin.c:c_cpp_builtins:

    #ifdef DWARF2_UNWIND_INFO
      if (dwarf2out_do_cfi_asm ())
        cpp_define (pfile, "__GCC_HAVE_DWARF2_CFI_ASM");
    #endif

I moved the to-zero definition to the place where TARGET_UNWIND_INFO is
defined.  Is that the correct place, or are there ARM configurations
where this doesn't fit?

> Thomas, want to give this a spin?

Here is the patch that I've been testing to do the right thing for
arm-none-linux-gnueabi, and not cause any regressions on
i686-pc-linux-gnu.  I used the following set of options...

    (none)
    -fno-dwarf2-cfi-asm
    -funwind-tables
    -fno-dwarf2-cfi-asm -funwind-tables
    -g
    -fno-dwarf2-cfi-asm -g
    -g -funwind-tables
    -fno-dwarf2-cfi-asm -g -funwind-tables

... on a simple C file containing a function that calls another external
function, and inspected the generated assembler code as well as the
object files for containing the correct statements, on i686-pc-linux-gnu
and arm-none-linux-gnueabi.

Automated regression testing on i686-pc-linux-gnu is still running.  Any
further testing needed?

Is that patch OK?  Who can approve it?  Jakub can't, he said on IRC.

gcc/
2010-03-31  Thomas Schwinge  <thomas@codesourcery.com>
	    Daniel Jacobowitz  <dan@codesourcery.com>

	* doc/tm.texi (DWARF2_UNWIND_INFO, TARGET_UNWIND_INFO): Improve.
	* dwarf2out.c (NEED_UNWIND_TABLES): Define.
	(dwarf2out_do_frame, dwarf2out_do_cfi_asm, dwarf2out_begin_prologue)
	(dwarf2out_frame_finish, dwarf2out_assembly_start): Use it.
	(dwarf2out_assembly_start): Correct logic for TARGET_UNWIND_INFO.
	* config/arm/arm.h (DWARF2_UNWIND_INFO): Remove definition.
	* config/arm/bpabi.h (DWARF2_UNWIND_INFO): Define to zero.

Index: gcc/doc/tm.texi
===================================================================
--- gcc/doc/tm.texi	(revision 157575)
+++ gcc/doc/tm.texi	(working copy)
@@ -8643,13 +8643,9 @@ that it does not contain any extraneous set bits i
 Define this macro to 0 if your target supports DWARF 2 frame unwind
 information, but it does not yet work with exception handling.
 Otherwise, if your target supports this information (if it defines
-@samp{INCOMING_RETURN_ADDR_RTX} and either @samp{UNALIGNED_INT_ASM_OP}
-or @samp{OBJECT_FORMAT_ELF}), GCC will provide a default definition of 1.
+@samp{INCOMING_RETURN_ADDR_RTX}) and @code{TARGET_UNWIND_INFO} is not defined,
+GCC will provide a default definition of 1.
 
-If @code{TARGET_UNWIND_INFO} is defined, the target specific unwinder
-will be used in all cases.  Defining this macro will enable the generation
-of DWARF 2 frame debugging information.
-
 If @code{TARGET_UNWIND_INFO} is not defined, and this macro is defined to 1,
 the DWARF 2 unwinder will be the default exception handling mechanism;
 otherwise, the @code{setjmp}/@code{longjmp}-based scheme will be used by
@@ -8659,6 +8655,9 @@ default.
 @defmac TARGET_UNWIND_INFO
 Define this macro if your target has ABI specified unwind tables.  Usually
 these will be output by @code{TARGET_UNWIND_EMIT}.
+
+Defining this macro will inhibit the default of generating DWARF 2 frame
+debugging information, see @code{DWARF2_UNWIND_INFO}.
 @end defmac
 
 @deftypevr {Target Hook} bool TARGET_UNWIND_TABLES_DEFAULT
Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c	(revision 157575)
+++ gcc/dwarf2out.c	(working copy)
@@ -124,6 +124,9 @@ int vms_file_stats_name (const char *, long long *
 # endif
 #endif
 
+#define NEED_UNWIND_TABLES \
+  (flag_unwind_tables || (flag_exceptions && !USING_SJLJ_EXCEPTIONS))
+
 /* Map register numbers held in the call frame info that gcc has
    collected using DWARF_FRAME_REGNUM to those that should be output in
    .debug_frame and .eh_frame.  */
@@ -147,9 +150,7 @@ dwarf2out_do_frame (void)
 	  || write_symbols == VMS_AND_DWARF2_DEBUG
 	  || DWARF2_FRAME_INFO || saved_do_cfi_asm
 #ifdef DWARF2_UNWIND_INFO
-	  || (DWARF2_UNWIND_INFO
-	      && (flag_unwind_tables
-		  || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)))
+	  || (DWARF2_UNWIND_INFO && NEED_UNWIND_TABLES)
 #endif
 	  );
 }
@@ -185,7 +186,7 @@ dwarf2out_do_cfi_asm (void)
 #ifdef TARGET_UNWIND_INFO
       return false;
 #else
-      if (USING_SJLJ_EXCEPTIONS || (!flag_unwind_tables && !flag_exceptions))
+      if (!NEED_UNWIND_TABLES)
 	return false;
 #endif
     }
@@ -3902,8 +3903,7 @@ dwarf2out_begin_prologue (unsigned int line ATTRIB
   /* ??? current_function_func_begin_label is also used by except.c
      for call-site information.  We must emit this label if it might
      be used.  */
-  if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
-      && ! dwarf2out_do_frame ())
+  if (!NEED_UNWIND_TABLES && !dwarf2out_do_frame ())
     return;
 #else
   if (! dwarf2out_do_frame ())
@@ -4063,7 +4063,7 @@ dwarf2out_frame_finish (void)
 
 #ifndef TARGET_UNWIND_INFO
   /* Output another copy for the unwinder.  */
-  if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
+  if (NEED_UNWIND_TABLES)
     output_call_frame_info (1);
 #endif
 }
@@ -20622,10 +20622,15 @@ dwarf2out_assembly_start (void)
 {
   if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE && dwarf2out_do_cfi_asm ())
     {
-#ifndef TARGET_UNWIND_INFO
-      if (USING_SJLJ_EXCEPTIONS || (!flag_unwind_tables && !flag_exceptions))
+#ifdef TARGET_UNWIND_INFO
+      /* We're only ever interested in .debug_frame.  */
+      fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
+#else
+      /* GAS defaults to emitting .eh_frame only, and .debug_frame is not
+	 wanted in case that the former one is present.  */
+      if (!NEED_UNWIND_TABLES)
+	fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
 #endif
-	fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
     }
 }
 
Index: gcc/config/arm/arm.h
===================================================================
--- gcc/config/arm/arm.h	(revision 157575)
+++ gcc/config/arm/arm.h	(working copy)
@@ -918,9 +918,6 @@ extern int arm_structure_size_boundary;
 #define MUST_USE_SJLJ_EXCEPTIONS 1
 #endif
 
-/* We can generate DWARF2 Unwind info, even though we don't use it.  */
-#define DWARF2_UNWIND_INFO 1
-
 /* Use r0 and r1 to pass exception handling information.  */
 #define EH_RETURN_DATA_REGNO(N) (((N) < 2) ? N : INVALID_REGNUM)
 
Index: gcc/config/arm/bpabi.h
===================================================================
--- gcc/config/arm/bpabi.h	(revision 157575)
+++ gcc/config/arm/bpabi.h	(working copy)
@@ -26,6 +26,7 @@
 #define TARGET_BPABI (TARGET_AAPCS_BASED)
 
 /* BPABI targets use EABI frame unwinding tables.  */
+#define DWARF2_UNWIND_INFO 0
 #define TARGET_UNWIND_INFO 1
 
 /* Section 4.1 of the AAPCS requires the use of VFP format.  */


Regards,
 Thomas

Attachment: pgp00000.pgp
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]