This fixes a few hundreds of compilation/linking FAILs (similar to PR69506),
where the GCN/LLVM 'ld' reported:

    ld: error: relocation R_AMDGPU_REL32_LO cannot be used against symbol 
'_ZGTtnam'; recompile with -fPIC
    >>> defined in 
[...]/amdgcn-amdhsa/./libstdc++-v3/src/.libs/libstdc++.a(cow-stdexcept.o)
    >>> referenced by cow-stdexcept.cc:259 
([...]/libstdc++-v3/src/c++11/cow-stdexcept.cc:259)
    >>>               
cow-stdexcept.o:(_txnal_cow_string_C1_for_exceptions(void*, char const*, 
void*)) in archive [...]/amdgcn-amdhsa/./libstdc++-v3/src/.libs/libstdc++.a

    ld: error: relocation R_AMDGPU_REL32_HI cannot be used against symbol 
'_ZGTtnam'; recompile with -fPIC
    >>> defined in 
[...]/amdgcn-amdhsa/./libstdc++-v3/src/.libs/libstdc++.a(cow-stdexcept.o)
    >>> referenced by cow-stdexcept.cc:259 
([...]/source-gcc/libstdc++-v3/src/c++11/cow-stdexcept.cc:259)
    >>>               
cow-stdexcept.o:(_txnal_cow_string_C1_for_exceptions(void*, char const*, 
void*)) in archive [...]/amdgcn-amdhsa/./libstdc++-v3/src/.libs/libstdc++.a

    [...]

..., which is:

    $ c++filt _ZGTtnam
    transaction clone for operator new[](unsigned long)

..., and similarly for other libitm symbols.

However, the affected test cases, if applicable, then run into execution test
FAILs, due to PR119369
"GCN: weak undefined symbols -> execution test FAIL, 
'HSA_STATUS_ERROR_VARIABLE_UNDEFINED'".

        PR target/119369
        libstdc++-v3/
        * config/cpu/gcn/cpu_defines.h: New.
        * configure.host [GCN] (cpu_defines_dir): Point to it.
---
 libstdc++-v3/config/cpu/gcn/cpu_defines.h | 55 +++++++++++++++++++++++
 libstdc++-v3/configure.host               |  3 ++
 2 files changed, 58 insertions(+)
 create mode 100644 libstdc++-v3/config/cpu/gcn/cpu_defines.h

diff --git a/libstdc++-v3/config/cpu/gcn/cpu_defines.h 
b/libstdc++-v3/config/cpu/gcn/cpu_defines.h
new file mode 100644
index 000000000000..028bfb0ccff1
--- /dev/null
+++ b/libstdc++-v3/config/cpu/gcn/cpu_defines.h
@@ -0,0 +1,55 @@
+// Specific definitions for GCN platforms  -*- C++ -*-
+
+// Copyright (C) 2025 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file bits/cpu_defines.h
+ *  This is an internal header file, included by other library headers.
+ *  Do not attempt to use it directly. @headername{iosfwd}
+ */
+
+#ifndef _GLIBCXX_CPU_DEFINES
+#define _GLIBCXX_CPU_DEFINES 1
+
+/* GCN appears to run into issues similar to PR69506:
+
+       ld: error: relocation R_AMDGPU_REL32_LO cannot be used against symbol 
'_ZGTtnam'; recompile with -fPIC
+       >>> defined in 
[...]/amdgcn-amdhsa/./libstdc++-v3/src/.libs/libstdc++.a(cow-stdexcept.o)
+       >>> referenced by cow-stdexcept.cc:259 
([...]/libstdc++-v3/src/c++11/cow-stdexcept.cc:259)
+       >>>               
cow-stdexcept.o:(_txnal_cow_string_C1_for_exceptions(void*, char const*, 
void*)) in archive [...]/amdgcn-amdhsa/./libstdc++-v3/src/.libs/libstdc++.a
+       
+       ld: error: relocation R_AMDGPU_REL32_HI cannot be used against symbol 
'_ZGTtnam'; recompile with -fPIC
+       >>> defined in 
[...]/amdgcn-amdhsa/./libstdc++-v3/src/.libs/libstdc++.a(cow-stdexcept.o)
+       >>> referenced by cow-stdexcept.cc:259 
([...]/source-gcc/libstdc++-v3/src/c++11/cow-stdexcept.cc:259)
+       >>>               
cow-stdexcept.o:(_txnal_cow_string_C1_for_exceptions(void*, char const*, 
void*)) in archive [...]/amdgcn-amdhsa/./libstdc++-v3/src/.libs/libstdc++.a
+       
+       [...]
+
+   ..., which is:
+
+       $ c++filt _ZGTtnam
+       transaction clone for operator new[](unsigned long)
+
+   ..., and similarly for other libitm symbols.  See PR119369.  */
+#define _GLIBCXX_USE_WEAK_REF 0
+
+#endif
diff --git a/libstdc++-v3/configure.host b/libstdc++-v3/configure.host
index cb4c28a62bf3..0bed9dfff957 100644
--- a/libstdc++-v3/configure.host
+++ b/libstdc++-v3/configure.host
@@ -147,6 +147,9 @@ cpu_include_dir=cpu/${try_cpu}
 # Set specific CPU overrides for cpu_defines_dir. Most can just use generic.
 # THIS TABLE IS SORTED.  KEEP IT THAT WAY.
 case "${host_cpu}" in
+  amdgcn)
+    cpu_defines_dir=cpu/gcn
+    ;;
   arm*)
     cpu_defines_dir=cpu/arm
     ;;
-- 
2.34.1

Reply via email to