[05/11] arm: redirect fp constant data directives through a wrapper

Message ID 20240604115628.784729-6-rearnsha@arm.com
State Committed
Headers
Series arm: Remove FPA support from gas/binutils |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Richard Earnshaw June 4, 2024, 11:56 a.m. UTC
  Assembler directives such as .float, or .double are handled by generic
code, but on Arm, their output can vary depeding on the type of FPU
begin targetted.  When we remove FPA support we don't want to silently
generate different code for processors that previously defaulted to
the FPA, so redirect these directives through a wrapper function that
checks the FPU is enabled; we use the legacy -mno-fpu in the test to
catch this.

Also fix a few tests so that they won't start to fail on targets (eg
arm-wince-pe) where there is no default format for the FPU and we pick
this from the default processor type.
---
 gas/config/tc-arm.c                           | 25 +++++++++++++++----
 gas/testsuite/gas/all/gas.exp                 |  2 ++
 gas/testsuite/gas/arm/bfloat16-directive-be.d |  2 +-
 gas/testsuite/gas/arm/bfloat16-directive-le.d |  2 +-
 gas/testsuite/gas/arm/float16-bad.d           |  1 +
 gas/testsuite/gas/arm/float16-be.d            |  2 +-
 .../gas/arm/float16-format-opt-bad.d          |  2 +-
 gas/testsuite/gas/arm/float16-le.d            |  2 +-
 gas/testsuite/gas/arm/fp-directive-bad.d      |  4 +++
 gas/testsuite/gas/arm/fp-directive-bad.l      |  7 ++++++
 gas/testsuite/gas/arm/fp-directive.d          |  9 +++++++
 gas/testsuite/gas/arm/fp-directive.s          |  7 ++++++
 12 files changed, 55 insertions(+), 10 deletions(-)
 create mode 100644 gas/testsuite/gas/arm/fp-directive-bad.d
 create mode 100644 gas/testsuite/gas/arm/fp-directive-bad.l
 create mode 100644 gas/testsuite/gas/arm/fp-directive.d
 create mode 100644 gas/testsuite/gas/arm/fp-directive.s
  

Patch

diff --git a/gas/config/tc-arm.c b/gas/config/tc-arm.c
index 9294619e1a4..1ba7bb31ac5 100644
--- a/gas/config/tc-arm.c
+++ b/gas/config/tc-arm.c
@@ -5148,6 +5148,14 @@  set_fp16_format (int dummy ATTRIBUTE_UNUSED)
   ignore_rest_of_line ();
 }
 
+static void s_arm_float_cons (int float_type)
+{
+  /* We still parse the directive on error, so that any syntactic issues
+     are picked up.  */
+  if (ARM_FEATURE_ZERO (selected_fpu))
+    as_bad (_("the floating-point format has not been set (or has been disabled)"));
+  float_cons (float_type);
+}
 /* This table describes all the machine specific pseudo-ops the assembler
    has to support.  The fields are:
      pseudo-op name without dot
@@ -5212,10 +5220,17 @@  const pseudo_typeS md_pseudo_table[] =
   { "loc",  dwarf2_directive_loc,  0 },
   { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
 #endif
-  { "extend",	   float_cons, 'x' },
-  { "ldouble",	   float_cons, 'x' },
-  { "packed",	   float_cons, 'p' },
-  { "bfloat16",	   float_cons, 'b' },
+  /* Override the default float_cons handling so that we can validate
+     the FPU setting.  */
+  { "float",	   s_arm_float_cons, 'f' },
+  { "single",	   s_arm_float_cons, 'f' },
+  { "double",	   s_arm_float_cons, 'd' },
+  { "dc.s",	   s_arm_float_cons, 'f' },
+  { "dc.d",	   s_arm_float_cons, 'd' },
+  { "extend",	   s_arm_float_cons, 'x' },
+  { "ldouble",	   s_arm_float_cons, 'x' },
+  { "packed",	   s_arm_float_cons, 'p' },
+  { "bfloat16",	   s_arm_float_cons, 'b' },
 #ifdef TE_PE
   {"secrel32", pe_directive_secrel, 0},
 #endif
@@ -5226,7 +5241,7 @@  const pseudo_typeS md_pseudo_table[] =
   {"asmfunc",      s_ccs_asmfunc,    0},
   {"endasmfunc",   s_ccs_endasmfunc, 0},
 
-  {"float16", float_cons, 'h' },
+  {"float16", s_arm_float_cons, 'h' },
   {"float16_format", set_fp16_format, 0 },
 
   { 0, 0, 0 }
diff --git a/gas/testsuite/gas/all/gas.exp b/gas/testsuite/gas/all/gas.exp
index b9ff43997cb..af461b1988d 100644
--- a/gas/testsuite/gas/all/gas.exp
+++ b/gas/testsuite/gas/all/gas.exp
@@ -47,6 +47,8 @@  if { ![istarget cris-*-*] && ![istarget crisv32-*-*]
      && ![istarget z80-*-*] } then {
     if { [istarget tic4x-*-*] } then {
 	set as_opt ""
+    } elseif { [istarget arm*-*-pe ] } then {
+	set as_opt "--defsym hasnan=1 -mfpu=softvfp"
     } else {
 	set as_opt "--defsym hasnan=1"
     }
diff --git a/gas/testsuite/gas/arm/bfloat16-directive-be.d b/gas/testsuite/gas/arm/bfloat16-directive-be.d
index 8862f8302f7..44eadb33194 100644
--- a/gas/testsuite/gas/arm/bfloat16-directive-be.d
+++ b/gas/testsuite/gas/arm/bfloat16-directive-be.d
@@ -1,7 +1,7 @@ 
 # name: Big endian bfloat16 literal directives
 # source: bfloat16-directive.s
 # objdump: -s --section=.data
-# as: -mbig-endian
+# as: -mbig-endian -mfpu=softvfp
 
 .*: +file format .*
 
diff --git a/gas/testsuite/gas/arm/bfloat16-directive-le.d b/gas/testsuite/gas/arm/bfloat16-directive-le.d
index da94b6b254c..c595d8b065a 100644
--- a/gas/testsuite/gas/arm/bfloat16-directive-le.d
+++ b/gas/testsuite/gas/arm/bfloat16-directive-le.d
@@ -1,7 +1,7 @@ 
 # name: Little endian bfloat16 literal directives
 # source: bfloat16-directive.s
 # objdump: -s --section=.data
-# as: -mlittle-endian
+# as: -mlittle-endian -mfpu=softvfp
 
 .*: +file format .*
 
diff --git a/gas/testsuite/gas/arm/float16-bad.d b/gas/testsuite/gas/arm/float16-bad.d
index 8eac0af5cbb..604bb20adaf 100644
--- a/gas/testsuite/gas/arm/float16-bad.d
+++ b/gas/testsuite/gas/arm/float16-bad.d
@@ -1,3 +1,4 @@ 
 # name: Invalid float16 literals (IEEE 754 & Alternative)
 # source: float16-bad.s
 # error_output: float16-bad.l
+# as: -mfpu=softvfp
diff --git a/gas/testsuite/gas/arm/float16-be.d b/gas/testsuite/gas/arm/float16-be.d
index e31d9fbf432..b63d6cd49d5 100644
--- a/gas/testsuite/gas/arm/float16-be.d
+++ b/gas/testsuite/gas/arm/float16-be.d
@@ -1,7 +1,7 @@ 
 # name: Big endian float16 literals (IEEE 754 & Alternative)
 # source: float16.s
 # objdump: -s --section=.data
-# as: -mbig-endian
+# as: -mbig-endian -mfpu=softvfp
 
 .*: +file format .*arm.*
 
diff --git a/gas/testsuite/gas/arm/float16-format-opt-bad.d b/gas/testsuite/gas/arm/float16-format-opt-bad.d
index 861125800da..af8cca48956 100644
--- a/gas/testsuite/gas/arm/float16-format-opt-bad.d
+++ b/gas/testsuite/gas/arm/float16-format-opt-bad.d
@@ -1,4 +1,4 @@ 
 # name: Invalid combination of command line arguments and directives
 # source: float16.s
 # error_output: float16-format-opt-bad.l
-# as: -mfp16-format=ieee
+# as: -mfpu=softvfp -mfp16-format=ieee
diff --git a/gas/testsuite/gas/arm/float16-le.d b/gas/testsuite/gas/arm/float16-le.d
index c1fe7c20dc6..abbf09202be 100644
--- a/gas/testsuite/gas/arm/float16-le.d
+++ b/gas/testsuite/gas/arm/float16-le.d
@@ -1,7 +1,7 @@ 
 # name: Little endian float16 literals (IEEE 754 & Alternative)
 # source: float16.s
 # objdump: -s --section=.data
-# as: -mlittle-endian
+# as: -mlittle-endian -mfpu=softvfp
 
 .*: +file format .*arm.*
 
diff --git a/gas/testsuite/gas/arm/fp-directive-bad.d b/gas/testsuite/gas/arm/fp-directive-bad.d
new file mode 100644
index 00000000000..dfa01e6829c
--- /dev/null
+++ b/gas/testsuite/gas/arm/fp-directive-bad.d
@@ -0,0 +1,4 @@ 
+#name: floating-point directives disabled
+#source: fp-directive.s
+#as: -mno-warn-deprecated -mno-fpu
+#error_output: fp-directive-bad.l
\ No newline at end of file
diff --git a/gas/testsuite/gas/arm/fp-directive-bad.l b/gas/testsuite/gas/arm/fp-directive-bad.l
new file mode 100644
index 00000000000..263cc9e6de4
--- /dev/null
+++ b/gas/testsuite/gas/arm/fp-directive-bad.l
@@ -0,0 +1,7 @@ 
+[^:]*: Assembler messages:
+[^:]*:2: Error: the floating-point format has not been set \(or has been disabled\)
+[^:]*:3: Error: the floating-point format has not been set \(or has been disabled\)
+[^:]*:4: Error: the floating-point format has not been set \(or has been disabled\)
+[^:]*:5: Error: the floating-point format has not been set \(or has been disabled\)
+[^:]*:6: Error: the floating-point format has not been set \(or has been disabled\)
+[^:]*:7: Error: the floating-point format has not been set \(or has been disabled\)
diff --git a/gas/testsuite/gas/arm/fp-directive.d b/gas/testsuite/gas/arm/fp-directive.d
new file mode 100644
index 00000000000..46ff9e9c571
--- /dev/null
+++ b/gas/testsuite/gas/arm/fp-directive.d
@@ -0,0 +1,9 @@ 
+#name: floating-point directives
+#objdump: -s --section=.data
+#as: -mfpu=softvfp
+
+.*: +file format .*arm.*
+
+Contents of section \.data:
+ 0000 .*
+ 0010 .*
diff --git a/gas/testsuite/gas/arm/fp-directive.s b/gas/testsuite/gas/arm/fp-directive.s
new file mode 100644
index 00000000000..c6fc22760f7
--- /dev/null
+++ b/gas/testsuite/gas/arm/fp-directive.s
@@ -0,0 +1,7 @@ 
+	.data
+	.float 1.0
+	.double 2.0
+	.single 3.0
+	.dc.s 5.3
+	.dc.d 6
+	.float16 4.0