[v3,1/9] Add configure check to test if gcc supports attribute ifunc.

Message ID 1472047472-30307-1-git-send-email-stli@linux.vnet.ibm.com
State Committed
Headers

Commit Message

Stefan Liebler Aug. 24, 2016, 2:04 p.m. UTC
  This patch adds a configure check to test if gcc supports attribute ifunc.
The support can either be enabled in <gcc-src>/gcc/config.gcc for one
architecture in general by setting default_gnu_indirect_function variable to yes
or by configuring gcc with --enable-gnu-indirect-function.

The next patch rewrites libc_ifunc macro to use gcc attribute ifunc instead
of inline assembly to generate the IFUNC symbols due to false debuginfo.

If gcc does not support attribute ifunc, the old approach for generating
ifunc'ed symbols is used. Then the debug-information is false. Thus it is
recommended to use a gcc with indirect function support (See notes in INSTALL).
After this patch-series these inline assemblies for ifunc-handling are not
scattered in multiple files but are used only indirect via ifunc-macros
and can simply removed in libc-symbols.h in future.

If glibc is configured with --enable-multi-arch and gcc does not support
attribute ifunc, a configure warning is dumped!

This NEWS entry will be added:
* For multi-arch support it is recommended to use a GCC with gnu-indirect-function
  support as it is used to generate ifunc'ed symbols with correct
  debug-information. This support can either be enabled by configuring GCC with
  '--enable-gnu-indirect-function' or by enabling it by default by setting
  'default_gnu_indirect_function' variable for a particular architecture in
  gcc source file 'gcc/config.gcc'.

ChangeLog:

	* config.h.in (HAVE_GCC_IFUNC): New undef.
	* configure.ac: Add check if gcc supports attribute ifunc feature.
	* configure: Regenerated.
	* manual/install.texi: Add recommendation for gcc with
	indirect-function support.
	* INSTALL: Regenerated.
---
 INSTALL             |  8 ++++++++
 config.h.in         |  3 +++
 configure           | 42 ++++++++++++++++++++++++++++++++++++++++++
 configure.ac        | 33 +++++++++++++++++++++++++++++++++
 manual/install.texi |  7 +++++++
 5 files changed, 93 insertions(+)
  

Comments

Florian Weimer Aug. 29, 2016, 9:34 a.m. UTC | #1
On 08/24/2016 04:04 PM, Stefan Liebler wrote:
> +For multi-arch support it is recommended to use a GCC with gnu-indirect-function
> +support as it is used to generate ifunc'ed symbols with correct
> +debug-information. This support can either be enabled by configuring GCC with
> +@samp{--enable-gnu-indirect-function} or by enabling it by default by setting
> +@samp{default_gnu_indirect_function} variable for a particular architecture in
> +gcc source file @file{gcc/config.gcc}.

Maybe use this text instead?

For multi-arch support it is recommended to use a GCC which has been 
built with support for GNU indirect functions.  This ensures that 
correct debugging information is generated for functions selected by 
IFUNC resolvers.  This support can either be enabled by configuring GCC 
with @samp{--enable-gnu-indirect-function}, or by enabling it by default 
by setting @samp{default_gnu_indirect_function} variable for a 
particular architecture in the GCC source file @file{gcc/config.gcc}.


The configure check looks okay to me.  Some existing checks use 
AC_TRY_COMPILE, others use the manual expansion you provided.

Thanks,
Florian
  
Stefan Liebler Sept. 5, 2016, 7:12 a.m. UTC | #2
On 08/24/2016 04:04 PM, Stefan Liebler wrote:
> This patch adds a configure check to test if gcc supports attribute ifunc.
> The support can either be enabled in <gcc-src>/gcc/config.gcc for one
> architecture in general by setting default_gnu_indirect_function variable to yes
> or by configuring gcc with --enable-gnu-indirect-function.
>
> The next patch rewrites libc_ifunc macro to use gcc attribute ifunc instead
> of inline assembly to generate the IFUNC symbols due to false debuginfo.
>
> If gcc does not support attribute ifunc, the old approach for generating
> ifunc'ed symbols is used. Then the debug-information is false. Thus it is
> recommended to use a gcc with indirect function support (See notes in INSTALL).
> After this patch-series these inline assemblies for ifunc-handling are not
> scattered in multiple files but are used only indirect via ifunc-macros
> and can simply removed in libc-symbols.h in future.
>
> If glibc is configured with --enable-multi-arch and gcc does not support
> attribute ifunc, a configure warning is dumped!
>
> This NEWS entry will be added:
> * For multi-arch support it is recommended to use a GCC with gnu-indirect-function
>   support as it is used to generate ifunc'ed symbols with correct
>   debug-information. This support can either be enabled by configuring GCC with
>   '--enable-gnu-indirect-function' or by enabling it by default by setting
>   'default_gnu_indirect_function' variable for a particular architecture in
>   gcc source file 'gcc/config.gcc'.
>
> ChangeLog:
>
> 	* config.h.in (HAVE_GCC_IFUNC): New undef.
> 	* configure.ac: Add check if gcc supports attribute ifunc feature.
> 	* configure: Regenerated.
> 	* manual/install.texi: Add recommendation for gcc with
> 	indirect-function support.
> 	* INSTALL: Regenerated.

Hi,

PING.

Here is the current status of the patchset:
-"[PATCH v3 1/9] Add configure check to test if gcc supports attribute 
ifunc.":
ok from Florian.

-"[PATCH v3 2/9] Use gcc attribute ifunc in libc_ifunc macro instead of 
inline assembly due to false debuginfo.":
partial ok from Paul. Paul, are the redirection of the f/l variants of 
__finite and others ok as they are needed (see my previous answer)?
PING: ifunc-macros in libc-symbols.h

-"[PATCH v3 3/9] s390: Refactor ifunc resolvers due to false debuginfo.":
PING.

-"[PATCH v3 4/9] i386, x86: Use libc_ifunc macro for time, gettimeofday.":
PING. Andreas, are the names for the redirection defines okay?

-"[PATCH v3 5/9] ppc: Use libc_ifunc macro for time, gettimeofday.":
ok from Paul.

-"[PATCH v3 6/9] Use libc_ifunc macro for clock_* symbols in librt.":
ok from Florian.

-"[PATCH v3 7/9] Use libc_ifunc macro for system in libpthread.":
ok from Florian.

-"[PATCH v3 8/9] Use libc_ifunc macro for vfork in libpthread.":
ok from Florian.

-"[PATCH v3 9/9] Use libc_ifunc macro for siglongjmp, longjmp in 
libpthread.":
PING.

Bye.
Stefan
  
Stefan Liebler Sept. 29, 2016, 1:50 p.m. UTC | #3
PING.


On 09/05/2016 09:12 AM, Stefan Liebler wrote:
> On 08/24/2016 04:04 PM, Stefan Liebler wrote:
>> This patch adds a configure check to test if gcc supports attribute
>> ifunc.
>> The support can either be enabled in <gcc-src>/gcc/config.gcc for one
>> architecture in general by setting default_gnu_indirect_function
>> variable to yes
>> or by configuring gcc with --enable-gnu-indirect-function.
>>
>> The next patch rewrites libc_ifunc macro to use gcc attribute ifunc
>> instead
>> of inline assembly to generate the IFUNC symbols due to false debuginfo.
>>
>> If gcc does not support attribute ifunc, the old approach for generating
>> ifunc'ed symbols is used. Then the debug-information is false. Thus it is
>> recommended to use a gcc with indirect function support (See notes in
>> INSTALL).
>> After this patch-series these inline assemblies for ifunc-handling are
>> not
>> scattered in multiple files but are used only indirect via ifunc-macros
>> and can simply removed in libc-symbols.h in future.
>>
>> If glibc is configured with --enable-multi-arch and gcc does not support
>> attribute ifunc, a configure warning is dumped!
>>
>> This NEWS entry will be added:
>> * For multi-arch support it is recommended to use a GCC with
>> gnu-indirect-function
>>   support as it is used to generate ifunc'ed symbols with correct
>>   debug-information. This support can either be enabled by configuring
>> GCC with
>>   '--enable-gnu-indirect-function' or by enabling it by default by
>> setting
>>   'default_gnu_indirect_function' variable for a particular
>> architecture in
>>   gcc source file 'gcc/config.gcc'.
>>
>> ChangeLog:
>>
>>     * config.h.in (HAVE_GCC_IFUNC): New undef.
>>     * configure.ac: Add check if gcc supports attribute ifunc feature.
>>     * configure: Regenerated.
>>     * manual/install.texi: Add recommendation for gcc with
>>     indirect-function support.
>>     * INSTALL: Regenerated.
>
> Hi,
>
> PING.
>
> Here is the current status of the patchset:
> -"[PATCH v3 1/9] Add configure check to test if gcc supports attribute
> ifunc.":
> ok from Florian.
>
> -"[PATCH v3 2/9] Use gcc attribute ifunc in libc_ifunc macro instead of
> inline assembly due to false debuginfo.":
> partial ok from Paul. Paul, are the redirection of the f/l variants of
> __finite and others ok as they are needed (see my previous answer)?
> PING: ifunc-macros in libc-symbols.h
>
> -"[PATCH v3 3/9] s390: Refactor ifunc resolvers due to false debuginfo.":
> PING.
>
> -"[PATCH v3 4/9] i386, x86: Use libc_ifunc macro for time, gettimeofday.":
> PING. Andreas, are the names for the redirection defines okay?
>
> -"[PATCH v3 5/9] ppc: Use libc_ifunc macro for time, gettimeofday.":
> ok from Paul.
>
> -"[PATCH v3 6/9] Use libc_ifunc macro for clock_* symbols in librt.":
> ok from Florian.
>
> -"[PATCH v3 7/9] Use libc_ifunc macro for system in libpthread.":
> ok from Florian.
>
> -"[PATCH v3 8/9] Use libc_ifunc macro for vfork in libpthread.":
> ok from Florian.
>
> -"[PATCH v3 9/9] Use libc_ifunc macro for siglongjmp, longjmp in
> libpthread.":
> PING.
>
> Bye.
> Stefan
>
  
Stefan Liebler Oct. 7, 2016, 9:18 a.m. UTC | #4
Hi,

as all patches are acked I've pushed the series.
I also opened the bug "Bug 77894 - Enable GNU indirect function support 
by default as it will be used in glibc."
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77894) against gcc and 
sent a note to the distribution maintainers listed in 
https://sourceware.org/glibc/wiki/MAINTAINERS#Distribution_Maintainers.

Thanks.
Stefan

On 08/24/2016 04:04 PM, Stefan Liebler wrote:
> This patch adds a configure check to test if gcc supports attribute ifunc.
> The support can either be enabled in <gcc-src>/gcc/config.gcc for one
> architecture in general by setting default_gnu_indirect_function variable to yes
> or by configuring gcc with --enable-gnu-indirect-function.
>
> The next patch rewrites libc_ifunc macro to use gcc attribute ifunc instead
> of inline assembly to generate the IFUNC symbols due to false debuginfo.
>
> If gcc does not support attribute ifunc, the old approach for generating
> ifunc'ed symbols is used. Then the debug-information is false. Thus it is
> recommended to use a gcc with indirect function support (See notes in INSTALL).
> After this patch-series these inline assemblies for ifunc-handling are not
> scattered in multiple files but are used only indirect via ifunc-macros
> and can simply removed in libc-symbols.h in future.
> > ---
>  INSTALL             |  8 ++++++++

> If glibc is configured with --enable-multi-arch and gcc does not support
> attribute ifunc, a configure warning is dumped!
>
> This NEWS entry will be added:
> * For multi-arch support it is recommended to use a GCC with gnu-indirect-function
>   support as it is used to generate ifunc'ed symbols with correct
>   debug-information. This support can either be enabled by configuring GCC with
>   '--enable-gnu-indirect-function' or by enabling it by default by setting
>   'default_gnu_indirect_function' variable for a particular architecture in
>   gcc source file 'gcc/config.gcc'.
>
> ChangeLog:
>
> 	* config.h.in (HAVE_GCC_IFUNC): New undef.
> 	* configure.ac: Add check if gcc supports attribute ifunc feature.
> 	* configure: Regenerated.
> 	* manual/install.texi: Add recommendation for gcc with
> 	indirect-function support.
> 	* INSTALL: Regenerated.
  

Patch

diff --git a/INSTALL b/INSTALL
index ec3445f..1a67891 100644
--- a/INSTALL
+++ b/INSTALL
@@ -359,6 +359,14 @@  build the GNU C Library:
      better code.  As of release time, GCC 5.3 is the newest compiler
      verified to work to build the GNU C Library.
 
+     For multi-arch support it is recommended to use a GCC with
+     gnu-indirect-function support as it is used to generate ifunc'ed
+     symbols with correct debug-information.  This support can either be
+     enabled by configuring GCC with '--enable-gnu-indirect-function' or
+     by enabling it by default by setting
+     'default_gnu_indirect_function' variable for a particular
+     architecture in gcc source file 'gcc/config.gcc'.
+
      You can use whatever compiler you like to compile programs that use
      the GNU C Library.
 
diff --git a/config.h.in b/config.h.in
index 856ef6a..9f5c5ff 100644
--- a/config.h.in
+++ b/config.h.in
@@ -171,6 +171,9 @@ 
 /* Define to 1 if STT_GNU_IFUNC support actually works.  */
 #define HAVE_IFUNC 0
 
+/* Define if gcc supports attribute ifunc.  */
+#undef HAVE_GCC_IFUNC
+
 /* Define if the linker defines __ehdr_start.  */
 #undef HAVE_EHDR_START
 
diff --git a/configure b/configure
index 17625e1..8ffc2b5 100755
--- a/configure
+++ b/configure
@@ -3914,6 +3914,36 @@  fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_ld_gnu_indirect_function" >&5
 $as_echo "$libc_cv_ld_gnu_indirect_function" >&6; }
 
+# Check if gcc supports attribute ifunc as it is used in libc_ifunc macro.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gcc attribute ifunc support" >&5
+$as_echo_n "checking for gcc attribute ifunc support... " >&6; }
+if ${libc_cv_gcc_indirect_function+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat > conftest.c <<EOF
+extern int func (int);
+int used_func (int a)
+{
+  return a;
+}
+static void *resolver ()
+{
+  return &used_func;
+}
+extern __typeof (func) func __attribute__ ((ifunc ("resolver")));
+EOF
+libc_cv_gcc_indirect_function=no
+if ${CC-cc} -c conftest.c -o conftest.o 1>&5 \
+   2>&5 ; then
+  if $READELF -s conftest.o | grep IFUNC >/dev/null 2>&5; then
+    libc_cv_gcc_indirect_function=yes
+  fi
+fi
+rm -f conftest*
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_gcc_indirect_function" >&5
+$as_echo "$libc_cv_gcc_indirect_function" >&6; }
+
 if test x"$libc_cv_ld_gnu_indirect_function" != xyes; then
   if test x"$multi_arch" = xyes; then
     as_fn_error $? "--enable-multi-arch support requires assembler and linker support" "$LINENO" 5
@@ -3921,6 +3951,13 @@  if test x"$libc_cv_ld_gnu_indirect_function" != xyes; then
     multi_arch=no
   fi
 fi
+if test x"$libc_cv_gcc_indirect_function" != xyes &&
+   test x"$multi_arch" = xyes; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: --enable-multi-arch support recommends a gcc with gnu-indirect-function support.
+Please use a gcc which supports it by default or configure gcc with --enable-gnu-indirect-function" >&5
+$as_echo "$as_me: WARNING: --enable-multi-arch support recommends a gcc with gnu-indirect-function support.
+Please use a gcc which supports it by default or configure gcc with --enable-gnu-indirect-function" >&2;}
+fi
 multi_arch_d=
 if test x"$multi_arch" != xno; then
   multi_arch_d=/multiarch
@@ -6504,6 +6541,11 @@  if test x"$libc_cv_ld_gnu_indirect_function" = xyes; then
 
 fi
 
+if test x"$libc_cv_gcc_indirect_function" = xyes; then
+  $as_echo "#define HAVE_GCC_IFUNC 1" >>confdefs.h
+
+fi
+
 # This is far from the AC_ARG_ENABLE that sets it so that a sysdeps
 # configure fragment can override the value to prevent this AC_DEFINE.
 
diff --git a/configure.ac b/configure.ac
index 33bcd62..643002f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -634,6 +634,30 @@  if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS \
 fi
 rm -f conftest*])
 
+# Check if gcc supports attribute ifunc as it is used in libc_ifunc macro.
+AC_CACHE_CHECK([for gcc attribute ifunc support],
+	       libc_cv_gcc_indirect_function, [dnl
+cat > conftest.c <<EOF
+extern int func (int);
+int used_func (int a)
+{
+  return a;
+}
+static void *resolver ()
+{
+  return &used_func;
+}
+extern __typeof (func) func __attribute__ ((ifunc ("resolver")));
+EOF
+libc_cv_gcc_indirect_function=no
+if ${CC-cc} -c conftest.c -o conftest.o 1>&AS_MESSAGE_LOG_FD \
+   2>&AS_MESSAGE_LOG_FD ; then
+  if $READELF -s conftest.o | grep IFUNC >/dev/null 2>&AS_MESSAGE_LOG_FD; then
+    libc_cv_gcc_indirect_function=yes
+  fi
+fi
+rm -f conftest*])
+
 if test x"$libc_cv_ld_gnu_indirect_function" != xyes; then
   if test x"$multi_arch" = xyes; then
     AC_MSG_ERROR([--enable-multi-arch support requires assembler and linker support])
@@ -641,6 +665,11 @@  if test x"$libc_cv_ld_gnu_indirect_function" != xyes; then
     multi_arch=no
   fi
 fi
+if test x"$libc_cv_gcc_indirect_function" != xyes &&
+   test x"$multi_arch" = xyes; then
+  AC_MSG_WARN([--enable-multi-arch support recommends a gcc with gnu-indirect-function support.
+Please use a gcc which supports it by default or configure gcc with --enable-gnu-indirect-function])
+fi
 multi_arch_d=
 if test x"$multi_arch" != xno; then
   multi_arch_d=/multiarch
@@ -1770,6 +1799,10 @@  if test x"$libc_cv_ld_gnu_indirect_function" = xyes; then
   AC_DEFINE(HAVE_IFUNC)
 fi
 
+if test x"$libc_cv_gcc_indirect_function" = xyes; then
+  AC_DEFINE(HAVE_GCC_IFUNC)
+fi
+
 # This is far from the AC_ARG_ENABLE that sets it so that a sysdeps
 # configure fragment can override the value to prevent this AC_DEFINE.
 AC_SUBST(use_nscd)
diff --git a/manual/install.texi b/manual/install.texi
index 79ee45f..d738ee0 100644
--- a/manual/install.texi
+++ b/manual/install.texi
@@ -402,6 +402,13 @@  the newest version of the compiler that is known to work for building
 release time, GCC 5.3 is the newest compiler verified to work to build
 @theglibc{}.
 
+For multi-arch support it is recommended to use a GCC with gnu-indirect-function
+support as it is used to generate ifunc'ed symbols with correct
+debug-information. This support can either be enabled by configuring GCC with
+@samp{--enable-gnu-indirect-function} or by enabling it by default by setting
+@samp{default_gnu_indirect_function} variable for a particular architecture in
+gcc source file @file{gcc/config.gcc}.
+
 You can use whatever compiler you like to compile programs that use
 @theglibc{}.