From: Dave Hart Date: Sun, 13 Feb 2011 06:50:40 +0000 (-0500) Subject: Use the gcc -ffunction-segments feature to allow gc when linking with static libevent X-Git-Tag: release-2.0.11-stable~51 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0965c563568e49448955aea30bd43df30e544b92;p=libevent Use the gcc -ffunction-segments feature to allow gc when linking with static libevent --- diff --git a/configure.in b/configure.in index 53701368..c00abd20 100644 --- a/configure.in +++ b/configure.in @@ -628,5 +628,37 @@ if test x$enable_gcc_warnings = xyes && test "$GCC" = "yes"; then fi +LIBEVENT_GC_SECTIONS= +if test "$GCC" = yes ; then + AC_CACHE_CHECK( + [if linker supports omitting unused code and data], + [libevent_cv_gc_sections_works], + [ + origCFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -Wl,--gc-sections" + AC_LINK_IFELSE( + [AC_LANG_PROGRAM([[]], [[]])], + [ + if grep gc-sections conftest.err ; then + libevent_cv_gc_sections_works=no + else + libevent_cv_gc_sections_works=yes + fi + ], + [libevent_cv_gc_sections_works=no] + ) + CFLAGS="$origCFLAGS" + AS_UNSET([origCFLAGS]) + ] + ) + case "$libevent_cv_gc_sections_works" in + yes) + CFLAGS="-ffunction-sections -fdata-sections $CFLAGS" + LIBEVENT_GC_SECTIONS="-Wl,--gc-sections" + ;; + esac +fi +AC_SUBST([LIBEVENT_GC_SECTIONS]) + AC_CONFIG_FILES( [libevent.pc libevent_openssl.pc libevent_pthreads.pc] ) AC_OUTPUT(Makefile include/Makefile test/Makefile sample/Makefile) diff --git a/sample/Makefile.am b/sample/Makefile.am index 0071d26f..2d616f9e 100644 --- a/sample/Makefile.am +++ b/sample/Makefile.am @@ -1,6 +1,6 @@ AUTOMAKE_OPTIONS = foreign no-dependencies -LDADD = ../libevent.la +LDADD = @LIBEVENT_GC_SECTIONS@ ../libevent.la AM_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/compat -I$(top_srcdir)/include -I../include noinst_PROGRAMS = event-test time-test signal-test dns-example hello-world http-server diff --git a/test/Makefile.am b/test/Makefile.am index 97682fb4..b9fb8d04 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -45,7 +45,7 @@ if BUILD_WIN32 regress_SOURCES += regress_iocp.c endif -regress_LDADD = ../libevent.la $(PTHREAD_LIBS) $(ZLIB_LIBS) +regress_LDADD = @LIBEVENT_GC_SECTIONS@ ../libevent.la $(PTHREAD_LIBS) $(ZLIB_LIBS) regress_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/compat \ -I$(top_srcdir)/include -I../include $(PTHREAD_CFLAGS) $(ZLIB_CFLAGS) regress_LDFLAGS = $(PTHREAD_CFLAGS) @@ -56,13 +56,13 @@ regress_LDADD += ../libevent_openssl.la -lcrypto -lssl endif bench_SOURCES = bench.c -bench_LDADD = ../libevent.la +bench_LDADD = @LIBEVENT_GC_SECTIONS@ ../libevent.la bench_cascade_SOURCES = bench_cascade.c -bench_cascade_LDADD = ../libevent.la +bench_cascade_LDADD = @LIBEVENT_GC_SECTIONS@ ../libevent.la bench_http_SOURCES = bench_http.c -bench_http_LDADD = ../libevent.la +bench_http_LDADD = @LIBEVENT_GC_SECTIONS@ ../libevent.la bench_httpclient_SOURCES = bench_httpclient.c -bench_httpclient_LDADD = ../libevent_core.la +bench_httpclient_LDADD = @LIBEVENT_GC_SECTIONS@ ../libevent_core.la regress.gen.c regress.gen.h: regress.rpc $(top_srcdir)/event_rpcgen.py $(top_srcdir)/event_rpcgen.py $(srcdir)/regress.rpc || echo "No Python installed"