diff options
author | Nick Mathewson <nickm@torproject.org> | 2020-10-23 10:33:07 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2020-10-23 10:33:07 -0400 |
commit | 2908086694ee3822c8d3116952bec5a415387d75 (patch) | |
tree | f91342c8b52ad57e995c4dabe815fd0b0520e84c | |
parent | 0d420918e71f94bec3fd4c5010e570b45667d48d (diff) | |
parent | e834702f9d33f228815403055666e957b33c1857 (diff) | |
download | tor-2908086694ee3822c8d3116952bec5a415387d75.tar.gz tor-2908086694ee3822c8d3116952bec5a415387d75.zip |
Merge branch 'combined_libs'
-rw-r--r-- | Makefile.am | 21 | ||||
-rw-r--r-- | changes/ticket40127 | 7 | ||||
-rwxr-xr-x | scripts/build/combine_libs | 35 | ||||
-rwxr-xr-x | scripts/codegen/fuzzing_include_am.py | 7 | ||||
-rw-r--r-- | src/app/include.am | 4 | ||||
-rw-r--r-- | src/test/fuzz/include.am | 7 | ||||
-rw-r--r-- | src/test/include.am | 10 |
7 files changed, 76 insertions, 15 deletions
diff --git a/Makefile.am b/Makefile.am index 136368088e..50b002139e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -14,6 +14,7 @@ CLEANFILES= TESTS= noinst_PROGRAMS= DISTCLEANFILES= +MOSTLYCLEANFILES= bin_SCRIPTS= AM_CPPFLAGS=\ -I$(top_srcdir)/src \ @@ -137,6 +138,13 @@ TOR_INTERNAL_LIBS = \ src/trunnel/libor-trunnel.a \ src/lib/libtor-trace.a +libtor.a: $(TOR_INTERNAL_LIBS) + $(AM_V_AR) export AR="$(AR)"; \ + export ARFLAGS="$(ARFLAGS)"; \ + $(top_srcdir)/scripts/build/combine_libs libtor.a $(TOR_INTERNAL_LIBS) + +MOSTLYCLEANFILES += libtor.a + # Variants of the above for linking the testing variant of tor (for coverage # and tests) if UNITTESTS_ENABLED @@ -148,6 +156,14 @@ TOR_INTERNAL_TESTING_LIBS = \ $(TOR_UTIL_TESTING_LIBS) \ src/trunnel/libor-trunnel-testing.a \ src/lib/libtor-trace.a + +src/test/libtor-testing.a: $(TOR_INTERNAL_TESTING_LIBS) + $(AM_V_AR) export AR="$(AR)"; \ + export ARFLAGS="$(ARFLAGS)"; \ + export RANLIB="$(RANLIB)"; \ + $(top_srcdir)/scripts/build/combine_libs src/test/libtor-testing.a $(TOR_INTERNAL_TESTING_LIBS) + +MOSTLYCLEANFILES += src/test/libtor-testing.a endif TOR_LDFLAGS_CRYPTLIB=@TOR_LDFLAGS_openssl@ @@ -175,6 +191,7 @@ EXTRA_DIST+= \ Makefile.nmake \ README \ ReleaseNotes \ + scripts/build/combine_libs \ scripts/maint/checkIncludes.py \ scripts/maint/checkSpace.pl \ scripts/maint/checkSpaceTest.sh \ @@ -701,7 +718,7 @@ show-distdir-core: file $(distdir)/_build/core; fi show-libs: - @echo $(TOR_INTERNAL_LIBS) + @echo libtor.a show-testing-libs: - @echo $(TOR_INTERNAL_TESTING_LIBS) + @echo src/test/libtor-testing.a diff --git a/changes/ticket40127 b/changes/ticket40127 new file mode 100644 index 0000000000..f546a8ea3b --- /dev/null +++ b/changes/ticket40127 @@ -0,0 +1,7 @@ + o Minor features (compilation): + - When building Tor, first link all object files into a single + static library. This may help with embedding Tor in other + programs. Note that most Tor functions do not constitute a + part of a stable or supported API: Only those functions in + tor_api.h should be used if embedding Tor. Closes ticket + 40127. diff --git a/scripts/build/combine_libs b/scripts/build/combine_libs new file mode 100755 index 0000000000..fb311552fe --- /dev/null +++ b/scripts/build/combine_libs @@ -0,0 +1,35 @@ +#!/bin/sh + +set -e + +TMPDIR="$(mktemp -d -t tor_lib_combining.XXXXXX)" +ORIGDIR="$(pwd)" + +trap 'cd "$ORIGDIR" && rm -rf "$TMPDIR"' 0 + +abspath() { + echo "$(cd "$(dirname "$1")">/dev/null && pwd)/$(basename "$1")" +} + +TARGET=$(abspath "$1") + +#echo ORIGDIR="$ORIGDIR" +#echo AR="$AR" +#echo ARFLAGS="$AFLAGS" + +shift + +for input in "$@"; do + cd "$ORIGDIR" + abs=$(abspath "$input") + dir="$TMPDIR"/$(basename "$input" .a) + mkdir "$dir" + cd "$dir">/dev/null + ar x "$abs" +done + +cd "$TMPDIR" >/dev/null +#echo "${AR:-ar}" "${ARFLAGS:-cru}" library.tmp.a ./*/** +"${AR:-ar}" "${ARFLAGS:-cru}" library.tmp.a ./*/** +"${RANLIB:-ranlib}" library.tmp.a +mv -f library.tmp.a "$TARGET" diff --git a/scripts/codegen/fuzzing_include_am.py b/scripts/codegen/fuzzing_include_am.py index b3892b6fd3..b52b956f81 100755 --- a/scripts/codegen/fuzzing_include_am.py +++ b/scripts/codegen/fuzzing_include_am.py @@ -31,17 +31,18 @@ FUZZING_CFLAGS = \ FUZZING_LDFLAG = \ @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB) @TOR_LDFLAGS_libevent@ FUZZING_LIBS = \ - $(TOR_INTERNAL_TESTING_LIBS) \ + src/test/libtor-testing.a \ $(rust_ldadd) \ @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ \ @TOR_LIBEVENT_LIBS@ $(TOR_LIBS_CRYPTLIB) \ @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ @CURVE25519_LIBS@ \ @TOR_SYSTEMD_LIBS@ \ @TOR_LZMA_LIBS@ \ - @TOR_ZSTD_LIBS@ + @TOR_ZSTD_LIBS@ \ + @TOR_TRACE_LIBS@ oss-fuzz-prereqs: \ - $(TOR_INTERNAL_TESTING_LIBS) + src/test/libtor-testing.a noinst_HEADERS += \ src/test/fuzz/fuzzing.h diff --git a/src/app/include.am b/src/app/include.am index 8488a1bf19..b81fad0276 100644 --- a/src/app/include.am +++ b/src/app/include.am @@ -15,7 +15,7 @@ src_app_tor_SOURCES = src/app/main/tor_main.c # matters a lot there, and is quite hard to debug if you forget to do it. src_app_tor_LDFLAGS = @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB) @TOR_LDFLAGS_libevent@ -src_app_tor_LDADD = $(TOR_INTERNAL_LIBS) \ +src_app_tor_LDADD = libtor.a \ $(rust_ldadd) \ @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ $(TOR_LIBS_CRYPTLIB) \ @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ \ @@ -27,7 +27,7 @@ src_app_tor_cov_SOURCES = $(src_app_tor_SOURCES) src_app_tor_cov_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_CPPFLAGS) src_app_tor_cov_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS) src_app_tor_cov_LDFLAGS = @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB) @TOR_LDFLAGS_libevent@ -src_app_tor_cov_LDADD = $(TOR_INTERNAL_TESTING_LIBS) \ +src_app_tor_cov_LDADD = src/test/libtor-testing.a \ @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ $(TOR_LIBS_CRYPTLIB) \ @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ \ @CURVE25519_LIBS@ @TOR_SYSTEMD_LIBS@ \ diff --git a/src/test/fuzz/include.am b/src/test/fuzz/include.am index 510ff35a3c..ef952c3812 100644 --- a/src/test/fuzz/include.am +++ b/src/test/fuzz/include.am @@ -7,17 +7,18 @@ FUZZING_CFLAGS = \ FUZZING_LDFLAG = \ @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB) @TOR_LDFLAGS_libevent@ FUZZING_LIBS = \ - $(TOR_INTERNAL_TESTING_LIBS) \ + src/test/libtor-testing.a \ $(rust_ldadd) \ @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ \ @TOR_LIBEVENT_LIBS@ $(TOR_LIBS_CRYPTLIB) \ @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ @CURVE25519_LIBS@ \ @TOR_SYSTEMD_LIBS@ \ @TOR_LZMA_LIBS@ \ - @TOR_ZSTD_LIBS@ @TOR_TRACE_LIBS@ + @TOR_ZSTD_LIBS@ \ + @TOR_TRACE_LIBS@ oss-fuzz-prereqs: \ - $(TOR_INTERNAL_TESTING_LIBS) + src/test/libtor-testing.a noinst_HEADERS += \ src/test/fuzz/fuzzing.h diff --git a/src/test/include.am b/src/test/include.am index 173f007fbf..cb3a498f74 100644 --- a/src/test/include.am +++ b/src/test/include.am @@ -312,7 +312,7 @@ src_test_test_switch_id_LDADD = \ src_test_test_LDFLAGS = @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB) \ @TOR_LDFLAGS_libevent@ src_test_test_LDADD = \ - $(TOR_INTERNAL_TESTING_LIBS) \ + src/test/libtor-testing.a \ $(rust_ldadd) \ @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ \ $(TOR_LIBS_CRYPTLIB) @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ \ @@ -341,7 +341,7 @@ src_test_test_memwipe_LDFLAGS = $(src_test_test_LDFLAGS) @CFLAGS_BUGTRAP@ src_test_bench_LDFLAGS = @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB) \ @TOR_LDFLAGS_libevent@ src_test_bench_LDADD = \ - $(TOR_INTERNAL_LIBS) \ + libtor.a \ $(rust_ldadd) \ @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ \ $(TOR_LIBS_CRYPTLIB) @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ \ @@ -351,7 +351,7 @@ src_test_bench_LDADD = \ src_test_test_workqueue_LDFLAGS = @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB) \ @TOR_LDFLAGS_libevent@ src_test_test_workqueue_LDADD = \ - $(TOR_INTERNAL_TESTING_LIBS) \ + src/test/libtor-testing.a \ $(rust_ldadd) \ @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ \ $(TOR_LIBS_CRYPTLIB) @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ \ @@ -400,7 +400,7 @@ noinst_PROGRAMS+= src/test/test-hs-ntor-cl src_test_test_ntor_cl_SOURCES = src/test/test_ntor_cl.c src_test_test_ntor_cl_LDFLAGS = @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB) src_test_test_ntor_cl_LDADD = \ - $(TOR_INTERNAL_LIBS) \ + libtor.a \ $(rust_ldadd) \ @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ \ $(TOR_LIBS_CRYPTLIB) @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ @TOR_LIB_USERENV@ \ @@ -411,7 +411,7 @@ src_test_test_ntor_cl_AM_CPPFLAGS = \ src_test_test_hs_ntor_cl_SOURCES = src/test/test_hs_ntor_cl.c src_test_test_hs_ntor_cl_LDFLAGS = @TOR_LDFLAGS_zlib@ $(TOR_LDFLAGS_CRYPTLIB) src_test_test_hs_ntor_cl_LDADD = \ - $(TOR_INTERNAL_LIBS) \ + libtor.a \ @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ \ $(TOR_LIBS_CRYPTLIB) @TOR_LIB_WS32@ @TOR_LIB_IPHLPAPI@ @TOR_LIB_SHLWAPI@ @TOR_LIB_GDI@ \ @CURVE25519_LIBS@ @TOR_TRACE_LIBS@ |