Files
binutils-gdb/config/clang-plugin.m4
H.J. Lu 10deea6e2f Binutils/GCC: Add clang LTO support to AR, NM and RANLIB
Add CLANG_PLUGIN_FILE to find the clang plugin file and pass it to
--plugin for ar, nm and ranlib so that binutils can be built with
clang LTO.  Run CLANG_PLUGIN_FILE before GCC_PLUGIN_OPTION since
GCC_PLUGIN_OPTION may return the wrong PLUGIN_OPTION with clang.

	PR binutils/33470
	* Makefile.in: Regenerated.
	* Makefile.tpl (NM): Add @NM_PLUGIN_OPTION@.
	* configure: Regenerated.
	* configure.ac: Include config/clang-plugin.m4.
	Run CLANG_PLUGIN_FILE before GCC_PLUGIN_OPTION to set
	PLUGIN_OPTION.  Set and subst NM_PLUGIN_OPTION.
	* libtool.m4 (_LT_CMD_OLD_ARCHIVE): Use CLANG_PLUGIN_FILE and
	GCC_PLUGIN_OPTION.

config/

	PR binutils/33470
	* clang-plugin.m4: New file.

libbacktrace/

	PR binutils/33470
	* Makefile.in: Regenerated.
	* aclocal.m4: Likewise.
	* configure: Likewise.

libiberty/

	PR binutils/33470
	* aclocal.m4: Regenerated.
	* configure: Likewise.
	* configure.ac: Move GCC_PLUGIN_OPTION after GCC_NO_EXECUTABLES.
	Run CLANG_PLUGIN_FILE before GCC_PLUGIN_OPTION to set
	PLUGIN_OPTION.  Don't add the redundant --plugin option.

zlib/

	PR binutils/33470
	* Makefile.in: Regenerated.
	* aclocal.m4: Likewise.
	* configure: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-09-25 12:30:13 +08:00

63 lines
1.9 KiB
Plaintext

# clang-plugin.m4 -*- Autoconf -*-
# Check clang plugin file.
dnl Copyright (C) 2025 Free Software Foundation, Inc.
dnl This file is free software, distributed under the terms of the GNU
dnl General Public License. As a special exception to the GNU General
dnl Public License, this file may be distributed as part of a program
dnl that contains a configuration script generated by Autoconf, under
dnl the same distribution terms as the rest of that program.
dnl
dnl
dnl CLANG_PLUGIN_FILE
dnl (SHELL-CODE_HANDLER)
dnl
AC_DEFUN([CLANG_PLUGIN_FILE],[dnl
AC_CACHE_CHECK([for clang], 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])
plugin_names="LLVMgold.so"
for plugin in $plugin_names; do
plugin_file=`${CC} ${CFLAGS} --print-file-name $plugin`
if test x$plugin_file = x$plugin; then
AC_CHECK_TOOL(LLVM_CONFIG, llvm-config)
if test "$?" != 0; then
AC_MSG_ERROR([Required tool 'llvm-config' not found on PATH.])
fi
clang_lib_dir=`$LLVM_CONFIG --libdir`
if test -f $clang_lib_dir/$plugin; then
plugin_file=$clang_lib_dir/$plugin
fi
if test x$plugin_file != x$plugin; then
break;
fi
fi
done
if test -z $plugin_file; then
AC_MSG_ERROR([Couldn't find clang plugin file for $CC.])
fi
dnl Check if ${AR} $plugin_option rc works.
AC_CHECK_TOOL(AR, ar)
if test "${AR}" = "" ; then
AC_MSG_ERROR([Required archive tool 'ar' not found on PATH.])
fi
plugin_option="--plugin $plugin_file"
touch conftest.c
${AR} $plugin_option rc conftest.a conftest.c
if test "$?" != 0; then
AC_MSG_WARN([Failed: $AR $plugin_option rc])
plugin_file=
fi
rm -f conftest.*
AC_MSG_RESULT($plugin_file)
fi
$1="$plugin_file"
])