[pacman-dev] LTO and PGO build options

Que Quotion quequotion at gmail.com
Fri Mar 18 18:35:17 UTC 2016


This orignates from a utility I put together:
https://bbs.archlinux.org/viewtopic.php?pid=1451263#p1451263

The script streamlines enabling some build options that makepkg does not
yet offer, such as link-time optimization and profile-guided optimization.

The above script works, but has limitations in that it is a wrapper script.
I propose adding these as build options in makepkg itself. Most packages
compile safely with both or either option and the benefits are enormous
(especially with PGO).

Here are the changes I propose to makepkg, for which I am open to
suggestions and hope someone other than myself will test:

--- /usr/bin/makepkg 2016-02-26 14:07:15.000000000 +0900
+++ ./makepkg.qq 2016-03-19 03:13:09.535977092 +0900
@@ -48,7 +48,7 @@

 LIBRARY=${LIBRARY:-'/usr/share/makepkg'}

-build_options=('ccache' 'distcc' 'buildflags' 'makeflags')
+build_options=('ccache' 'distcc' 'buildflags' 'makeflags' 'pgo' 'lto')
 splitpkg_overrides=('pkgdesc' 'arch' 'url' 'license' 'groups' 'depends'
                     'optdepends' 'provides' 'conflicts' 'replaces' 'backup'
                     'options' 'install' 'changelog')
@@ -866,6 +866,32 @@
  export DISTCC_HOSTS
  fi

+
+ # Use lto if it is requested (check buildenv and PKGBUILD opts)
+ if check_buildoption "lto" "y" && [[ -f "$(gcc -print-search-dirs | grep
install | awk '{print $2 "liblto_plugin.so"}')" ]]; then
+ CFLAGS+=" -flto=$(getconf _NPROCESSORS_ONLN)"
+ CXXFLAGS+=" -flto=$(getconf _NPROCESSORS_ONLN)"
+ LDFLAGS+=" $CFLAGS -fuse-linker-plugin"
+ LTOPLUGIN="$(gcc -print-search-dirs | grep install | awk '{print $2
"liblto_plugin.so"}')"
+ ARFLAGS+=" --plugin $LTOPLUGIN"
+ RANLIBFLAGS+=" --plugin $LTOPLUGIN"
+ NMFLAGS+=" --plugin $LTOPLUGIN"
+ fi
+
+ # Generate or utilize pgo if it is requested (check buildenv and PKGBUILD
opts)
+ if check_buildoption "pgo" "y"; then
+ if [ ! -d "$PROFDEST/$pkgbase.gen" ]; then
+ mkdir "$PROFDEST/$pkgbase.gen"
+ CFLAGS+="-fprofile-generate -fprofile-dir=$PROFDEST/$pkgbase.gen"
+ CXXFLAGS+="-fprofile-generate -fprofile-dir=$PROFDEST/$pkgbase.gen"
+ LDFLAGS+="-lgcov"
+ elif [ ! -d "$PROFDEST/$pkgbase.used" ]; then
+ mv "$PROFDEST/$pkgbase.gen" "$PROFDEST/$pkgbase.used"
+ CFLAGS+="-fprofile-correction -fprofile-use
-fprofile-dir=$PROFDEST/$pkgbase.used"
+ CXXFLAGS+="-fprofile-correction -fprofile-use
-fprofile-dir=$PROFDEST/$pkgbase.used"
+ fi
+ fi
+
  run_function_safe "build"
 }

@@ -2002,6 +2028,7 @@
 [[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST})
 [[ -n ${SRCDEST} ]] && _SRCDEST=$(canonicalize_path ${SRCDEST})
 [[ -n ${SRCPKGDEST} ]] && _SRCPKGDEST=$(canonicalize_path ${SRCPKGDEST})
+[[ -n ${PROFDEST} ]] && _PROFDEST=$(canonicalize_path ${PROFDEST})
 [[ -n ${LOGDEST} ]] && _LOGDEST=$(canonicalize_path ${LOGDEST})
 [[ -n ${BUILDDIR} ]] && _BUILDDIR=$(canonicalize_path ${BUILDDIR})
 [[ -n ${PKGEXT} ]] && _PKGEXT=${PKGEXT}
@@ -2098,6 +2125,14 @@
  IGNOREARCH=1
 fi

+PROFDEST=${_PROFDEST:-$PROFDEST}
+PROFDEST=${PROFDEST:-$startdir} #default to $startdir if undefined
+if [[ ! -w $PROFDEST ]] ; then
+ error "$(gettext "You do not have write permission to store profiles in
%s.")" "$PROFDEST"
+ plain "$(gettext "Aborting...")"
+ exit 1
+fi
+
 LOGDEST=${_LOGDEST:-$LOGDEST}
 LOGDEST=${LOGDEST:-$startdir} #default to $startdir if undefined
 if (( LOGGING )) && [[ ! -w $LOGDEST ]]; then


More information about the pacman-dev mailing list