]> granicus.if.org Git - libevent/commitdiff
Use the gcc -ffunction-segments feature to allow gc when linking with static libevent
authorDave Hart <hart@ntp.org>
Sun, 13 Feb 2011 06:50:40 +0000 (01:50 -0500)
committerNick Mathewson <nickm@torproject.org>
Tue, 22 Feb 2011 05:25:58 +0000 (00:25 -0500)
configure.in
sample/Makefile.am
test/Makefile.am

index 53701368db5db1d3e0502944d6eadc11e93a680f..c00abd20fa8a53284c7bfaed442188bc012d985b 100644 (file)
@@ -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)
index 0071d26f2776fcc2231e3f3f83c71180ad52a7db..2d616f9eb38c77cfafa940fda7b75356f90f019c 100644 (file)
@@ -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
index 97682fb467c8be968504ac266be1bd356f6f8bc1..b9fb8d04ca027cf7f43fbb24c538a2d004d1be39 100644 (file)
@@ -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"