Cf. PR93409 comments 4 and later. The comments 1–3 of the PR are covered
by patch https://gcc.gnu.org/ml/gcc-patches/2020-01/msg01663.html (skip
building libgomp's HSA/GCN plugin with -mx32).
For AMDGCN, the LLVM assembler is used. While for LLVM 7+8, GCC
generates code which is the same as LLVM, for LLVM 9 (and later), the
LLVM switched from Code Object V2 to V3.
With LLVM 9, the old variant is only accepted when also passing
"-mattr=-code-object-v3" to the compiler; that's a"-" after the "=" to
disable V3. (Cf. also
https://sources.debian.org/src/gcc-10/10-20200117-2/debian/patches/gcc-amdgcn-fix.diff/).
My initial idea was to add a configure check – which I also include as
attachment. However, it turned out that at last the assembler of LLVM
version 7.0.1 already supports this flag. Hence, we can go for the
simpler solution and use the assembler flag unconditionally.
OK for the trunk?
Tobias
PR bootstrap/93409
* config/gcn/gcn-hsa.h (ASM_SPEC): Add -mattr=-code-object-v3 as
LLVM's assembler changed the default in version 9.
diff --git a/gcc/config/gcn/gcn-hsa.h b/gcc/config/gcn/gcn-hsa.h
index cefe67217e7..d6523cf1247 100644
--- a/gcc/config/gcn/gcn-hsa.h
+++ b/gcc/config/gcn/gcn-hsa.h
@@ -76,7 +76,7 @@ extern unsigned int gcn_local_sym_hash (const char *name);
#define GOMP_SELF_SPECS ""
/* Use LLVM assembler and linker options. */
-#define ASM_SPEC "-triple=amdgcn--amdhsa " \
+#define ASM_SPEC "-triple=amdgcn--amdhsa -mattr=-code-object-v3 " \
"%:last_arg(%{march=*:-mcpu=%*}) " \
"-filetype=obj"
/* Add -mlocal-symbol-id=<source-file-basename> unless the user (or mkoffload)
* IGNORE *
THIS PATCH IS NOT NEEDED AS LLVM 7's ASSEMBLER ALREADY SUPPORTS THAT OPTION.
ONLY THE DEFAULT CHANGED WITH LLVM 9
* gcc/configure.ac: Add -mattr=-code-object-v3 check.
* gcc/config/gcn/gcn-hsa.h (ASM_SPEC): use it
gcc/config.in | 12 +++++++
gcc/config/gcn/gcn-hsa.h | 7 ++++
gcc/configure | 91 +++++++++++++++++++++++++++++++++++++++++++-----
gcc/configure.ac | 33 ++++++++++++++++++
4 files changed, 135 insertions(+), 8 deletions(-)
diff --git a/gcc/config.in b/gcc/config.in
index ec5c46abdb5..05dc9499f22 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -546,6 +546,12 @@
#endif
+/* Define if your assembler supports -mattr=-code-object-v3. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_AS_MATTR_CODE_OBJECT_V3
+#endif
+
+
/* Define if your assembler supports mfcr field. */
#ifndef USED_FOR_TARGET
#undef HAVE_AS_MFCRF
@@ -2185,6 +2191,12 @@
#endif
+/* Define if your target C Library properly handles PT_GNU_STACK */
+#ifndef USED_FOR_TARGET
+#undef TARGET_LIBC_GNUSTACK
+#endif
+
+
/* Define if your target C Library provides the AT_HWCAP value in the TCB */
#ifndef USED_FOR_TARGET
#undef TARGET_LIBC_PROVIDES_HWCAP_IN_TCB
diff --git a/gcc/config/gcn/gcn-hsa.h b/gcc/config/gcn/gcn-hsa.h
index cefe67217e7..9ba2b543519 100644
--- a/gcc/config/gcn/gcn-hsa.h
+++ b/gcc/config/gcn/gcn-hsa.h
@@ -76,9 +76,16 @@ extern unsigned int gcn_local_sym_hash (const char *name);
#define GOMP_SELF_SPECS ""
/* Use LLVM assembler and linker options. */
+#if HAVE_AS_MATTR_CODE_OBJECT_V3
+#define ASM_SPEC "-triple=amdgcn--amdhsa -mattr=-code-object-v3 " \
+ "%:last_arg(%{march=*:-mcpu=%*}) " \
+ "-filetype=obj"
+#else
#define ASM_SPEC "-triple=amdgcn--amdhsa " \
"%:last_arg(%{march=*:-mcpu=%*}) " \
"-filetype=obj"
+#endif
+
/* Add -mlocal-symbol-id=<source-file-basename> unless the user (or mkoffload)
passes the option explicitly on the command line. The option also causes
several dump-matching tests to fail in the testsuite, so the option is not
diff --git a/gcc/configure b/gcc/configure
index 490fe6ac8e8..0b6a8cb23a4 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -974,6 +974,7 @@ with_zstd_include
with_zstd_lib
enable_rpath
with_libiconv_prefix
+with_libiconv_type
enable_sjlj_exceptions
with_gcc_major_version_only
enable_secureplt
@@ -1811,6 +1812,7 @@ Optional Packages:
--with-gnu-ld assume the C compiler uses GNU ld default=no
--with-libiconv-prefix[=DIR] search for libiconv in DIR/include and DIR/lib
--without-libiconv-prefix don't search for libiconv in includedir and libdir
+ --with-libiconv-type=TYPE type of library to search for (auto/static/shared)
--with-gcc-major-version-only
use only GCC major number in filesystem paths
--with-pic try to use only PIC/non-PIC objects [default=use
@@ -10730,6 +10732,16 @@ if test "${with_libiconv_prefix+set}" = set; then :
fi
+
+# Check whether --with-libiconv-type was given.
+if test "${with_libiconv_type+set}" = set; then :
+ withval=$with_libiconv_type; with_libiconv_type=$withval
+else
+ with_libiconv_type=auto
+fi
+
+ lib_type=`eval echo \$with_libiconv_type`
+
LIBICONV=
LTLIBICONV=
INCICONV=
@@ -10767,13 +10779,13 @@ fi
found_so=
found_a=
if test $use_additional = yes; then
- if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext"; then
+ if test -n "$shlibext" && test -f "$additional_libdir/lib$name.$shlibext" && test x$lib_type != xstatic; then
found_dir="$additional_libdir"
found_so="$additional_libdir/lib$name.$shlibext"
if test -f "$additional_libdir/lib$name.la"; then
found_la="$additional_libdir/lib$name.la"
fi
- else
+ elif test x$lib_type != xshared; then
if test -f "$additional_libdir/lib$name.$libext"; then
found_dir="$additional_libdir"
found_a="$additional_libdir/lib$name.$libext"
@@ -10797,13 +10809,13 @@ fi
case "$x" in
-L*)
dir=`echo "X$x" | sed -e 's/^X-L//'`
- if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext"; then
+ if test -n "$shlibext" && test -f "$dir/lib$name.$shlibext" && test x$lib_type != xstatic; then
found_dir="$dir"
found_so="$dir/lib$name.$shlibext"
if test -f "$dir/lib$name.la"; then
found_la="$dir/lib$name.la"
fi
- else
+ elif test x$lib_type != xshared; then
if test -f "$dir/lib$name.$libext"; then
found_dir="$dir"
found_a="$dir/lib$name.$libext"
@@ -11031,8 +11043,13 @@ fi
done
fi
else
- LIBICONV="${LIBICONV}${LIBICONV:+ }-l$name"
- LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-l$name"
+ if x$lib_type = xauto || x$lib_type = xshared; then
+ LIBICONV="${LIBICONV}${LIBICONV:+ }-l$name"
+ LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-l$name"
+ else
+ LIBICONV="${LIBICONV}${LIBICONV:+ }-l:lib$name.$libext"
+ LTLIBICONV="${LTLIBICONV}${LTLIBICONV:+ }-l:lib$name.$libext"
+ fi
fi
fi
fi
@@ -18957,7 +18974,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 18960 "configure"
+#line 18977 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -19063,7 +19080,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 19066 "configure"
+#line 19083 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -28158,6 +28175,47 @@ case "$target" in
;;
esac
+# AMGCGN: Check whether the assembler supports -mattr=-code-object-v3
+case "$target" in
+ amdgcn-* | gcn-*)
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler support for -mattr=-code-object-v3" >&5
+$as_echo_n "checking assembler support for -mattr=-code-object-v3... " >&6; }
+ gcc_cv_as_mattr_code_object_v3=no
+ if test x$gcc_cv_as != x; then
+ cat > conftest.s <<EOF
+ .text
+ .hsa_code_object_version 2,0
+ .hsa_code_object_isa
+ .section .AMDGPU.config
+ .text
+ .section .text
+ .globl a
+ .data
+ .align 16
+ .type a, @object
+ .size a, 4
+EOF
+ if { ac_try='$gcc_cv_as -triple=amdgcn--amdhsa -filetype=obj -mattr=-code-object-v3 conftest.s -o conftest.o'
+ { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; }
+ then
+ gcc_cv_as_mattr_code_object_v3=yes
+ fi
+ rm -f conftest.s conftest.o conftest
+ fi
+ if test x$gcc_cv_as_mattr_code_object_v3 = xyes; then
+
+$as_echo "#define HAVE_AS_MATTR_CODE_OBJECT_V3 1" >>confdefs.h
+
+ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_mattr_code_object_v3" >&5
+$as_echo "$gcc_cv_as_mattr_code_object_v3" >&6; }
+ ;;
+esac
+
# ??? Not all targets support dwarf2 debug_line, even within a version
# of gas. Moreover, we need to emit a valid instruction to trigger any
# info to the output file. So, as supported targets are added to gas 2.11,
@@ -29800,6 +29858,23 @@ $as_echo "#define TARGET_LIBC_PROVIDES_HWCAP_IN_TCB 1" >>confdefs.h
fi
+# Check if the target LIBC handles PT_GNU_STACK.
+gcc_cv_libc_gnustack=unknown
+case "$target" in
+ mips*-*-linux*)
+
+if test $glibc_version_major -gt 2 \
+ || ( test $glibc_version_major -eq 2 && test $glibc_version_minor -ge 31 ); then :
+ gcc_cv_libc_gnustack=yes
+fi
+ ;;
+esac
+if test x$gcc_cv_libc_gnustack = xyes; then
+
+$as_echo "#define TARGET_LIBC_GNUSTACK 1" >>confdefs.h
+
+fi
+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dl_iterate_phdr in target C library" >&5
$as_echo_n "checking dl_iterate_phdr in target C library... " >&6; }
gcc_cv_target_dl_iterate_phdr=unknown
diff --git a/gcc/configure.ac b/gcc/configure.ac
index a7521ee9943..22357ff1aac 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -5084,6 +5084,39 @@ case "$target" in
;;
esac
+# AMGCGN: Check whether the assembler supports -mattr=-code-object-v3
+case "$target" in
+ amdgcn-* | gcn-*)
+ AC_MSG_CHECKING(assembler support for -mattr=-code-object-v3)
+ gcc_cv_as_mattr_code_object_v3=no
+ if test x$gcc_cv_as != x; then
+ cat > conftest.s <<EOF
+ .text
+ .hsa_code_object_version 2,0
+ .hsa_code_object_isa
+ .section .AMDGPU.config
+ .text
+ .section .text
+ .globl a
+ .data
+ .align 16
+ .type a, @object
+ .size a, 4
+EOF
+ if AC_TRY_COMMAND([$gcc_cv_as -triple=amdgcn--amdhsa -filetype=obj -mattr=-code-object-v3 conftest.s -o conftest.o])
+ then
+ gcc_cv_as_mattr_code_object_v3=yes
+ fi
+ rm -f conftest.s conftest.o conftest
+ fi
+ if test x$gcc_cv_as_mattr_code_object_v3 = xyes; then
+ AC_DEFINE(HAVE_AS_MATTR_CODE_OBJECT_V3, 1,
+ [Define if your assembler supports -mattr=-code-object-v3.])
+ fi
+ AC_MSG_RESULT($gcc_cv_as_mattr_code_object_v3)
+ ;;
+esac
+
# ??? Not all targets support dwarf2 debug_line, even within a version
# of gas. Moreover, we need to emit a valid instruction to trigger any
# info to the output file. So, as supported targets are added to gas 2.11,