public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-9168] amdgcn: fix up offload debug linking with LLVM 13
@ 2021-10-18  8:57 Tobias Burnus
  0 siblings, 0 replies; only message in thread
From: Tobias Burnus @ 2021-10-18  8:57 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:cc84160c5f470b23b7aed4633f887df113b2675d

commit r11-9168-gcc84160c5f470b23b7aed4633f887df113b2675d
Author: Andrew Stubbs <ams@codesourcery.com>
Date:   Wed Oct 13 11:53:42 2021 +0100

    amdgcn: fix up offload debug linking with LLVM 13
    
    Between LLVM 9 and LLVM 13 the attribute works differently in several ways,
    and this needs to be allowed for in GCC and mkoffload independently.
    
    This patch fixes up mkoffload when debug info is enabled, which is made more
    complicated because the configure tests checks whether the attribute option
    is accepted silently, but does not check if the assembler actually sets the
    ELF flags for that attribute, and mkoffload needs to mimick that behaviour
    exactly. The patch therefore removes some of the conditionals.
    
    gcc/ChangeLog:
    
            * config/gcn/gcn-hsa.h (S_FIJI): Set unconditionally.
            (S_900): Likewise.
            (S_906): Likewise.
            * config/gcn/gcn.c: Hard code SRAM ECC settings for old architectures.
            * config/gcn/mkoffload.c (ELFABIVERSION_AMDGPU_HSA): Rename to ...
            (ELFABIVERSION_AMDGPU_HSA_V3): ... this.
            (ELFABIVERSION_AMDGPU_HSA_V4): New.
            (SET_SRAM_ECC_UNSUPPORTED): New.
            (copy_early_debug_info): Create elf flags to match the other objects.
            (main): Just let the attribute flags pass through.
    
    (cherry picked from commit f3d64372d777d7d6068df8167b6751c289963e85)

Diff:
---
 gcc/config/gcn/gcn-hsa.h   | 13 +------------
 gcc/config/gcn/gcn.c       |  6 ------
 gcc/config/gcn/mkoffload.c | 36 +++++++++++++++++++++++++-----------
 3 files changed, 26 insertions(+), 29 deletions(-)

diff --git a/gcc/config/gcn/gcn-hsa.h b/gcc/config/gcn/gcn-hsa.h
index 6a432d17d99..4fd2f07b983 100644
--- a/gcc/config/gcn/gcn-hsa.h
+++ b/gcc/config/gcn/gcn-hsa.h
@@ -96,21 +96,10 @@ extern unsigned int gcn_local_sym_hash (const char *name);
 #define X_908 "march=gfx908:;"
 #endif
 
-#ifdef HAVE_GCN_SRAM_ECC_FIJI
-#define S_FIJI
-#else
+/* These targets can't have SRAM-ECC, even if a broken assembler allows it.  */
 #define S_FIJI "!march=*:;march=fiji:;"
-#endif
-#ifdef HAVE_GCN_SRAM_ECC_GFX900
-#define S_900
-#else
 #define S_900 "march=gfx900:;"
-#endif
-#ifdef HAVE_GCN_SRAM_ECC_GFX906
-#define S_906
-#else
 #define S_906 "march=gfx906:;"
-#endif
 #ifdef HAVE_GCN_SRAM_ECC_GFX908
 #define S_908
 #else
diff --git a/gcc/config/gcn/gcn.c b/gcc/config/gcn/gcn.c
index eb4d2dbb949..329a578890b 100644
--- a/gcc/config/gcn/gcn.c
+++ b/gcc/config/gcn/gcn.c
@@ -5043,27 +5043,21 @@ output_file_start (void)
 #ifndef HAVE_GCN_XNACK_FIJI
       use_xnack_attr = false;
 #endif
-#ifndef HAVE_GCN_SRAM_ECC_FIJI
       use_sram_attr = false;
-#endif
       break;
     case PROCESSOR_VEGA10:
       cpu = "gfx900";
 #ifndef HAVE_GCN_XNACK_GFX900
       use_xnack_attr = false;
 #endif
-#ifndef HAVE_GCN_SRAM_ECC_GFX900
       use_sram_attr = false;
-#endif
       break;
     case PROCESSOR_VEGA20:
       cpu = "gfx906";
 #ifndef HAVE_GCN_XNACK_GFX906
       use_xnack_attr = false;
 #endif
-#ifndef HAVE_GCN_SRAM_ECC_GFX906
       use_sram_attr = false;
-#endif
       break;
     case PROCESSOR_GFX908:
       cpu = "gfx908";
diff --git a/gcc/config/gcn/mkoffload.c b/gcc/config/gcn/mkoffload.c
index 1da78b672f2..2b8350e1653 100644
--- a/gcc/config/gcn/mkoffload.c
+++ b/gcc/config/gcn/mkoffload.c
@@ -42,8 +42,10 @@
 
 #undef  ELFOSABI_AMDGPU_HSA
 #define ELFOSABI_AMDGPU_HSA	 64
-#undef  ELFABIVERSION_AMDGPU_HSA
-#define ELFABIVERSION_AMDGPU_HSA 1
+#undef  ELFABIVERSION_AMDGPU_HSA_V3
+#define ELFABIVERSION_AMDGPU_HSA_V3 1
+#undef  ELFABIVERSION_AMDGPU_HSA_V4
+#define ELFABIVERSION_AMDGPU_HSA_V4 2
 
 #undef  EF_AMDGPU_MACH_AMDGCN_GFX803
 #define EF_AMDGPU_MACH_AMDGCN_GFX803 0x2a
@@ -77,6 +79,7 @@
 #define SET_SRAM_ECC_ON(VAR) VAR |= EF_AMDGPU_SRAM_ECC_V3
 #define SET_SRAM_ECC_ANY(VAR) SET_SRAM_ECC_ON (VAR)
 #define SET_SRAM_ECC_OFF(VAR) VAR &= ~EF_AMDGPU_SRAM_ECC_V3
+#define SET_SRAM_ECC_UNSUPPORTED(VAR) SET_SRAM_ECC_OFF (VAR)
 #define TEST_SRAM_ECC_ANY(VAR) 0 /* Not supported.  */
 #define TEST_SRAM_ECC_ON(VAR) (VAR & EF_AMDGPU_SRAM_ECC_V3)
 #endif
@@ -94,6 +97,9 @@
 				     | EF_AMDGPU_FEATURE_SRAMECC_ANY_V4)
 #define SET_SRAM_ECC_OFF(VAR) VAR = ((VAR & ~EF_AMDGPU_FEATURE_SRAMECC_V4) \
 				     | EF_AMDGPU_FEATURE_SRAMECC_OFF_V4)
+#define SET_SRAM_ECC_UNSUPPORTED(VAR) \
+  VAR = ((VAR & ~EF_AMDGPU_FEATURE_SRAMECC_V4) \
+	 | EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4)
 #define TEST_SRAM_ECC_ANY(VAR) ((VAR & EF_AMDGPU_FEATURE_SRAMECC_V4) \
 				== EF_AMDGPU_FEATURE_SRAMECC_ANY_V4)
 #define TEST_SRAM_ECC_ON(VAR) ((VAR & EF_AMDGPU_FEATURE_SRAMECC_V4) \
@@ -346,12 +352,27 @@ copy_early_debug_info (const char *infile, const char *outfile)
   /* We only support host relocations of x86_64, for now.  */
   gcc_assert (ehdr.e_machine == EM_X86_64);
 
+  /* Fiji devices use HSACOv3 regardless of the assembler.  */
+  uint32_t elf_flags_actual = (elf_arch == EF_AMDGPU_MACH_AMDGCN_GFX803
+			       ? 0 : elf_flags);
+  /* GFX900 devices don't support the sramecc attribute even if
+     a buggy assembler thinks it does.  This must match gcn-hsa.h  */
+  if (elf_arch == EF_AMDGPU_MACH_AMDGCN_GFX900)
+    SET_SRAM_ECC_UNSUPPORTED (elf_flags_actual);
+
   /* Patch the correct elf architecture flag into the file.  */
   ehdr.e_ident[7] = ELFOSABI_AMDGPU_HSA;
-  ehdr.e_ident[8] = ELFABIVERSION_AMDGPU_HSA;
+#ifdef HAVE_GCN_ASM_V3_SYNTAX
+  ehdr.e_ident[8] = ELFABIVERSION_AMDGPU_HSA_V3;
+#endif
+#ifdef HAVE_GCN_ASM_V4_SYNTAX
+  ehdr.e_ident[8] = (elf_arch == EF_AMDGPU_MACH_AMDGCN_GFX803
+		     ? ELFABIVERSION_AMDGPU_HSA_V3
+		     : ELFABIVERSION_AMDGPU_HSA_V4);
+#endif
   ehdr.e_type = ET_REL;
   ehdr.e_machine = EM_AMDGPU;
-  ehdr.e_flags = elf_arch | elf_flags;
+  ehdr.e_flags = elf_arch | elf_flags_actual;
 
   /* Load the section headers so we can walk them later.  */
   Elf64_Shdr *sections = (Elf64_Shdr *)xmalloc (sizeof (Elf64_Shdr)
@@ -987,13 +1008,6 @@ main (int argc, char **argv)
   obstack_ptr_grow (&cc_argv_obstack, "-xlto");
   if (fopenmp)
     obstack_ptr_grow (&cc_argv_obstack, "-mgomp");
-  obstack_ptr_grow (&cc_argv_obstack,
-		    (TEST_XNACK (elf_flags)
-		     ? "-mxnack" : "-mno-xnack"));
-  obstack_ptr_grow (&cc_argv_obstack,
-		    (TEST_SRAM_ECC_ON (elf_flags) ? "-msram-ecc=on"
-		     : TEST_SRAM_ECC_ANY (elf_flags) ? "-msram-ecc=any"
-		     : "-msram-ecc=off"));
 
   for (int ix = 1; ix != argc; ix++)
     {


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-10-18  8:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-18  8:57 [gcc r11-9168] amdgcn: fix up offload debug linking with LLVM 13 Tobias Burnus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).