Ok, admittedly, the following patch [v2] is cleaner and the assumption
that the llvm-mc assembler is used is also inside the backend assembler
spec.

OK for mainline?

* * *

Note: I tried to see whether this patch plus the comment 14 patch makes
a difference. While the testcase itself (and in our testsuite all others
as well) stopped failing after early July, I could manually trigger it
by copying some lines 20,000 times – which failed without the comment 14
patch by Jakub, but assembled without issues with the patch.
Thus, on the assembler side, it seems to work fine. - Note: I have not
tried to see how debugger handle it - nor have I extensively run test
suite to see whether there are any issues. But at least llvm-mc-15 to
llvm-mc-20 seem to be happy with the assembler file.

* * *

Jakub Jelinek wrote:

+    # llvm-mc requires those flags to produce a proper .o file
+    # readable by either binutils' objdump or llvm-objdump
Ugh, so what exactly it outputs by default?

--filetype=asm ("Emit an assembly ('.s') file"), otherwise 'null'
and 'obj' are supported.
The resulting "asm" file looks pretty much the same as the original .s,
except that ".uleb128 1280" gets converted to '.ascii  "\200\n"'.

* * *

Does the gcc driver pass those options to as all the time?

Yes, see config/gcn/gcn-hsa.h's ASM_SPEC; admittedly,
it uses -triple=amdgcn--amdhsa, which is nearly the same
but not quite as -arch=amdgcn.  This difference really
shouldn't matter, but I have now switched over to
-triple=amdgcn--amdhsa as well. (I think it sets a
single extra flag when HSA appears, but I might have
misread or just misremembed what's in the LLVM source code.)

* * *

In any case, don't all the other gcc_cv_as tests need the same options?
If they read ELF files, yes. When glancing at it, I missed:
Sure, some tests use gcc_GAS_CHECK_FEATURE and only care if something
assembles, don't check conftest.o.
But e.g. gcc_cv_as_subsection_m1 test uses nm on conftest.o,
gcc_cv_ld_ro_rw_mix uses ld on it, gcc_fn_eh_frame_ro uses objdump,
gcc_cv_as_cfi_advance_working does as well, etc.
So if the defaults are insane, perhaps they should be appended to
gcc_cv_as var?

Talking about gcc_fn_eh_frame_ro, it really seems to make
sense to add 'objdump' to install.texi.

Tobias
[gcn] gcc/configure.ac + install.texi - changes to detect HAVE_AS_LEB128 [PR119367]

The llvm-mc linker by default assemblies to another assembly file and not to an ELF
binary; that usually does not matter – but for the LEB128 check, additionally, the
resulting binary is checked. Hence, when using llvm-mc as target linker for
amdgcn-*-*, we better add the "--filetype=obj -triple=amdgcn--amdhsa" flags. The
current patch does so unconditionally, assuming that always llvm-mc is used.

Additionally, the resulting ELF file is checked, which requires an ELF reader such
as objdump. This commit adds llvm-objdump to the build documentation for amdgcn,
albeit also, e.g., Binutil's 'objdump' would do - as long as either
amdgcn-amdhsa-objdump or amdgcn-amdhsa/bin/objdump is found during the amdgcn
cross build.

gcc/ChangeLog:

	PR debug/119367
	* acinclude.m4 (gcc_GAS_FLAGS): For gcn, use "--filetype=obj
	-triple=amdgcn--amdhsa", if supported.
	* configure: Regenerate.
	* doc/install.texi (amdgcn-*-*): Also add llvm-objdump to the list of
	to-be-copied files.

 gcc/acinclude.m4     | 5 +++++
 gcc/configure        | 3 +++
 gcc/doc/install.texi | 1 +
 3 files changed, 9 insertions(+)

diff --git a/gcc/acinclude.m4 b/gcc/acinclude.m4
index ca4820221d5..ad8b878e24d 100644
--- a/gcc/acinclude.m4
+++ b/gcc/acinclude.m4
@@ -481,6 +481,11 @@ AC_DEFUN([gcc_GAS_FLAGS],
     dnl Always pass -arch ppc to assembler.
     gcc_cv_as_flags="-arch ppc"
     ;;
+  amdgcn*)
+    dnl Currently, only the llvm-mc assembler is supported.
+    dnl Add flags to ensure an amdgcn ELF file is written
+    gcc_cv_as_flags="--filetype=obj -triple=amdgcn--amdhsa"
+    ;;
   *)
     gcc_cv_as_flags=" "
     ;;
diff --git a/gcc/configure b/gcc/configure
index 4a751d969ba..66b51d63022 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -25638,6 +25638,9 @@ else
   powerpc*-*-darwin*)
         gcc_cv_as_flags="-arch ppc"
     ;;
+  amdgcn*)
+            gcc_cv_as_flags="--filetype=obj -triple=amdgcn--amdhsa"
+    ;;
   *)
     gcc_cv_as_flags=" "
     ;;
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 6913035b596..f2a8d0e24ab 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -4065,6 +4065,7 @@ AMD GCN GPU target.
 Instead of GNU Binutils, you need to install LLVM and copy
 @file{bin/llvm-mc} to @file{amdgcn-amdhsa/bin/as},
 @file{bin/lld} to @file{amdgcn-amdhsa/bin/ld},
+@file{bin/llvm-objdump} to @file{amdgcn-amdhsa/bin/objdump},
 @file{bin/llvm-nm} to @file{amdgcn-amdhsa/bin/nm}, and
 @file{bin/llvm-ar} to both @file{bin/amdgcn-amdhsa-ar} and
 @file{bin/amdgcn-amdhsa-ranlib}.

Reply via email to