[m-rev.] for review: Make link-time optimisation with gcc work.

Julien Fischer jfischer at opturion.com
Tue Jan 28 15:12:46 AEDT 2020


Hi Peter,

On Tue, 28 Jan 2020, Peter Wang wrote:

> configure.ac:
>    Add -flto to LINK_SHARED_OBJ and LINK_SHARED_OBJ_SH commands
>    when LTO is enabled with gcc.
>
>    Search for and use LTO-aware gcc-ar, gcc-ranlib and gcc-nm
>    programs in place of the normal tools.
>
> diff --git a/configure.ac b/configure.ac
> index 3e7e10c09..6dbee8860 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -5348,7 +5348,19 @@ if test "$mercury_cv_lto" = "yes"; then
>             CFLAGS_FOR_LTO="-GL"
>             LDFLAGS_FOR_LTO="-LTCG"
>             ;;
> -        gcc*|clang*)
> +        gcc*)
> +            CFLAGS_FOR_LTO="-flto"
> +            LDFLAGS_FOR_LTO="-flto"
> +            LINK_SHARED_OBJ="$LINK_SHARED_OBJ -flto"
> +            LINK_SHARED_OBJ_SH="$LINK_SHARED_OBJ_SH -flto"
> +            AC_CHECK_TOOL([GCC_AR], [gcc-ar], [])
> +            AC_CHECK_TOOL([GCC_RANLIB], [gcc-ranlib], [])
> +            AC_CHECK_TOOL([GCC_NM], [gcc-nm], [])


Is that going to work in situations where the gcc executable is not
named gcc.  (For Homebrew, it is named gcc-9, gcc-8 etc.)
(We don't need to support that case now however.)

> +            AR=${GCC_AR:-$AR}
> +            RANLIB=${GCC_RANLIB:-$RANLIB}
> +            NM=${GCC_NM:-$NM}
> +            ;;
> +        clang*)
>             CFLAGS_FOR_LTO="-flto"
>             LDFLAGS_FOR_LTO="-flto"
>             ;;

That's fine.

Julien.


More information about the reviews mailing list