From c2836614aa4309f2e5077de83eabedf5e867290d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= <clement.chigot@atos.net>
Date: Wed, 2 Dec 2020 18:19:35 +0100
Subject: [PATCH] gcc: handle double quotes in symbol name during stabstrings
 generation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

With the new gccgo mangling scheme, a type name might now have a double
quotes in it. The current code doesn't escape these double quotes when
writing .stabs pseudo-opcode in the assembly file.

Changelog:
2020-12-02  Clément Chigot  <clement.chigot@atosnet>

	* dbxout.c (dbxout_symbol_name): Handle double quotes.
---
 gcc/dbxout.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/gcc/dbxout.c b/gcc/dbxout.c
index eaee2f19ce0..d1ffd7f36d2 100644
--- a/gcc/dbxout.c
+++ b/gcc/dbxout.c
@@ -3274,7 +3274,24 @@ dbxout_symbol_name (tree decl, const char *suffix, int letter)
        added by ASM_FORMAT_PRIVATE_NAME.  */
     name = DECL_NAME (decl);
 
-  if (name)
+  if (name && strchr(IDENTIFIER_POINTER(name), '"'))
+    {
+      /* Make sure double quote characters are correctly handled.  */
+      const char *str = IDENTIFIER_POINTER(name);
+      char c;
+      while ((c = *(str)++) != 0)
+	{
+	  if (c == '\"')
+#ifdef XCOFF_DEBUGGING_INFO
+	    stabstr_C ('\"');
+#else
+	    stabstr_C ('\\');
+#endif
+
+	  stabstr_C (c);
+	}
+    }
+  else if (name)
     stabstr_I (name);
   else
     stabstr_S ("(anon)");
-- 
2.25.0

