]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
binutils: Pass target plugin file to target ar/nm/ranlib
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 26 Sep 2025 00:03:01 +0000 (08:03 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Sat, 27 Sep 2025 03:34:45 +0000 (11:34 +0800)
There are 2 kinds of binutils tests:

1. Tests of binutils object files and libraries using the build tools,
like CC, AR, NM and RANLIB.
2. Tests of binutils programs as the target tools, like CC_FOR_TARGET,
AR_FOR_TARGET, NM_FOR_TARGET and RANLIB_FOR_TARGET.

Set AR_PLUGIN_OPTION_FOR_TARGET, NM_PLUGIN_OPTION_FOR_TARGET and
RANLIB_PLUGIN_OPTION_FOR_TARGET to the target compiler plugin file for
target ar/nm/ranlib.

PR binutils/33483
* Makefile.in: Regenerated.
* configure: Likewise.
* Makefile.tpl (AR_FOR_TARGET): Add @AR_PLUGIN_OPTION_FOR_TARGET@.
(NM_FOR_TARGET): Add @NM_PLUGIN_OPTION_FOR_TARGET@.
(RANLIB_FOR_TARGET): Add @RANLIB_PLUGIN_OPTION_FOR_TARGET@.
* configure.ac: Use CLANG_PLUGIN_FILE_FOR_TARGET and
GCC_PLUGIN_OPTION_FOR_TARGET to set AR_PLUGIN_OPTION_FOR_TARGET,
NM_PLUGIN_OPTION_FOR_TARGET and RANLIB_PLUGIN_OPTION_FOR_TARGET.
AC_SUBST AR_PLUGIN_OPTION_FOR_TARGET, NM_PLUGIN_OPTION_FOR_TARGET
and RANLIB_PLUGIN_OPTION_FOR_TARGET.

config/

PR binutils/33483
* clang-plugin.m4 (CLANG_PLUGIN_FILE_FOR_TARGET): New.
* gcc-plugin.m4 (GCC_PLUGIN_OPTION_FOR_TARGET): Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Makefile.in
Makefile.tpl
config/clang-plugin.m4
config/gcc-plugin.m4
configure
configure.ac

index bb1ebbf8a33fe0abfd4929648e03503bcff33c6d..3b0f6321ffd5372b97118a47592b06f00317a9bb 100644 (file)
@@ -659,7 +659,7 @@ do-compare3 = $(do-compare)
 # Programs producing files for the TARGET machine
 # -----------------------------------------------
 
-AR_FOR_TARGET=@AR_FOR_TARGET@
+AR_FOR_TARGET=@AR_FOR_TARGET@ @AR_PLUGIN_OPTION_FOR_TARGET@
 AS_FOR_TARGET=@AS_FOR_TARGET@
 CC_FOR_TARGET=$(STAGE_CC_WRAPPER) @CC_FOR_TARGET@
 
@@ -679,11 +679,11 @@ DSYMUTIL_FOR_TARGET=@DSYMUTIL_FOR_TARGET@
 LD_FOR_TARGET=@LD_FOR_TARGET@
 
 LIPO_FOR_TARGET=@LIPO_FOR_TARGET@
-NM_FOR_TARGET=@NM_FOR_TARGET@
+NM_FOR_TARGET=@NM_FOR_TARGET@ @NM_PLUGIN_OPTION_FOR_TARGET@
 OBJDUMP_FOR_TARGET=@OBJDUMP_FOR_TARGET@
 OBJCOPY_FOR_TARGET=@OBJCOPY_FOR_TARGET@
 OTOOL_FOR_TARGET=@OTOOL_FOR_TARGET@
-RANLIB_FOR_TARGET=@RANLIB_FOR_TARGET@
+RANLIB_FOR_TARGET=@RANLIB_FOR_TARGET@ @RANLIB_PLUGIN_OPTION_FOR_TARGET@
 READELF_FOR_TARGET=@READELF_FOR_TARGET@
 STRIP_FOR_TARGET=@STRIP_FOR_TARGET@
 WINDRES_FOR_TARGET=@WINDRES_FOR_TARGET@
index 8534a9804c546a96d5d38e8b307b5cb1d4f27102..c642836662136eef0141fd69ae9481eb00cec5c2 100644 (file)
@@ -582,7 +582,7 @@ do-compare3 = $(do-compare)
 # Programs producing files for the TARGET machine
 # -----------------------------------------------
 
-AR_FOR_TARGET=@AR_FOR_TARGET@
+AR_FOR_TARGET=@AR_FOR_TARGET@ @AR_PLUGIN_OPTION_FOR_TARGET@
 AS_FOR_TARGET=@AS_FOR_TARGET@
 CC_FOR_TARGET=$(STAGE_CC_WRAPPER) @CC_FOR_TARGET@
 
@@ -602,11 +602,11 @@ DSYMUTIL_FOR_TARGET=@DSYMUTIL_FOR_TARGET@
 LD_FOR_TARGET=@LD_FOR_TARGET@
 
 LIPO_FOR_TARGET=@LIPO_FOR_TARGET@
-NM_FOR_TARGET=@NM_FOR_TARGET@
+NM_FOR_TARGET=@NM_FOR_TARGET@ @NM_PLUGIN_OPTION_FOR_TARGET@
 OBJDUMP_FOR_TARGET=@OBJDUMP_FOR_TARGET@
 OBJCOPY_FOR_TARGET=@OBJCOPY_FOR_TARGET@
 OTOOL_FOR_TARGET=@OTOOL_FOR_TARGET@
-RANLIB_FOR_TARGET=@RANLIB_FOR_TARGET@
+RANLIB_FOR_TARGET=@RANLIB_FOR_TARGET@ @RANLIB_PLUGIN_OPTION_FOR_TARGET@
 READELF_FOR_TARGET=@READELF_FOR_TARGET@
 STRIP_FOR_TARGET=@STRIP_FOR_TARGET@
 WINDRES_FOR_TARGET=@WINDRES_FOR_TARGET@
index ce7307cb70d024b0b2c14362023202000409952f..14219910ec5b785145ad8d8754173934508a452d 100644 (file)
@@ -60,3 +60,49 @@ AC_DEFUN([CLANG_PLUGIN_FILE],[dnl
   fi
   $1="$plugin_file"
 ])
+
+dnl
+dnl
+dnl CLANG_PLUGIN_FILE_FOR_TARGET
+dnl    (SHELL-CODE_HANDLER)
+dnl
+AC_DEFUN([CLANG_PLUGIN_FILE_FOR_TARGET],[dnl
+  AC_CACHE_CHECK([for clang for target], clang_cv_is_clang, [
+    AC_EGREP_CPP(yes, [
+#ifdef __clang__
+  yes
+#endif
+    ], clang_cv_is_clang=yes, clang_cv_is_clang=no)])
+  plugin_file=
+  if test $clang_cv_is_clang = yes; then
+    AC_MSG_CHECKING([for clang plugin file for target])
+    plugin_names="LLVMgold.so"
+    COMPILER_FOR_TARGET="${CC_FOR_TARGET}"
+    dnl Check if the host compiler is used.
+    if test x${COMPILER_FOR_TARGET} = x"\$(CC)"; then
+      COMPILER_FOR_TARGET="$CC"
+    fi
+    for plugin in $plugin_names; do
+      plugin_file=`${COMPILER_FOR_TARGET} ${CFLAGS_FOR_TARGET} --print-file-name $plugin`
+      if test x$plugin_file = x$plugin; then
+       GCC_TARGET_TOOL(llvm-config, LLVM_CONFIG_FOR_TARGET, LLVM_CONFIG)
+       if test "$?" != 0; then
+         AC_MSG_ERROR([Required target tool 'llvm-config' not found.])
+       fi
+       clang_lib_dir=`$LLVM_CONFIG_FOR_TARGET --libdir`
+       if test -f $clang_lib_dir/$plugin; then
+         plugin_file=$clang_lib_dir/$plugin
+       fi
+      fi
+      if test x$plugin_file != x$plugin; then
+       break;
+      fi
+      plugin_file=
+    done
+    if test -z $plugin_file; then
+      AC_MSG_ERROR([Couldn't find clang plugin file for $CC_FOR_TARGET.])
+    fi
+    AC_MSG_RESULT($plugin_file)
+  fi
+  $1="$plugin_file"
+])
index c30cfdd8fadba3fb54f89d6afe8edb3441206dba..84110142019eba25eb0cdd676b7691a25c9928e9 100644 (file)
@@ -169,3 +169,36 @@ else
   AC_MSG_RESULT([no])
 fi
 ])
+
+dnl
+dnl
+dnl GCC_PLUGIN_OPTION_FOR_TARGET
+dnl    (SHELL-CODE_HANDLER)
+dnl
+AC_DEFUN([GCC_PLUGIN_OPTION_FOR_TARGET],[dnl
+AC_MSG_CHECKING([for -plugin option])
+
+COMPILER_FOR_TARGET="${CC_FOR_TARGET}"
+dnl Check if the host compiler is used.
+if test x${COMPILER_FOR_TARGET} = x"\$(CC)"; then
+  COMPILER_FOR_TARGET="$CC"
+fi
+plugin_names="liblto_plugin.so liblto_plugin-0.dll cyglto_plugin-0.dll"
+plugin_option=
+for plugin in $plugin_names; do
+  plugin_so=`${COMPILER_FOR_TARGET} ${CFLAGS_FOR_TARGET} --print-prog-name $plugin`
+  if test x$plugin_so = x$plugin; then
+    plugin_so=`${COMPILER_FOR_TARGET} ${CFLAGS_FOR_TARGET} --print-file-name $plugin`
+  fi
+  if test x$plugin_so != x$plugin; then
+    plugin_option="--plugin $plugin_so"
+    break
+  fi
+done
+if test -n "$plugin_option"; then
+  $1="$plugin_option"
+  AC_MSG_RESULT($plugin_option)
+else
+  AC_MSG_RESULT([no])
+fi
+])
index 5cef196ae5fa1506371570111e7a570da8e14a7d..f2571197877a87c355c455ff803bc1b28b6b0ade 100755 (executable)
--- a/configure
+++ b/configure
@@ -596,6 +596,10 @@ MAINTAINER_MODE_TRUE
 COMPILER_NM_FOR_TARGET
 COMPILER_LD_FOR_TARGET
 COMPILER_AS_FOR_TARGET
+RANLIB_PLUGIN_OPTION_FOR_TARGET
+NM_PLUGIN_OPTION_FOR_TARGET
+AR_PLUGIN_OPTION_FOR_TARGET
+LLVM_CONFIG_FOR_TARGET
 FLAGS_FOR_TARGET
 RAW_CXX_FOR_TARGET
 WINDMC_FOR_TARGET
@@ -20383,6 +20387,142 @@ AR_FOR_TARGET=${AR_FOR_TARGET}${extra_arflags_for_target}
 RANLIB_FOR_TARGET=${RANLIB_FOR_TARGET}${extra_ranlibflags_for_target}
 NM_FOR_TARGET=${NM_FOR_TARGET}${extra_nmflags_for_target}
 
+# Try CLANG_PLUGIN_FILE_FOR_TARGET first since GCC_PLUGIN_OPTION_FOR_TARGET
+# may return the wrong PLUGIN_OPTION_FOR_TARGET with clang.
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for clang for target" >&5
+$as_echo_n "checking for clang for target... " >&6; }
+if ${clang_cv_is_clang+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#ifdef __clang__
+  yes
+#endif
+
+_ACEOF
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
+  $EGREP "yes" >/dev/null 2>&1; then :
+  clang_cv_is_clang=yes
+else
+  clang_cv_is_clang=no
+fi
+rm -f conftest*
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $clang_cv_is_clang" >&5
+$as_echo "$clang_cv_is_clang" >&6; }
+  plugin_file=
+  if test $clang_cv_is_clang = yes; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for clang plugin file for target" >&5
+$as_echo_n "checking for clang plugin file for target... " >&6; }
+    plugin_names="LLVMgold.so"
+    COMPILER_FOR_TARGET="${CC_FOR_TARGET}"
+        if test x${COMPILER_FOR_TARGET} = x"\$(CC)"; then
+      COMPILER_FOR_TARGET="$CC"
+    fi
+    for plugin in $plugin_names; do
+      plugin_file=`${COMPILER_FOR_TARGET} ${CFLAGS_FOR_TARGET} --print-file-name $plugin`
+      if test x$plugin_file = x$plugin; then
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking where to find the target llvm-config" >&5
+$as_echo_n "checking where to find the target llvm-config... " >&6; }
+if test "x${build}" != "x${host}" ; then
+  if expr "x$LLVM_CONFIG_FOR_TARGET" : "x/" > /dev/null; then
+    # We already found the complete path
+    ac_dir=`dirname $LLVM_CONFIG_FOR_TARGET`
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: pre-installed in $ac_dir" >&5
+$as_echo "pre-installed in $ac_dir" >&6; }
+  else
+    # Canadian cross, just use what we found
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: pre-installed" >&5
+$as_echo "pre-installed" >&6; }
+  fi
+else
+  if expr "x$LLVM_CONFIG_FOR_TARGET" : "x/" > /dev/null; then
+    # We already found the complete path
+    ac_dir=`dirname $LLVM_CONFIG_FOR_TARGET`
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: pre-installed in $ac_dir" >&5
+$as_echo "pre-installed in $ac_dir" >&6; }
+  elif test "x$target" = "x$host"; then
+    # We can use an host tool
+    LLVM_CONFIG_FOR_TARGET='$(LLVM_CONFIG)'
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: host tool" >&5
+$as_echo "host tool" >&6; }
+  else
+    # We need a cross tool
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: pre-installed" >&5
+$as_echo "pre-installed" >&6; }
+  fi
+fi
+
+       if test "$?" != 0; then
+         as_fn_error $? "Required target tool 'llvm-config' not found." "$LINENO" 5
+       fi
+       clang_lib_dir=`$LLVM_CONFIG_FOR_TARGET --libdir`
+       if test -f $clang_lib_dir/$plugin; then
+         plugin_file=$clang_lib_dir/$plugin
+       fi
+      fi
+      if test x$plugin_file != x$plugin; then
+       break;
+      fi
+      plugin_file=
+    done
+    if test -z $plugin_file; then
+      as_fn_error $? "Couldn't find clang plugin file for $CC_FOR_TARGET." "$LINENO" 5
+    fi
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $plugin_file" >&5
+$as_echo "$plugin_file" >&6; }
+  fi
+  PLUGIN_FILE_FOR_TARGET="$plugin_file"
+
+if test -n "$PLUGIN_FILE_FOR_TARGET"; then
+  PLUGIN_OPTION_FOR_TARGET="--plugin $PLUGIN_FILE_FOR_TARGET"
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -plugin option" >&5
+$as_echo_n "checking for -plugin option... " >&6; }
+
+COMPILER_FOR_TARGET="${CC_FOR_TARGET}"
+if test x${COMPILER_FOR_TARGET} = x"\$(CC)"; then
+  COMPILER_FOR_TARGET="$CC"
+fi
+plugin_names="liblto_plugin.so liblto_plugin-0.dll cyglto_plugin-0.dll"
+plugin_option=
+for plugin in $plugin_names; do
+  plugin_so=`${COMPILER_FOR_TARGET} ${CFLAGS_FOR_TARGET} --print-prog-name $plugin`
+  if test x$plugin_so = x$plugin; then
+    plugin_so=`${COMPILER_FOR_TARGET} ${CFLAGS_FOR_TARGET} --print-file-name $plugin`
+  fi
+  if test x$plugin_so != x$plugin; then
+    plugin_option="--plugin $plugin_so"
+    break
+  fi
+done
+if test -n "$plugin_option"; then
+  PLUGIN_OPTION_FOR_TARGET="$plugin_option"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $plugin_option" >&5
+$as_echo "$plugin_option" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+fi
+if test -n "$PLUGIN_OPTION_FOR_TARGET"; then
+  AR_PLUGIN_OPTION_FOR_TARGET="$PLUGIN_OPTION_FOR_TARGET"
+  NM_PLUGIN_OPTION_FOR_TARGET="$PLUGIN_OPTION_FOR_TARGET"
+  RANLIB_PLUGIN_OPTION_FOR_TARGET="$PLUGIN_OPTION_FOR_TARGET"
+else
+  AR_PLUGIN_OPTION_FOR_TARGET=
+  NM_PLUGIN_OPTION_FOR_TARGET=
+  RANLIB_PLUGIN_OPTION_FOR_TARGET=
+fi
+
+
+
+
 # When building target libraries, except in a Canadian cross, we use
 # the same toolchain as the compiler we just built.
 COMPILER_AS_FOR_TARGET='$(AS_FOR_TARGET)'
index bc9a3d4a7461a980231cadb5cabe58f9c96a2cdc..8050259e34f5ce1efef7bdabe9a4d0198053ea31 100644 (file)
@@ -4012,6 +4012,27 @@ AR_FOR_TARGET=${AR_FOR_TARGET}${extra_arflags_for_target}
 RANLIB_FOR_TARGET=${RANLIB_FOR_TARGET}${extra_ranlibflags_for_target}
 NM_FOR_TARGET=${NM_FOR_TARGET}${extra_nmflags_for_target}
 
+# Try CLANG_PLUGIN_FILE_FOR_TARGET first since GCC_PLUGIN_OPTION_FOR_TARGET
+# may return the wrong PLUGIN_OPTION_FOR_TARGET with clang.
+CLANG_PLUGIN_FILE_FOR_TARGET(PLUGIN_FILE_FOR_TARGET)
+if test -n "$PLUGIN_FILE_FOR_TARGET"; then
+  PLUGIN_OPTION_FOR_TARGET="--plugin $PLUGIN_FILE_FOR_TARGET"
+else
+  GCC_PLUGIN_OPTION_FOR_TARGET(PLUGIN_OPTION_FOR_TARGET)
+fi
+if test -n "$PLUGIN_OPTION_FOR_TARGET"; then
+  AR_PLUGIN_OPTION_FOR_TARGET="$PLUGIN_OPTION_FOR_TARGET"
+  NM_PLUGIN_OPTION_FOR_TARGET="$PLUGIN_OPTION_FOR_TARGET"
+  RANLIB_PLUGIN_OPTION_FOR_TARGET="$PLUGIN_OPTION_FOR_TARGET"
+else
+  AR_PLUGIN_OPTION_FOR_TARGET=
+  NM_PLUGIN_OPTION_FOR_TARGET=
+  RANLIB_PLUGIN_OPTION_FOR_TARGET=
+fi
+AC_SUBST(AR_PLUGIN_OPTION_FOR_TARGET)
+AC_SUBST(NM_PLUGIN_OPTION_FOR_TARGET)
+AC_SUBST(RANLIB_PLUGIN_OPTION_FOR_TARGET)
+
 # When building target libraries, except in a Canadian cross, we use
 # the same toolchain as the compiler we just built.
 COMPILER_AS_FOR_TARGET='$(AS_FOR_TARGET)'