From 074aeb56b59d84dd578375ec613562004d55f43e Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Fri, 19 Apr 2024 09:31:13 +0000 Subject: [PATCH] Bug 1892198 - No longer support linkerscript style for moz_expand_libs r=glandium @file are supported by gcc since gcc 7 and by clang since clang 3.x, which removes the need for linker script to list input files. We cannot directly use @file from the compiler driver (it would expand to a large number of arguments and hit the linker limit) so pass -Wl,@FILE instead, which is supported since binutils 2.17. As a side effect this removes the LTO dependency from the check. Differential Revision: https://phabricator.services.mozilla.com/D207839 --- build/autoconf/expandlibs.m4 | 33 +++++++++------------- python/mozbuild/mozbuild/backend/common.py | 10 +++---- toolkit/library/gen_buildid.py | 11 +------- 3 files changed, 18 insertions(+), 36 deletions(-) diff --git a/build/autoconf/expandlibs.m4 b/build/autoconf/expandlibs.m4 index 70bc153e6678..b0fc6caf9537 100644 --- a/build/autoconf/expandlibs.m4 +++ b/build/autoconf/expandlibs.m4 @@ -14,32 +14,25 @@ dnl ======================================================== AC_CACHE_CHECK(what kind of list files are supported by the linker, moz_cv_expand_libs_list_style, [echo "int main() {return 0;}" > conftest.${ac_ext} - 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.${OBJ_SUFFIX} -c $CFLAGS $CPPFLAGS conftest.${ac_ext} 1>&5) && test -s conftest.${OBJ_SUFFIX}; then if test "$CC_TYPE" = "clang-cl"; 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 - moz_cv_expand_libs_list_style=linkerscript + echo "conftest.${OBJ_SUFFIX}" > conftest.list + if AC_TRY_COMMAND($link $LDFLAGS [-Wl,@conftest.list] $LIBS 1>&5) && test -s conftest${ac_exeext}; then + moz_cv_expand_libs_list_style=linkerlist + + dnl -filelist is for the OS X linker. We need to try -filelist first + dnl because clang understands @file, but may pass an oversized argument + dnl list to the linker depending on the contents of @file. + elif AC_TRY_COMMAND($link $LDFLAGS [-Wl,-filelist,conftest.list] $LIBS 1>&5) && test -s conftest${ac_exeext}; then + moz_cv_expand_libs_list_style=filelist + elif AC_TRY_COMMAND($link $LDFLAGS [@conftest.list] $LIBS 1>&5) && test -s conftest${ac_exeext}; then + moz_cv_expand_libs_list_style=list 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($link $MOZ_LTO_LDFLAGS $LDFLAGS [-Wl,-filelist,conftest.list] $LIBS 1>&5) && test -s conftest${ac_exeext}; then - moz_cv_expand_libs_list_style=filelist - elif AC_TRY_COMMAND($link $MOZ_LTO_LDFLAGS $LDFLAGS @conftest.list $LIBS 1>&5) && test -s conftest${ac_exeext}; then - moz_cv_expand_libs_list_style=list - else - AC_ERROR([Couldn't find one that works]) - fi + AC_ERROR([Couldn't find one that works]) fi else dnl We really don't expect to get here, but just in case diff --git a/python/mozbuild/mozbuild/backend/common.py b/python/mozbuild/mozbuild/backend/common.py index 9fe9d06e8efd..3e14484a3035 100644 --- a/python/mozbuild/mozbuild/backend/common.py +++ b/python/mozbuild/mozbuild/backend/common.py @@ -325,15 +325,13 @@ class CommonBackend(BuildBackend): list_style = "list" list_file_path = mozpath.join(objdir, name) objs = [os.path.relpath(o, objdir) for o in objs] - if list_style == "linkerscript": - ref = list_file_path - content = "\n".join('INPUT("%s")' % o for o in objs) - elif list_style == "filelist": + content = "\n".join(objs) + if list_style == "filelist": ref = "-Wl,-filelist," + list_file_path - content = "\n".join(objs) + elif list_style == "linkerlist": + ref = "-Wl,@" + list_file_path elif list_style == "list": ref = "@" + list_file_path - content = "\n".join(objs) else: return None diff --git a/toolkit/library/gen_buildid.py b/toolkit/library/gen_buildid.py index 9943ad253910..0078a5cfd6ae 100644 --- a/toolkit/library/gen_buildid.py +++ b/toolkit/library/gen_buildid.py @@ -18,16 +18,7 @@ from mozbuild.preprocessor import Preprocessor def main(output, input_file): with open(input_file) as fh: - if buildconfig.substs["EXPAND_LIBS_LIST_STYLE"] == "linkerscript": - - def cleanup(line): - assert line.startswith('INPUT("') - assert line.endswith('")') - return line[len('INPUT("') : -len('")')] - - objs = [cleanup(l.strip()) for l in fh.readlines()] - else: - objs = [l.strip() for l in fh.readlines()] + objs = [l.strip() for l in fh.readlines()] pp = Preprocessor() pp.out = StringIO()