[lto] add a --with-libelf configure option
Eric Fisher
joefoxreal@gmail.com
Thu May 21 02:25:00 GMT 2009
Hello,
This is a patch which adds a --with-libelf configure option.
Currently, it doesn't check for whether gelf.h exists.
Do we need to check it in configure, or .c file?
Which option name is better between --with-libelf and --with-elf?
Because the configure and Makefile.in are auto generated and large, I
just omit them in the following patch.
It's been tested in my x86 machine.
2009-05-21 Eric Fisher <joefoxreal@gmial.com>
* configure.ac, Makefile.tpl: add a --with-libelf configure option.
* gcc/lto/lto-elf.c, lto-plugin/lto-plugin.c,
lto-plugin/lto-symtab.c: don't check gelf.h.
* lto-plugin/configure.ac, lto-plugin/Makefile.am: don't check
gelf.h, use LIBELFINC and LIBELFLIBS.
Index: gcc/lto/lto-elf.c
===================================================================
--- gcc/lto/lto-elf.c (revision 147756)
+++ gcc/lto/lto-elf.c (working copy)
@@ -24,21 +24,12 @@ 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"
#include "lto-section-out.h"
-
/* Initialize FILE, an LTO file object for FILENAME. */
static void
lto_file_init (lto_file *file, const char *filename)
Index: configure.ac
===================================================================
--- configure.ac (revision 147756)
+++ configure.ac (working copy)
@@ -1451,6 +1451,45 @@ AC_SUBST(clooglibs)
AC_SUBST(clooginc)
+# Check for libelf
+libelflibs="-lelf"
+libelfinc=
+
+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
+ clooginc="-I$with_libelf_include"
+fi
+if test "x$with_libelf_lib" != x; then
+ clooglibs="-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)
+
+
# By default, C is the only stage 1 language.
stage1_languages=,c,
Index: Makefile.tpl
===================================================================
--- Makefile.tpl (revision 147756)
+++ 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 147756)
+++ lto-plugin/configure.ac (working copy)
@@ -3,7 +3,11 @@ 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])
+
+#AC_CHECK_GELF
AM_PROG_LIBTOOL
AC_SUBST(target_noncanonical)
AC_CONFIG_FILES(Makefile)
Index: lto-plugin/Makefile.am
===================================================================
--- lto-plugin/Makefile.am (revision 147756)
+++ lto-plugin/Makefile.am (working copy)
@@ -2,6 +2,13 @@ gcc_version := $(shell cat $(top_srcdir)
target_noncanonical := @target_noncanonical@
libexecsubdir := $(libexecdir)/gcc/$(target_noncanonical)/$(gcc_version)
+# How to find LIBELF
+LIBELFINC = @LIBELFINC@
+LIBELFLIBS = @LIBELFLIBS@
+
+INCLUDES = $(LIBELFINC)
+LIBS = $(LIBELFLIBS)
+
AM_CPPFLAGS = -I$(top_srcdir)/../include -D_LARGEFILE_SOURCE \
-D_FILE_OFFSET_BITS=64
Index: lto-plugin/lto-plugin.c
===================================================================
--- lto-plugin/lto-plugin.c (revision 147756)
+++ lto-plugin/lto-plugin.c (working copy)
@@ -46,16 +46,7 @@ Foundation, Inc., 51 Franklin Street - F
#include <sys/wait.h>
#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
+#include <gelf.h>
#include "plugin-api.h"
#include "../gcc/lto/common.h"
Index: lto-plugin/lto-symtab.c
===================================================================
--- lto-plugin/lto-symtab.c (revision 147756)
+++ lto-plugin/lto-symtab.c (working copy)
@@ -23,20 +23,11 @@ Foundation, Inc., 51 Franklin Street - F
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
+#include <gelf.h>
#include "plugin-api.h"
#include "../gcc/lto/common.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
-
static ld_plugin_claim_file_handler claim_file_handler;
static ld_plugin_all_symbols_read_handler all_symbols_read_handler;
static ld_plugin_cleanup_handler cleanup_handler;
Best regards,
Eric Fisher
More information about the Gcc-patches
mailing list