[lto] Add --enable-lto and --with-libelf
Diego Novillo
dnovillo@google.com
Wed May 20 19:48:00 GMT 2009
This patch fixes a long standing wart in the branch. LTO is not
really a language from the user's perspective, so having to use
--enable-languages to enable it is odd.
Additionally, the dependency on libelf has always required using
libelf.h in system headers or hacking CPPFLAGS/BOOT_LDFLAGS to
get it from other places.
With this patch, the compiler can now enable LTO functionality
automatically (if it detects a working libelf), or it can be
requested with --enable-lto.
If --enable-lto is used and no there isn't a working libelf.h,
configure emits an error. If --with-libelf is used and/or a
working libelf.h is found in the system paths, then LTO is
enabled automatically.
Finally, if LTO has been disabled, using -flto/-fwhopr produces
an error at runtime. The testsuite uses this to determine
whether to run the LTO tests.
Bootstrapped and tested on hosts with a system libelf.h and hosts
with a libelf.h in a different directory.
Paolo, could you review the changes so I can make fixes in the
branch before they are merged to mainline?
Thanks. Diego.
ChangeLog.lto:
* configure.ac (host_libs): Remove lto-plugin.
Add --enable-lto.
Add --with-libelf, --with-libelf-include and --with-libelf-lib.
If --enable-lto is used, add 'lto' to new_enable_languages.
If --enable-lto is used and gold is enabled, add
lto-plugin to configdirs.
* Makefile.tpl (HOST_EXPORTS): Add LIBELFLIBS and LIBELFINC.
(HOST_LIBELFLIBS): Define.
(HOST_LIBELFINC): Define.
* configure: Regenerate.
* Makefile.in: Regenerate.
gcc/ChangeLog.lto
* doc/install.texi: Document libelf requirements,
--with-libelf and --enable-lto.
* configure: Regenerate.
* aclocal.m4: Do not include ../config/libelf.m4.
* config.in: Regenerate.
* configure.ac: Remove calls to AC_CHECK_LIBELF and
AC_CHECK_GELF.
If LTO is enabled, define ENABLE_LTO.
Call AC_ARG_VAR for LIBELFLIBS and LIBELFINC.
* c-opts.c (c_common_post_options): Issue an error if
ENABLE_LTO is false and -flto or -fwhopr are used.
* Makefile.in (LIBELFLIBS): Define.
(LIBELFINC): Define.
(BACKENDLIBS): Add LIBELFLIB.
(INCLUDES): Add LIBELFINC.
* collect2.c (main): Issue an error if ENABLE_LTO is
false and -flto or -fwhopr are used.
gcc/lto/ChangeLog
* lto-elf.c: Always include <gelf.h>.
* config-lang.in (target_libs): Remove.
(build_by_default): Set to no.
gcc/testsuite/ChangeLog.lto
* gcc.dg/lto/lto.exp: Call check_effective_target_lto.
* g++.dg/lto/lto.exp: Call check_effective_target_lto.
lto-plugin/ChangeLog
* configure: Regenerate.
* Makefile.in: Regenerate.
* configure.ac: Remove call to AC_CHECK_GELF.
Call AC_ARG_VAR for LIBELFLIBS and LIBELFINC.
* acinclude.m4: Do not include ../config/libelf.m4
* Makefile.am (LIBELFLIBS): Define.
(LIBELFINC): Define.
(AM_CPPFLAGS): Add $(LIBELFINC).
(ltosymtab_LDADD): Add $(LIBELFLIBS).
(liblto_plugin_la_LIBADD): Add $(LIBELFLIBS)
* lto-plugin.c: Always include <gelf.h>
* lto-symtab.c: Likewise.
config/ChangeLog.lto
* libelf.m4: Remove.
Index: gcc/doc/install.texi
===================================================================
--- gcc/doc/install.texi (revision 147597)
+++ gcc/doc/install.texi (working copy)
@@ -344,6 +344,15 @@ not installed in your default library se
Necessary to build libgcj, the GCJ runtime.
+@item libelf version 0.8.10
+
+Necessary to build link-time optimization (LTO) support. It can be
+downloaded from @uref{http://www.mr511.de/software/libelf-0.8.10.tar.gz},
+though it is commonly available in several systems.
+
+The @option{--with-libelf} configure option should be used if libelf is
+not installed in your default library search patch.
+
@end table
@@ -1814,6 +1823,10 @@ Use the @code{WCHAR} and Win32 W functio
add @code{-lunicows} to @file{libgcj.spec}. The built executables will
only run on Microsoft Windows NT and above.
@end table
+
+@item --enable-lto
+Enable link-time optimization (LTO). This is enabled by default if a
+working libelf implemetnation is found (see @option{--with-libelf}).
@end table
@subsubheading AWT-Specific Options
Index: gcc/testsuite/gcc.dg/lto/lto.exp
===================================================================
--- gcc/testsuite/gcc.dg/lto/lto.exp (revision 147597)
+++ gcc/testsuite/gcc.dg/lto/lto.exp (working copy)
@@ -41,6 +41,11 @@ lto_init
# with other lto tests running at the same time.
set sid "c_lto"
+# If LTO has not been enabled, bail.
+if { ![check_effective_target_lto] } {
+ return
+}
+
# Main loop.
foreach src [lsort [find $srcdir/$subdir *_0.c]] {
# If we're only testing specific files and this isn't one of them, skip it.
Index: gcc/testsuite/g++.dg/lto/lto.exp
===================================================================
--- gcc/testsuite/g++.dg/lto/lto.exp (revision 147597)
+++ gcc/testsuite/g++.dg/lto/lto.exp (working copy)
@@ -42,6 +42,11 @@ lto_init
# with other lto tests running at the same time.
set sid "cp_lto"
+# If LTO has not been enabled, bail.
+if { ![check_effective_target_lto] } {
+ return
+}
+
# Main loop.
foreach src [lsort [find $srcdir/$subdir *_0.C]] {
# If we're only testing specific files and this isn't one of them, skip it.
Index: gcc/aclocal.m4
===================================================================
--- gcc/aclocal.m4 (revision 147597)
+++ gcc/aclocal.m4 (working copy)
@@ -105,7 +105,6 @@ m4_include([../config/override.m4])
m4_include([../config/progtest.m4])
m4_include([../config/unwind_ipinfo.m4])
m4_include([../config/warnings.m4])
-m4_include([../config/libelf.m4])
m4_include([../libtool.m4])
m4_include([../ltoptions.m4])
m4_include([../ltsugar.m4])
Index: gcc/configure.ac
===================================================================
--- gcc/configure.ac (revision 147597)
+++ gcc/configure.ac (working copy)
@@ -931,9 +931,6 @@ AC_CHECK_HEADERS(limits.h stddef.h strin
AC_CHECK_HEADER(thread.h, [have_thread_h=yes], [have_thread_h=])
AC_CHECK_HEADER(pthread.h, [have_pthread_h=yes], [have_pthread_h=])
-AC_CHECK_LIBELF
-AC_CHECK_GELF
-
# These tests can't be done till we know if we have limits.h.
gcc_AC_C_CHAR_BIT
AC_C_BIGENDIAN
@@ -3842,6 +3839,10 @@ changequote([,])dnl
all_compilers="$all_compilers $compilers"
all_outputs="$all_outputs $outputs"
all_gtfiles="$all_gtfiles [[$subdir]] $gtfiles"
+
+ if test x"$language" = x"lto" ; then
+ AC_DEFINE(ENABLE_LTO, 1, [Define to enable LTO support.])
+ fi
done
# Pick up gtfiles for c
@@ -4028,6 +4029,12 @@ if test "x${CLOOGLIBS}" != "x" ; then
AC_DEFINE(HAVE_cloog, 1, [Define if cloog is in use.])
fi
+AC_ARG_VAR(LIBELFLIBS,[How to link libelf])
+AC_ARG_VAR(LIBELFINC,[How to find libelf include files])
+if test "x${LIBELFLIBS}" != "x" ; then
+ AC_DEFINE(HAVE_libelf, 1, [Define if libelf is in use.])
+fi
+
# Check for plugin support
AC_ARG_ENABLE(plugin,
[ --enable-plugin enable plugin support],
Index: gcc/c-opts.c
===================================================================
--- gcc/c-opts.c (revision 147597)
+++ gcc/c-opts.c (working copy)
@@ -1026,21 +1026,25 @@ c_common_post_options (const char **pfil
C_COMMON_OVERRIDE_OPTIONS;
#endif
- /* Reconcile -flto and -fwhopr. Set additional flags as appropriate and
- check option consistency. */
- if (flag_lto && flag_whopr)
- error ("-flto and -fwhopr are mutually exclusive");
-
if (flag_lto || flag_whopr)
{
+#ifdef ENABLE_LTO
flag_generate_lto = 1;
/* When generating IL, do not operate in whole-program mode.
Otherwise, symbols will be privatized too early, causing link
errors later. */
flag_whole_program = 0;
+#else
+ error ("LTO support has not been enabled in this configuration");
+#endif
}
+ /* Reconcile -flto and -fwhopr. Set additional flags as appropriate and
+ check option consistency. */
+ if (flag_lto && flag_whopr)
+ error ("-flto and -fwhopr are mutually exclusive");
+
/* Excess precision other than "fast" requires front-end
support. */
if (c_dialect_cxx ())
Index: gcc/lto/lto-elf.c
===================================================================
--- gcc/lto/lto-elf.c (revision 147597)
+++ gcc/lto/lto-elf.c (working copy)
@@ -24,15 +24,7 @@ Boston, MA 02110-1301, USA. */
#include "coretypes.h"
#include "toplev.h"
#include "lto.h"
-#ifdef HAVE_GELF_H
-# include <gelf.h>
-#else
-# if defined(HAVE_LIBELF_GELF_H)
-# include <libelf/gelf.h>
-# else
-# error "gelf.h not available"
-# endif
-#endif
+#include <gelf.h>
#include "tm.h"
#include "libiberty.h"
#include "ggc.h"
Index: gcc/lto/config-lang.in
===================================================================
--- gcc/lto/config-lang.in (revision 147597)
+++ gcc/lto/config-lang.in (working copy)
@@ -23,6 +23,11 @@ language="lto"
compilers="lto1\$(exeext) ltrans-driver\$(exeext)"
stagestuff="lto1\$(exeext)"
-target_libs="lto-plugin"
-
gtfiles="\$(srcdir)/lto/lto-tree.h \$(srcdir)/lto/lto-lang.c \$(srcdir)/lto/lto.c"
+
+# LTO is a special front end. From a user's perspective it is not
+# really a language, but a middle end feature. However, the GIMPLE
+# reading module is implemented as a front end, so enabling LTO means
+# enabling this "language". To enable LTO functionality, use
+# --enable-lto when configuring the compiler.
+build_by_default=no
Index: gcc/Makefile.in
===================================================================
--- gcc/Makefile.in (revision 147597)
+++ gcc/Makefile.in (working copy)
@@ -283,6 +283,10 @@ PPLINC = @PPLINC@
CLOOGLIBS = @CLOOGLIBS@
CLOOGINC = @CLOOGINC@
+# How to find libelf
+LIBELFLIBS = @LIBELFLIBS@
+LIBELFINC = @LIBELFINC@
+
# Libs and linker option needed for plugin support
PLUGINLIBS = @pluginlibs@
@@ -926,7 +930,8 @@ BUILD_LIBDEPS= $(BUILD_LIBIBERTY)
# How to link with both our special library facilities
# and the system's installed libraries.
LIBS = @LIBS@ $(CPPLIB) $(LIBINTL) $(LIBICONV) $(LIBIBERTY) $(LIBDECNUMBER)
-BACKENDLIBS = $(CLOOGLIBS) $(PPLLIBS) $(GMPLIBS) $(PLUGINLIBS) $(ZLIB)
+BACKENDLIBS = $(CLOOGLIBS) $(PPLLIBS) $(GMPLIBS) $(PLUGINLIBS) $(ZLIB) \
+ $(LIBELFLIB)
# Any system libraries needed just for GNAT.
SYSLIBS = @GNAT_LIBEXC@
@@ -955,7 +960,7 @@ BUILD_ERRORS = build/errors.o
INCLUDES = -I. -I$(@D) -I$(srcdir) -I$(srcdir)/$(@D) \
-I$(srcdir)/../include @INCINTL@ \
$(CPPINC) $(GMPINC) $(DECNUMINC) \
- $(PPLINC) $(CLOOGINC)
+ $(PPLINC) $(CLOOGINC) $(LIBELFINC)
.c.o:
$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $< $(OUTPUT_OPTION)
Index: gcc/collect2.c
===================================================================
--- gcc/collect2.c (revision 147597)
+++ gcc/collect2.c (working copy)
@@ -1416,12 +1416,17 @@ main (int argc, char **argv)
break;
case 'f':
- if (strcmp (arg, "-flto") == 0 || strcmp (arg, "-fwhopr") == 0)
- {
- /* Do not pass LTO flag to the linker. */
- ld1--;
- ld2--;
- }
+ if (strcmp (arg, "-flto") == 0 || strcmp (arg, "-fwhopr") == 0)
+ {
+#ifdef ENABLE_LTO
+ /* Do not pass LTO flag to the linker. */
+ ld1--;
+ ld2--;
+#else
+ error ("LTO support has not been enabled in this "
+ "configuration");
+#endif
+ }
break;
case 'l':
Index: configure.ac
===================================================================
--- configure.ac (revision 147493)
+++ configure.ac (working copy)
@@ -158,7 +158,7 @@ build_tools="build-texinfo build-byacc b
# these libraries are used by various programs built for the host environment
#
-host_libs="intl mmalloc libiberty opcodes bfd readline tcl tk itcl libgui zlib libcpp libdecnumber gmp mpfr ppl cloog libiconv lto-plugin"
+host_libs="intl mmalloc libiberty opcodes bfd readline tcl tk itcl libgui zlib libcpp libdecnumber gmp mpfr ppl cloog libiconv"
# these tools are built for the host environment
# Note, the powerpc-eabi build depends on sim occurring before gdb in order to
@@ -1450,6 +1450,79 @@ fi
AC_SUBST(clooglibs)
AC_SUBST(clooginc)
+# Check for LTO support.
+AC_ARG_ENABLE(lto,
+[ --enable-lto enable link time optimization support],
+enable_lto=$enableval,
+enable_lto=yes; default_enable_lto=yes)
+
+if test x"$enable_lto" = x"yes" ; then
+ # Make sure that libelf.h and gelf.h are available.
+ AC_ARG_WITH(libelf, [ --with-libelf=PATH Specify prefix directory for the installed libelf package
+ Equivalent to --with-libelf-include=PATH/include
+ plus --with-libelf-lib=PATH/lib])
+
+ AC_ARG_WITH(libelf_include, [ --with-libelf-include=PATH Specify directory for installed libelf include files])
+
+ AC_ARG_WITH(libelf_lib, [ --with-libelf-lib=PATH Specify the directory for the installed libelf library])
+
+ case $with_libelf in
+ no)
+ libelflibs=
+ libelfinc=
+ ;;
+ *)
+ libelflibs="-L$with_libelf/lib -lelf"
+ libelfinc="-I$with_libelf/include"
+ LIBS="$libelflibs $LIBS"
+ ;;
+ esac
+ if test "x$with_libelf_include" != x; then
+ libelfinc="-I$with_libelf_include"
+ fi
+ if test "x$with_libelf_lib" != x; then
+ libelflibs="-L$with_libelf_lib -lelf"
+ LIBS="$libelflibs $LIBS"
+ fi
+ if test "x$with_libelf$with_libelf_include$with_libelf_lib" = x && test -d ${srcdir}/libelf; then
+ libelflibs='-L$$r/$(HOST_SUBDIR)/libelf/.libs -L$$r/$(HOST_SUBDIR)/libelf/_libs -lelf '
+ libelfinc='-I$$r/$(HOST_SUBDIR)/libelf/include -I$$s/libelf/include'
+ LIBS="$libelflibs $LIBS"
+ fi
+
+ # Flags needed for libelf.
+ AC_SUBST(libelflibs)
+ AC_SUBST(libelfinc)
+
+ saved_CFLAGS="$CFLAGS"
+ saved_CPPFLAGS="$CPPFLAGS"
+
+ CFLAGS="$CFLAGS $libelfinc"
+ CPPFLAGS="$CPPFLAGS $libelfinc"
+
+ AC_CHECK_HEADERS(libelf.h, [have_libelf_h=yes])
+ AC_CHECK_HEADERS(gelf.h, [have_gelf_h=yes])
+
+ CFLAGS="$saved_CFLAGS"
+ CPPFLAGS="$saved_CPPFLAGS"
+
+ if test x"$have_libelf_h" != x"yes" ; then
+ if test x"$default_enable_lto" != x"yes" ; then
+ AC_MSG_ERROR([LTO support requires libelf.h.])
+ else
+ enable_lto=no
+ fi
+ fi
+
+ if test x"$have_gelf_h" != x"yes" ; then
+ if test x"$default_enable_lto" != x"yes" ; then
+ AC_MSG_ERROR([LTO support requires gelf.h.])
+ else
+ enable_lto=no
+ fi
+ fi
+fi
+
# By default, C is the only stage 1 language.
stage1_languages=,c,
@@ -1515,6 +1588,16 @@ if test -d ${srcdir}/gcc; then
done
new_enable_languages=,c,
+
+ # If LTO is enabled, add the LTO front end.
+ if test "$enable_lto" = "yes" ; then
+ new_enable_languages="${new_enable_languages}lto,"
+ if test "${ENABLE_GOLD}" = "yes" ; then
+ configdirs="$configdirs lto-plugin"
+ fi
+ configdirs="$configdirs lto-plugin"
+ fi
+
missing_languages=`echo ",$enable_languages," | sed -e s/,all,/,/ -e s/,c,/,/ `
potential_languages=,c,
Index: Makefile.tpl
===================================================================
--- Makefile.tpl (revision 147493)
+++ Makefile.tpl (working copy)
@@ -204,6 +204,8 @@ HOST_EXPORTS = \
PPLINC="$(HOST_PPLINC)"; export PPLINC; \
CLOOGLIBS="$(HOST_CLOOGLIBS)"; export CLOOGLIBS; \
CLOOGINC="$(HOST_CLOOGINC)"; export CLOOGINC; \
+ LIBELFLIBS="$(HOST_LIBELFLIBS)" ; export LIBELFLIBS; \
+ LIBELFINC="$(HOST_LIBELFINC)" ; export LIBELFINC; \
@if gcc-bootstrap
$(RPATH_ENVVAR)=`echo "$(TARGET_LIB_PATH)$$$(RPATH_ENVVAR)" | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; export $(RPATH_ENVVAR); \
@endif gcc-bootstrap
@@ -272,6 +274,10 @@ HOST_PPLINC = @pplinc@
HOST_CLOOGLIBS = @clooglibs@
HOST_CLOOGINC = @clooginc@
+# Where to find libelf
+HOST_LIBELFLIBS = @libelflibs@
+HOST_LIBELFINC = @libelfinc@
+
# ----------------------------------------------
# Programs producing files for the BUILD machine
# ----------------------------------------------
Index: lto-plugin/configure.ac
===================================================================
--- lto-plugin/configure.ac (revision 147493)
+++ lto-plugin/configure.ac (working copy)
@@ -3,7 +3,8 @@ AC_INIT([LTO plugin for ld], 0.1,,[lto-p
GCC_TOPLEV_SUBDIRS
AM_INIT_AUTOMAKE([foreign])
AC_PROG_CC
-AC_CHECK_GELF
+AC_ARG_VAR(LIBELFLIBS,[How to link libelf])
+AC_ARG_VAR(LIBELFINC,[How to find libelf include files])
AM_PROG_LIBTOOL
AC_SUBST(target_noncanonical)
AC_CONFIG_FILES(Makefile)
Index: lto-plugin/acinclude.m4
===================================================================
--- lto-plugin/acinclude.m4 (revision 147493)
+++ lto-plugin/acinclude.m4 (working copy)
@@ -1,6 +1,5 @@
m4_include([../config/acx.m4])
m4_include([../lt~obsolete.m4])
-m4_include([../config/libelf.m4])
m4_include([../ltsugar.m4])
m4_include([../ltoptions.m4])
m4_include([../ltversion.m4])
Index: lto-plugin/Makefile.am
===================================================================
--- lto-plugin/Makefile.am (revision 147493)
+++ lto-plugin/Makefile.am (working copy)
@@ -1,20 +1,26 @@
+# Makefile.am is used by automake 1.9.6 to generate Makefile.in.
+
gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
target_noncanonical := @target_noncanonical@
libexecsubdir := $(libexecdir)/gcc/$(target_noncanonical)/$(gcc_version)
+# How to find libelf
+LIBELFLIBS = @LIBELFLIBS@
+LIBELFINC = @LIBELFINC@
+
AM_CPPFLAGS = -I$(top_srcdir)/../include -D_LARGEFILE_SOURCE \
- -D_FILE_OFFSET_BITS=64
+ -D_FILE_OFFSET_BITS=64 $(LIBELFINC)
AM_CFLAGS = -Wall -Werror
bin_PROGRAMS = ltosymtab
ltosymtab_SOURCES = lto-symtab.c $(top_srcdir)/../gcc/lto/common.c
-ltosymtab_LDADD = -ldl -lelf
+ltosymtab_LDADD = $(LIBELFLIBS) -ldl
#hack to use common.c in both targets
ltosymtab_CFLAGS = $(AM_CFLAGS)
libexecsub_LTLIBRARIES = liblto_plugin.la
liblto_plugin_la_SOURCES = lto-plugin.c $(top_srcdir)/../gcc/lto/common.c
-liblto_plugin_la_LIBADD = -lelf -L../libiberty/pic -liberty
+liblto_plugin_la_LIBADD = $(LIBELFLIBS) -L../libiberty/pic -liberty
Index: lto-plugin/lto-plugin.c
===================================================================
--- lto-plugin/lto-plugin.c (revision 147493)
+++ lto-plugin/lto-plugin.c (working copy)
@@ -30,8 +30,7 @@ Foundation, Inc., 51 Franklin Street - F
It also has 2 options of its own:
-debug: Print the command line used to run lto-wrapper.
-nop: Instead of running lto-wrapper, pass the original to the plugin. This
- only works if the input files are hybrid.
-*/
+ only works if the input files are hybrid. */
#include <assert.h>
#include <string.h>
@@ -47,15 +46,8 @@ Foundation, Inc., 51 Franklin Street - F
#include <stdbool.h>
#include <libiberty.h>
-#ifdef HAVE_GELF_H
-# include <gelf.h>
-#else
-# if defined(HAVE_LIBELF_GELF_H)
-# include <libelf/gelf.h>
-# else
-# error "gelf.h not available"
-# endif
-#endif
+/* The presence of gelf.h is checked by the toplevel configure script. */
+#include <gelf.h>
#include "plugin-api.h"
#include "../gcc/lto/common.h"
Index: lto-plugin/lto-symtab.c
===================================================================
--- lto-plugin/lto-symtab.c (revision 147493)
+++ lto-plugin/lto-symtab.c (working copy)
@@ -27,15 +27,8 @@ Foundation, Inc., 51 Franklin Street - F
#include "plugin-api.h"
#include "../gcc/lto/common.h"
-#ifdef HAVE_GELF_H
+/* The presence of gelf.h is checked by the toplevel configure script. */
# include <gelf.h>
-#else
-# if defined(HAVE_LIBELF_GELF_H)
-# include <libelf/gelf.h>
-# else
-# error "gelf.h not available"
-# endif
-#endif
static ld_plugin_claim_file_handler claim_file_handler;
static ld_plugin_all_symbols_read_handler all_symbols_read_handler;
Index: config/libelf.m4
===================================================================
--- config/libelf.m4 (revision 147493)
+++ config/libelf.m4 (working copy)
@@ -1,13 +0,0 @@
-# Check for ELF header. Prefer <libelf.h>, but fall back to
-# <libelf/libelf.h> if <libelf.h> is not available.
-AC_DEFUN([AC_CHECK_LIBELF],
-[
-AC_CHECK_HEADERS(libelf.h libelf/libelf.h, [break])
-])
-
-# Check for GELF header. Prefer <gelf.h>, but fall back to
-# <libelf/gelf.h> if <gelf.h> is not available.
-AC_DEFUN([AC_CHECK_GELF],
-[
-AC_CHECK_HEADERS(gelf.h libelf/gelf.h, [break])
-])
More information about the Gcc-patches
mailing list