This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[lto, build] Provide elf_getshdrstrndx replacement
- From: Rainer Orth <ro at CeBiTec dot Uni-Bielefeld dot DE>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 13 Apr 2010 23:14:11 +0200
- Subject: [lto, build] Provide elf_getshdrstrndx replacement
Since this patch
[lto] Update call to elf_getshstrndx
http://gcc.gnu.org/ml/gcc-patches/2009-09/msg00366.html
LTO support depends on elf_getshdrstrndx in libelf. While recent
versions of Solaris 11 include it, older ones only had elf_getshstrndx.
Unfortunately, there exist two variants of the latter function, as
explained in the PSARC case to introduce elf_getshdrstrndx:
PSARC 2009/363 replace elf_getphnum, elf_getshnum, and elf_getshstrndx
http://arc.opensolaris.org/caselog/PSARC/2009/363/
* the gABI-specified one with the same signature as elf_getshdrstrndx, and
* the Solaris 2 one, which has different return codes by mistake
The following patch checks if elf_getshdrstrndx is present, but falls
back to elf_getshstrndx if not and detects which variant is present.
The configure test needs to be split into two parts:
* In toplevel configure.ac, I only check if either elf_getshdrstrndx or
elf_getshstrndx is present and continue to enable LTO if so.
* In gcc/configure.ac, I repeat the check for both functions and also
detect the flavor of elf_getshstrndx. This works by calling the
function with a NULL Elf *, which is an error condition, and checking
the error code. This is necessary since there's no header created by
toplevel configure.ac which could pass that information into the gcc
subdir.
Instead of cluttering lto-elf.c with ifdefs in the single location
elf_getshdrstrndx is called, I instead provide a replacement if necessary.
Bootstrapped without regressions on i386-pc-solaris2.10 (which doesn't
enable LTO without this patch) and i386-pc-solaris2.11 (which does,
given a sufficiently recent vintage of Solaris 11). There are still
some LTO testsuite failures on both platforms, which I'll investigate
subsequently.
Ok for mainline and the 4.5 branch after 4.5.0 is released?
Rainer
--
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University
2010-04-10 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
toplevel:
* configure.ac: Check for elf_getshdrstrndx or elf_getshstrndx
separately.
* configure: Regenerate.
gcc:
* configure.ac: Check for elf_getshdrstrndx or elf_getshstrndx
flavor.
* configure: Regenerate.
* config.in: Regenerate.
gcc/lto:
* lto-elf.c [!HAVE_ELF_GETSHDRSTRNDX] (elf_getshdrstrndx): New
function.
diff -r f2548f44fe26 configure.ac
--- a/configure.ac Sat Apr 10 16:56:51 2010 +0200
+++ b/configure.ac Sat Apr 10 17:16:13 2010 +0200
@@ -1735,7 +1735,6 @@
elf_nextscn (0, 0);
elf_strptr (0, 0, 0);
elf_getident (0, 0);
- elf_getshdrstrndx (0, 0);
elf_begin (0, 0, 0);
elf_ndxscn (0);
elf_end (0);
@@ -1744,6 +1743,27 @@
[AC_MSG_RESULT([no]); enable_lto=no; libelflibs= ; libelfinc= ]
)
+ # Check for elf_getshdrstrndx or elf_getshstrndx. The latter's flavor
+ # is determined in gcc/configure.ac.
+ if test x"$enable_lto" = x"yes" ; then
+ AC_MSG_CHECKING([for elf_getshdrstrndx])
+ AC_TRY_LINK(
+ [#include <libelf.h>],[
+ elf_getshdrstrndx (0, 0);
+ ],
+ [AC_MSG_RESULT([yes]);],
+ [AC_MSG_RESULT([no]);
+ AC_MSG_CHECKING([for elf_getshstrndx])
+ AC_TRY_LINK(
+ [#include <libelf.h>],[
+ elf_getshstrndx (0, 0);
+ ],
+ [AC_MSG_RESULT([yes]);],
+ [AC_MSG_RESULT([no]); enable_lto=no; libelflibs= ; libelfinc= ]
+ )]
+ )
+ fi
+
# If we couldn't enable LTO and the user forced it, emit an error.
if test x"$enable_lto" = x"no" \
&& test x"$default_enable_lto" != x"yes" ; then
diff -r f2548f44fe26 gcc/configure.ac
--- a/gcc/configure.ac Sat Apr 10 16:56:51 2010 +0200
+++ b/gcc/configure.ac Sat Apr 10 17:16:13 2010 +0200
@@ -1024,6 +1024,22 @@
gettimeofday mbstowcs wcswidth mmap mincore setlocale \
gcc_UNLOCKED_FUNCS)
+save_CPPFLAGS="$CPPFLAGS"
+save_LIBS="$LIBS"
+LIBS="$LIBS $LIBELFLIBS"
+AC_CHECK_FUNCS(elf_getshdrstrndx,,
+ [AC_CHECK_FUNCS(elf_getshstrndx,
+ [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdlib.h>
+#include <libelf.h>
+int main()
+{
+ return elf_getshstrndx (NULL, 0) == 0;
+}]]), AC_DEFINE(HAVE_ELF_GETSHSTRNDX_GABI, 1,
+ [Define if elf_getshstrndx has gABI conformant return values.])])])]
+ )
+LIBS="$save_LIBS"
+CPPFLAGS="$save_CPPFLAGS"
+
if test x$ac_cv_func_mbstowcs = xyes; then
AC_CACHE_CHECK(whether mbstowcs works, gcc_cv_func_mbstowcs_works,
[ AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdlib.h>
diff -r f2548f44fe26 gcc/lto/lto-elf.c
--- a/gcc/lto/lto-elf.c Sat Apr 10 16:56:51 2010 +0200
+++ b/gcc/lto/lto-elf.c Sat Apr 10 17:16:13 2010 +0200
@@ -455,6 +455,22 @@
DEFINE_VALIDATE_EHDR (64)
+#ifndef HAVE_ELF_GETSHDRSTRNDX
+/* elf_getshdrstrndx replacement for systems that lack it, but provide
+ either the gABI conformant or Solaris 2 variant of elf_getshstrndx
+ instead. */
+
+static int
+elf_getshdrstrndx (Elf *elf, size_t *dst)
+{
+#ifdef HAVE_ELF_GETSHSTRNDX_GABI
+ return elf_getshstrndx (elf, dst);
+#else
+ return elf_getshstrndx (elf, dst) ? 0 : -1;
+#endif
+}
+#endif
+
/* Validate's ELF_FILE's executable header and, if cached_file_attrs is
uninitialized, caches the results. Also records the section header string
table's section index. Returns true on success or false on failure. */