[RFC,6/9] gas: dw2gencfi: ignore all .cfi_* directives with --scfi=all

Message ID 20230920230401.1739139-7-indu.bhagat@oracle.com
State New
Headers
Series SCFI implementation in GNU assembler |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Testing passed

Commit Message

Indu Bhagat Sept. 20, 2023, 11:03 p.m. UTC
  As we add support for --scfi=inline, this commit will need to evolve and
more changes may be necessary.  More specifically, we will need to
explictly check the value of the enumerator flag_synth_cfi.

gas/
        * dw2gencfi.c (dot_cfi): Ignore processing when synthesizing
	CFI.
        (dot_cfi_escape): Likewise.
        (dot_cfi_personality): Likewise.
        (dot_cfi_lsda): Likewise.
        (dot_cfi_val_encoded_addr): Likewise.
        (dot_cfi_label): Likewise.
        (dot_cfi_sections): Likewise.
        (dot_cfi_startproc): Likewise.
        (dot_cfi_endproc): Likewise.
        (dot_cfi_personality_id): Likewise.
        (dot_cfi_fde_data): Likewise.
        (dot_cfi_inline_lsda): Likewise.
---
 gas/dw2gencfi.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)
  

Comments

Nick Clifton Sept. 28, 2023, 2:10 p.m. UTC | #1
Hi Indu,

> @@ -806,6 +806,12 @@ dot_cfi (int arg)
>     offsetT offset;
>     unsigned reg1, reg2;
>   
> +  if (flag_synth_cfi)
> +    {
> +      ignore_rest_of_line ();
> +      return;
> +    }
> +

I am concerned about this behaviour.  I understand that mixing
synthetic CFI statements and real ones would be a bad idea, but
I think that silently ignoring the real ones is a mistake.  At
the very least you ought to generate a warning message letting
the user know that their cfi instructions are being ignored.

Cheers
   Nick
  
Indu Bhagat Sept. 30, 2023, 6:20 a.m. UTC | #2
On 9/28/23 07:10, Nick Clifton wrote:
> Hi Indu,
> 
>> @@ -806,6 +806,12 @@ dot_cfi (int arg)
>>     offsetT offset;
>>     unsigned reg1, reg2;
>> +  if (flag_synth_cfi)
>> +    {
>> +      ignore_rest_of_line ();
>> +      return;
>> +    }
>> +
> 
> I am concerned about this behaviour.  I understand that mixing
> synthetic CFI statements and real ones would be a bad idea, but
> I think that silently ignoring the real ones is a mistake.  At
> the very least you ought to generate a warning message letting
> the user know that their cfi instructions are being ignored.
> 

Yes, we could trigger one warning per function, when we see, say a 
.cfi_startproc, for a asm function for which user specified --scfi=all:

   "Warning: --scfi=all ignores sythesizable CFI directives for function 
'foo'"

That said, it looks like for --scfi=all, we will need to honor at least 
the following from the user:
   - .cfi_sections
   - .cfi_label
   - .cfi_signal_frame

Thanks
  

Patch

diff --git a/gas/dw2gencfi.c b/gas/dw2gencfi.c
index cdef8d09978..2a02752b734 100644
--- a/gas/dw2gencfi.c
+++ b/gas/dw2gencfi.c
@@ -806,6 +806,12 @@  dot_cfi (int arg)
   offsetT offset;
   unsigned reg1, reg2;
 
+  if (flag_synth_cfi)
+    {
+      ignore_rest_of_line ();
+      return;
+    }
+
   if (frchain_now->frch_cfi_data == NULL)
     {
       as_bad (_("CFI instruction used without previous .cfi_startproc"));
@@ -936,6 +942,12 @@  dot_cfi_escape (int ignored ATTRIBUTE_UNUSED)
   struct cfi_escape_data *head, **tail, *e;
   struct cfi_insn_data *insn;
 
+  if (flag_synth_cfi)
+    {
+      ignore_rest_of_line ();
+      return;
+    }
+
   if (frchain_now->frch_cfi_data == NULL)
     {
       as_bad (_("CFI instruction used without previous .cfi_startproc"));
@@ -974,6 +986,12 @@  dot_cfi_personality (int ignored ATTRIBUTE_UNUSED)
   struct fde_entry *fde;
   offsetT encoding;
 
+  if (flag_synth_cfi)
+    {
+      ignore_rest_of_line ();
+      return;
+    }
+
   if (frchain_now->frch_cfi_data == NULL)
     {
       as_bad (_("CFI instruction used without previous .cfi_startproc"));
@@ -1045,6 +1063,12 @@  dot_cfi_lsda (int ignored ATTRIBUTE_UNUSED)
   struct fde_entry *fde;
   offsetT encoding;
 
+  if (flag_synth_cfi)
+    {
+      ignore_rest_of_line ();
+      return;
+    }
+
   if (frchain_now->frch_cfi_data == NULL)
     {
       as_bad (_("CFI instruction used without previous .cfi_startproc"));
@@ -1118,6 +1142,12 @@  dot_cfi_val_encoded_addr (int ignored ATTRIBUTE_UNUSED)
   struct cfi_insn_data *insn_ptr;
   offsetT encoding;
 
+  if (flag_synth_cfi)
+    {
+      ignore_rest_of_line ();
+      return;
+    }
+
   if (frchain_now->frch_cfi_data == NULL)
     {
       as_bad (_("CFI instruction used without previous .cfi_startproc"));
@@ -1183,6 +1213,12 @@  dot_cfi_label (int ignored ATTRIBUTE_UNUSED)
 {
   char *name;
 
+  if (flag_synth_cfi)
+    {
+      ignore_rest_of_line ();
+      return;
+    }
+
   if (frchain_now->frch_cfi_data == NULL)
     {
       as_bad (_("CFI instruction used without previous .cfi_startproc"));
@@ -1211,6 +1247,12 @@  dot_cfi_sections (int ignored ATTRIBUTE_UNUSED)
 {
   int sections = 0;
 
+  if (flag_synth_cfi)
+    {
+      ignore_rest_of_line ();
+      return;
+    }
+
   SKIP_WHITESPACE ();
   if (is_name_beginner (*input_line_pointer) || *input_line_pointer == '"')
     while (1)
@@ -1278,6 +1320,12 @@  dot_cfi_startproc (int ignored ATTRIBUTE_UNUSED)
 {
   int simple = 0;
 
+  if (flag_synth_cfi)
+    {
+      ignore_rest_of_line ();
+      return;
+    }
+
   if (frchain_now->frch_cfi_data != NULL)
     {
       as_bad (_("previous CFI entry not closed (missing .cfi_endproc)"));
@@ -1318,6 +1366,12 @@  dot_cfi_startproc (int ignored ATTRIBUTE_UNUSED)
 static void
 dot_cfi_endproc (int ignored ATTRIBUTE_UNUSED)
 {
+  if (flag_synth_cfi)
+    {
+      ignore_rest_of_line ();
+      return;
+    }
+
   if (frchain_now->frch_cfi_data == NULL)
     {
       as_bad (_(".cfi_endproc without corresponding .cfi_startproc"));
@@ -1382,6 +1436,12 @@  dot_cfi_personality_id (int ignored ATTRIBUTE_UNUSED)
 {
   struct fde_entry *fde;
 
+  if (flag_synth_cfi)
+    {
+      ignore_rest_of_line ();
+      return;
+    }
+
   if (frchain_now->frch_cfi_data == NULL)
     {
       as_bad (_("CFI instruction used without previous .cfi_startproc"));
@@ -1403,6 +1463,12 @@  dot_cfi_personality_id (int ignored ATTRIBUTE_UNUSED)
 static void
 dot_cfi_fde_data (int ignored ATTRIBUTE_UNUSED)
 {
+  if (flag_synth_cfi)
+    {
+      ignore_rest_of_line ();
+      return;
+    }
+
   if (frchain_now->frch_cfi_data == NULL)
     {
       as_bad (_(".cfi_fde_data without corresponding .cfi_startproc"));
@@ -1511,6 +1577,12 @@  dot_cfi_inline_lsda (int ignored ATTRIBUTE_UNUSED)
   int align;
   long max_alignment = 28;
 
+  if (flag_synth_cfi)
+    {
+      ignore_rest_of_line ();
+      return;
+    }
+
   if (!last_fde)
     {
       as_bad (_("unexpected .cfi_inline_lsda"));