[PATCH] Fix P81033 for FDEs in partitioned code.

Iain Sandoe iain@sandoe.co.uk
Tue Aug 14 11:20:00 GMT 2018


Hi,

A more detailed explanation is in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81033#c37

When function sub-sections are enabled, Darwin’s assembler needs the FDE local start
label for each sub-section to follow a linker-visible one so that the FDE will be correctly
associated with the code of the subsection.

The current code in final.c emits a linker-visible symbol, as needed by several targets.
However the local label used to define the FDE start precedes the linker-visible one
which, for Darwin causes it (the FDE start) to be associated with the previous linker-
visible symbol (or the section start if there isn’t one).  This applies regardless of the 
actual address of the label, for toolchain assemblers that have strict interpretation of
the Darwin sub-sections-via-symbols ABI.

The patch adds a new local label (analogous to the "LFBn” emitted for the regular
function starts) just after the linker-visible label emitted after switching text section.
The FDE second entry is made to point to this instead of the LcoldStartn one.  This
should be a no-op for targets using .cfi_ and for targets without sub-sections-via-symbols.

Bootstrapped on x86_64 and i686 linux and on a number of Darwin platforms (from 
i686-darwin9 to x86_64-darwin17).

OK for trunk?
open branches? (although it's a regression on 8, it’s a latent wrong-code on all branches)

thanks
Iain

2018-08-14  Iain Sandoe  <iain@sandoe.co.uk>

gcc:

        PR target/81033
	* dwarf2out.c (FUNC_SECOND_SECT_LABEL): New.
	(dwarf2out_switch_text_section): Generate subsection label and
	assign it to the FDE second section start.
	* final.c (final_scan_insn_1): Emit second section label when
	required.
---
 gcc/dwarf2out.c | 11 +++++++++--
 gcc/final.c     |  3 +++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 9ed473088e..c7557eb51d 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -297,6 +297,10 @@ static unsigned int rnglist_idx;
 #define FUNC_BEGIN_LABEL	"LFB"
 #endif
 
+#ifndef FUNC_SECOND_SECT_LABEL
+#define FUNC_SECOND_SECT_LABEL	"LFSB"
+#endif
+
 #ifndef FUNC_END_LABEL
 #define FUNC_END_LABEL		"LFE"
 #endif
@@ -1212,21 +1216,24 @@ static void set_cur_line_info_table (section *);
 void
 dwarf2out_switch_text_section (void)
 {
+  char label[MAX_ARTIFICIAL_LABEL_BYTES];
   section *sect;
   dw_fde_ref fde = cfun->fde;
 
   gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
 
+  ASM_GENERATE_INTERNAL_LABEL (label, FUNC_SECOND_SECT_LABEL,
+			       current_function_funcdef_no);
+
+  fde->dw_fde_second_begin = xstrdup (label);
   if (!in_cold_section_p)
     {
       fde->dw_fde_end = crtl->subsections.cold_section_end_label;
-      fde->dw_fde_second_begin = crtl->subsections.hot_section_label;
       fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
     }
   else
     {
       fde->dw_fde_end = crtl->subsections.hot_section_end_label;
-      fde->dw_fde_second_begin = crtl->subsections.cold_section_label;
       fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
     }
   have_multiple_function_sections = true;
diff --git a/gcc/final.c b/gcc/final.c
index 842e5e067d..6943c073d9 100644
--- a/gcc/final.c
+++ b/gcc/final.c
@@ -2232,6 +2232,9 @@ final_scan_insn_1 (rtx_insn *insn, FILE *file, int optimize_p ATTRIBUTE_UNUSED,
 	      ASM_OUTPUT_LABEL (asm_out_file,
 				IDENTIFIER_POINTER (cold_function_name));
 #endif
+	      if (dwarf2out_do_frame ()
+	          && cfun->fde->dw_fde_second_begin != NULL)
+		ASM_OUTPUT_LABEL (asm_out_file, cfun->fde->dw_fde_second_begin);
 	    }
 	  break;
 
-- 
2.17.1



More information about the Gcc-patches mailing list