Bug 1487931 - Avoid using linker scripts as file lists when doing LTO with BFD ld. r=froydnj
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 04 Sep 2018 21:49:16 +0000
changeset 483066 0db77a36565cd9971eb5794785defe498673c303
parent 483065 e119dbd3463f2cbe37ef4df3da54e47b5ae5a252
child 483067 098f6aaf52410eb6b51b230cfd2e478339d290c3
push id232
push userfmarier@mozilla.com
push dateWed, 05 Sep 2018 20:45:54 +0000
reviewersfroydnj
bugs1487931
milestone63.0a1
Bug 1487931 - Avoid using linker scripts as file lists when doing LTO with BFD ld. r=froydnj At least, when that combination doesn't work. This requires passing the LTO flags to the compiler invocations for the test, which in turn requires actually calling the linker directly on Windows, instead of directly through the compiler, as when actually building. Differential Revision: https://phabricator.services.mozilla.com/D4739
build/autoconf/expandlibs.m4
build/moz.configure/toolchain.configure
--- a/build/autoconf/expandlibs.m4
+++ b/build/autoconf/expandlibs.m4
@@ -9,29 +9,38 @@ dnl =
 dnl = Check what kind of list files are supported by the
 dnl = linker
 dnl =
 dnl ========================================================
 
 AC_CACHE_CHECK(what kind of list files are supported by the linker,
     EXPAND_LIBS_LIST_STYLE,
     [echo "int main() {return 0;}" > conftest.${ac_ext}
-     if AC_TRY_COMMAND(${CC-cc} -o conftest.${OBJ_SUFFIX} -c $CFLAGS $CPPFLAGS conftest.${ac_ext} 1>&5) && test -s conftest.${OBJ_SUFFIX}; then
+     dnl Because BFD ld doesn't work with LTO + linker scripts, we
+     dnl must pass the LTO CFLAGS to the compile command, and the LTO
+     dnl LDFLAGS to all subsequent link commands.
+     dnl https://sourceware.org/bugzilla/show_bug.cgi?id=23600
+     if AC_TRY_COMMAND(${CC-cc} -o conftest.${OBJ_SUFFIX} -c $MOZ_LTO_CFLAGS $CFLAGS $CPPFLAGS conftest.${ac_ext} 1>&5) && test -s conftest.${OBJ_SUFFIX}; then
          echo "INPUT(conftest.${OBJ_SUFFIX})" > conftest.list
-         if AC_TRY_COMMAND(${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.list $LIBS 1>&5) && test -s conftest${ac_exeext}; then
+         if test "$OS_TARGET" = WINNT; then
+             link="$LINKER -OUT:conftest${ac_exeext}"
+         else
+             link="${CC-cc} -o conftest${ac_exeext}"
+         fi
+         if AC_TRY_COMMAND($link $MOZ_LTO_LDFLAGS $LDFLAGS conftest.list $LIBS 1>&5) && test -s conftest${ac_exeext}; then
              EXPAND_LIBS_LIST_STYLE=linkerscript
          else
              echo "conftest.${OBJ_SUFFIX}" > conftest.list
              dnl -filelist is for the OS X linker.  We need to try -filelist
              dnl first because clang understands @file, but may pass an
              dnl oversized argument list to the linker depending on the
              dnl contents of @file.
-             if AC_TRY_COMMAND(${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS [-Wl,-filelist,conftest.list] $LIBS 1>&5) && test -s conftest${ac_exeext}; then
+             if AC_TRY_COMMAND($link $MOZ_LTO_LDFLAGS $LDFLAGS [-Wl,-filelist,conftest.list] $LIBS 1>&5) && test -s conftest${ac_exeext}; then
                  EXPAND_LIBS_LIST_STYLE=filelist
-             elif AC_TRY_COMMAND(${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS @conftest.list $LIBS 1>&5) && test -s conftest${ac_exeext}; then
+             elif AC_TRY_COMMAND($link $MOZ_LTO_LDFLAGS $LDFLAGS @conftest.list $LIBS 1>&5) && test -s conftest${ac_exeext}; then
                  EXPAND_LIBS_LIST_STYLE=list
              else
                  AC_ERROR([Couldn't find one that works])
              fi
          fi
      else
          dnl We really don't expect to get here, but just in case
          AC_ERROR([couldn't compile a simple C file])
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -1402,16 +1402,18 @@ def lto(value, pgo, c_compiler):
     )
 
 
 add_old_configure_assignment('MOZ_LTO', lto.enabled)
 set_config('MOZ_LTO', lto.enabled)
 set_define('MOZ_LTO', lto.enabled)
 set_config('MOZ_LTO_CFLAGS', lto.cflags)
 set_config('MOZ_LTO_LDFLAGS', lto.ldflags)
+add_old_configure_assignment('MOZ_LTO_CFLAGS', lto.cflags)
+add_old_configure_assignment('MOZ_LTO_LDFLAGS', lto.ldflags)
 
 # ASAN
 # ==============================================================
 
 js_option('--enable-address-sanitizer', help='Enable Address Sanitizer')
 
 
 @depends_if('--enable-address-sanitizer')