[gcc r17-3243] Darwin: Amend linker-visibility of strings [PR126723].

Iain D Sandoe via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:1c03a15e0979c76a33276cbf498379084896cd06

commit r17-3243-g1c03a15e0979c76a33276cbf498379084896cd06
Author: Iain Sandoe <[email protected]>
Date:   Tue Aug 11 11:58:18 2026 +0100

    Darwin: Amend linker-visibility of strings [PR126723].
    
    There seems to be quite some variability in the cases that clang makes
    string constant labels linker-visible, however the most conservative
    case is "all of them" which appears to be the strategy for aarch64.
    We dadopt this here, although there is some slight loss of efficiency
    for x86_64.
    
            PR target/126723
    
    gcc/ChangeLog:
    
            * config/darwin.cc (darwin_encode_section_info): Make all
            string constant labels linker-visible.  Likewise const
            section anchors.
    
    Signed-off-by: Iain Sandoe <[email protected]>

Diff:
---
 gcc/config/darwin.cc | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/gcc/config/darwin.cc b/gcc/config/darwin.cc
index 5812d61765b9..2f8232989631 100644
--- a/gcc/config/darwin.cc
+++ b/gcc/config/darwin.cc
@@ -1314,18 +1314,15 @@ darwin_encode_section_info (tree decl, rtx rtl, int first)
       gcc_checking_assert (strncmp ("*lC", name, 3) == 0);
 
       char *buf;
+      /* Some versions of clang make all string constants linker-visible,
+	 independent of their final section, follow this.  */
       if (is_str)
-	{
-	  bool for_asan = (flag_sanitize & SANITIZE_ADDRESS)
-			   && asan_protect_global (const_cast<tree> (decl));
-	  /* When we are generating code for sanitized strings, the string
-	     internal symbols are made visible in the object.  */
-	  buf = xasprintf ("*%c.str.%s", for_asan ? 'l' : 'L', &name[3]);
-	}
+	buf = xasprintf ("*l.str.%s", &name[3]);
       else
 	/* Lets identify anchored constants with a different prefix, for the
-	   sake of inspection only.  */
-	buf = xasprintf ("*LaC%s", &name[3]);
+	   sake of inspection only.  Assume these need to co-exist with weak
+	   constant defs and so need to be linker-visible.  */
+	buf = xasprintf ("*laC%s", &name[3]);
       if (sym_decl)
 	DECL_NAME (sym_decl) = get_identifier (buf);
       XSTR (sym_ref, 0) = ggc_strdup (buf);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.