bd07c2f
From cebc89b9328eab994f6b0314c263f94e7949a553 Mon Sep 17 00:00:00 2001
bd07c2f
From: Alan Modra <amodra@gmail.com>
bd07c2f
Date: Mon, 21 Feb 2022 10:58:57 +1030
bd07c2f
Subject: [PATCH] binutils 2.38 vs. ppc32 linux kernel
bd07c2f
bd07c2f
Commit b25f942e18d6 made .machine more strict.  Weaken it again.
bd07c2f
bd07c2f
	* config/tc-ppc.c (ppc_machine): Treat an early .machine specially,
bd07c2f
	keeping sticky options to work around gcc bugs.
bd07c2f
---
bd07c2f
 gas/config/tc-ppc.c | 25 ++++++++++++++++++++++++-
bd07c2f
 1 file changed, 24 insertions(+), 1 deletion(-)
bd07c2f
bd07c2f
diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c
bd07c2f
index 054f9c72161..89bc7d3f9b9 100644
bd07c2f
--- a/gas/config/tc-ppc.c
bd07c2f
+++ b/gas/config/tc-ppc.c
bd07c2f
@@ -5965,7 +5965,30 @@ ppc_machine (int ignore ATTRIBUTE_UNUSED)
bd07c2f
 	     options do not count as a new machine, instead they add
bd07c2f
 	     to currently selected opcodes.  */
bd07c2f
 	  ppc_cpu_t machine_sticky = 0;
bd07c2f
-	  new_cpu = ppc_parse_cpu (ppc_cpu, &machine_sticky, cpu_string);
bd07c2f
+	  /* Unfortunately, some versions of gcc emit a .machine
bd07c2f
+	     directive very near the start of the compiler's assembly
bd07c2f
+	     output file.  This is bad because it overrides user -Wa
bd07c2f
+	     cpu selection.  Worse, there are versions of gcc that
bd07c2f
+	     emit the *wrong* cpu, not even respecting the -mcpu given
bd07c2f
+	     to gcc.  See gcc pr101393.  And to compound the problem,
bd07c2f
+	     as of 20220222 gcc doesn't pass the correct cpu option to
bd07c2f
+	     gas on the command line.  See gcc pr59828.  Hack around
bd07c2f
+	     this by keeping sticky options for an early .machine.  */
bd07c2f
+	  asection *sec;
bd07c2f
+	  for (sec = stdoutput->sections; sec != NULL; sec = sec->next)
bd07c2f
+	    {
bd07c2f
+	      segment_info_type *info = seg_info (sec);
bd07c2f
+	      /* Are the frags for this section perturbed from their
bd07c2f
+		 initial state?  Even .align will count here.  */
bd07c2f
+	      if (info != NULL
bd07c2f
+		  && (info->frchainP->frch_root != info->frchainP->frch_last
bd07c2f
+		      || info->frchainP->frch_root->fr_type != rs_fill
bd07c2f
+		      || info->frchainP->frch_root->fr_fix != 0))
bd07c2f
+		break;
bd07c2f
+	    }
bd07c2f
+	  new_cpu = ppc_parse_cpu (ppc_cpu,
bd07c2f
+				   sec == NULL ? &sticky : &machine_sticky,
bd07c2f
+				   cpu_string);
bd07c2f
 	  if (new_cpu != 0)
bd07c2f
 	    ppc_cpu = new_cpu;
bd07c2f
 	  else
bd07c2f
-- 
bd07c2f
2.37.1
bd07c2f