1From ed9b2e40ebffec835d63473367da8dd8f80d7d5b Mon Sep 17 00:00:00 2001
2From: Alan Modra <amodra@gmail.com>
3Date: Mon, 21 Feb 2022 10:58:57 +1030
4Subject: [PATCH] binutils 2.38 vs. ppc32 linux kernel
5
6Commit b25f942e18d6 made .machine more strict.  Weaken it again.
7
8	* config/tc-ppc.c (ppc_machine): Treat an early .machine specially,
9	keeping sticky options to work around gcc bugs.
10
11(cherry picked from commit cebc89b9328eab994f6b0314c263f94e7949a553)
12Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
13---
14 gas/config/tc-ppc.c | 25 ++++++++++++++++++++++++-
15 1 file changed, 24 insertions(+), 1 deletion(-)
16
17diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c
18index 054f9c72161..89bc7d3f9b9 100644
19--- a/gas/config/tc-ppc.c
20+++ b/gas/config/tc-ppc.c
21@@ -5965,7 +5965,30 @@ ppc_machine (int ignore ATTRIBUTE_UNUSED)
22 	     options do not count as a new machine, instead they add
23 	     to currently selected opcodes.  */
24 	  ppc_cpu_t machine_sticky = 0;
25-	  new_cpu = ppc_parse_cpu (ppc_cpu, &machine_sticky, cpu_string);
26+	  /* Unfortunately, some versions of gcc emit a .machine
27+	     directive very near the start of the compiler's assembly
28+	     output file.  This is bad because it overrides user -Wa
29+	     cpu selection.  Worse, there are versions of gcc that
30+	     emit the *wrong* cpu, not even respecting the -mcpu given
31+	     to gcc.  See gcc pr101393.  And to compound the problem,
32+	     as of 20220222 gcc doesn't pass the correct cpu option to
33+	     gas on the command line.  See gcc pr59828.  Hack around
34+	     this by keeping sticky options for an early .machine.  */
35+	  asection *sec;
36+	  for (sec = stdoutput->sections; sec != NULL; sec = sec->next)
37+	    {
38+	      segment_info_type *info = seg_info (sec);
39+	      /* Are the frags for this section perturbed from their
40+		 initial state?  Even .align will count here.  */
41+	      if (info != NULL
42+		  && (info->frchainP->frch_root != info->frchainP->frch_last
43+		      || info->frchainP->frch_root->fr_type != rs_fill
44+		      || info->frchainP->frch_root->fr_fix != 0))
45+		break;
46+	    }
47+	  new_cpu = ppc_parse_cpu (ppc_cpu,
48+				   sec == NULL ? &sticky : &machine_sticky,
49+				   cpu_string);
50 	  if (new_cpu != 0)
51 	    ppc_cpu = new_cpu;
52 	  else
53--
542.30.2
55
56