This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch 9.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/9.2.x by this push:
new b6adc86af Adds a --enable-lto option (Link Time Optimization) (#9464)
b6adc86af is described below
commit b6adc86af5a443eb67fb1cbe78027df6b1f397df
Author: Leif Hedstrom <[email protected]>
AuthorDate: Tue Feb 28 08:50:07 2023 -0700
Adds a --enable-lto option (Link Time Optimization) (#9464)
(cherry picked from commit 6cc60279bc2f94fbb221c3fe5b51a094cb216740)
---
build/common.m4 | 3 +++
configure.ac | 25 +++++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/build/common.m4 b/build/common.m4
index 0409d735f..1cf815513 100644
--- a/build/common.m4
+++ b/build/common.m4
@@ -37,6 +37,9 @@ EOF
if test -n "$CXX"; then
echo "CXX=\"$CXX\"; export CXX" >> $1
fi
+ if test -n "$LD"; then
+ echo "LD=\"$LD\"; export LD" >> $1
+ fi
if test -n "$CFLAGS"; then
echo "CFLAGS=\"$CFLAGS\"; export CFLAGS" >> $1
fi
diff --git a/configure.ac b/configure.ac
index 481897f31..406c1a0aa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -231,6 +231,17 @@ AC_ARG_ENABLE([tsan],
)
AC_MSG_RESULT([$enable_tsan])
+#
+# Enable Link Time Optimization. This may need different settings per compiler?
+#
+AC_MSG_CHECKING([whether to enable LTO])
+AC_ARG_ENABLE([lto],
+ [AS_HELP_STRING([--enable-lto],[turn on Link Time Optimization])],
+ [],
+ [enable_lto=no]
+)
+AC_MSG_RESULT([$enable_lto])
+
#
# Fast SDK APIs, this disables the parameter checks (assert)
# on all APIs.
@@ -958,6 +969,19 @@ AS_IF([test x"$enable_werror" = "xyes"], [
TS_ADDTO(debug_opt, -Werror)
])
+# Add the necessary flags for LTO
+AS_IF([test x"$enable_lto" = "xyes"], [
+ AS_IF([test "x$ax_cv_c_compiler_vendor" = "xclang"], [
+ TS_ADDTO(AM_CXXFLAGS, [-flto=thin -fuse-ld=lld])
+ TS_ADDTO(AM_CFLAGS, [-flto=thin -fuse-ld=lld])
+ TS_ADDTO(AM_LDFLAGS, [-flto=thin -fuse-ld=lld])
+ ], [
+ TS_ADDTO(AM_CXXFLAGS, [-flto])
+ TS_ADDTO(AM_CFLAGS, [-flto])
+ TS_ADDTO(AM_LDFLAGS, [-flto])
+ ])
+])
+
cc_oflag_opt=$release_opt
cc_oflag_dbg=$debug_opt
cxx_oflag_opt="$release_opt $cxx_opt $cxx_rel"
@@ -2353,6 +2377,7 @@ AC_MSG_NOTICE([Build option summary:
CC: $CC
CXX: $CXX
CPP: $CPP
+ LD: $LD
CFLAGS: $CFLAGS
CXXFLAGS: $CXXFLAGS
CPPFLAGS: $CPPFLAGS