From 1b46872cde7fb50652f55bfe1e286e6af5124200 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 8 Feb 2017 13:20:09 +0100 Subject: qmake/nmake: Prevent overlong lines in link and lib response files Linking with too many object files could lead to "LNK1170: line in command file contains 131071 or more characters". Do not write all .obj files into one line but respect a limit of 1000 characters. If the limit is reached the object files are separated by newlines instead of spaces. Task-number: QTBUG-58710 Change-Id: Ibae1f737d6b614a9624b4e00cdd21d3722d341e3 Reviewed-by: Oswald Buddenhagen --- qmake/generators/win32/msvc_nmake.cpp | 41 +++++++++++++++++++++++++++++------ qmake/generators/win32/msvc_nmake.h | 1 + 2 files changed, 35 insertions(+), 7 deletions(-) (limited to 'qmake/generators') diff --git a/qmake/generators/win32/msvc_nmake.cpp b/qmake/generators/win32/msvc_nmake.cpp index c19c101d43..0b0efe4acf 100644 --- a/qmake/generators/win32/msvc_nmake.cpp +++ b/qmake/generators/win32/msvc_nmake.cpp @@ -566,9 +566,9 @@ void NmakeMakefileGenerator::writeBuildRulesPart(QTextStream &t) if(!project->isEmpty("QMAKE_PRE_LINK")) t << "\n\t" <isActiveConfig("staticlib")) { - t << "\n\t$(LIBAPP) $(LIBFLAGS) " << var("QMAKE_LINK_O_FLAG") << "$(DESTDIR_TARGET) @<<\n\t " - << "$(OBJECTS)" - << "\n<<"; + t << "\n\t$(LIBAPP) $(LIBFLAGS) " << var("QMAKE_LINK_O_FLAG") << "$(DESTDIR_TARGET) @<<\n\t "; + writeResponseFileFiles(t, project->values("OBJECTS")); + t << "<<"; } else { const bool embedManifest = ((templateName == "app" && project->isActiveConfig("embed_manifest_exe")) || (templateName == "lib" && project->isActiveConfig("embed_manifest_dll") @@ -652,11 +652,38 @@ void NmakeMakefileGenerator::writeLinkCommand(QTextStream &t, const QString &ext t << "$(LINKER) $(LFLAGS)"; if (!extraFlags.isEmpty()) t << ' ' << extraFlags; - t << " " << var("QMAKE_LINK_O_FLAG") << "$(DESTDIR_TARGET) @<<\n" - << "$(OBJECTS) $(LIBS)"; + t << " " << var("QMAKE_LINK_O_FLAG") << "$(DESTDIR_TARGET) @<<\n"; + writeResponseFileFiles(t, project->values("OBJECTS")); + t << "$(LIBS)\n"; if (!extraInlineFileContent.isEmpty()) - t << ' ' << extraInlineFileContent; - t << "\n<<"; + t << extraInlineFileContent << '\n'; + t << "<<"; +} + +void NmakeMakefileGenerator::writeResponseFileFiles(QTextStream &t, const ProStringList &files) +{ + if (files.isEmpty()) + return; + // Add line breaks in file lists in reponse files to work around LNK1170. + // The actual line length limit is 131070, but let's use a smaller limit + // in case other tools are similarly hampered. + const int maxLineLength = 1000; + int len = 0; + for (const ProString &file : files) { + const ProString escapedFilePath = escapeFilePath(file); + if (len) { + if (len + escapedFilePath.length() > maxLineLength) { + t << '\n'; + len = 0; + } else { + t << ' '; + len++; + } + } + t << escapedFilePath; + len += escapedFilePath.length(); + } + t << '\n'; } int NmakeMakefileGenerator::msvcVersion() const diff --git a/qmake/generators/win32/msvc_nmake.h b/qmake/generators/win32/msvc_nmake.h index 9c88934e36..f782f9d734 100644 --- a/qmake/generators/win32/msvc_nmake.h +++ b/qmake/generators/win32/msvc_nmake.h @@ -40,6 +40,7 @@ class NmakeMakefileGenerator : public Win32MakefileGenerator void writeImplicitRulesPart(QTextStream &t); void writeBuildRulesPart(QTextStream &t); void writeLinkCommand(QTextStream &t, const QString &extraFlags = QString(), const QString &extraInlineFileContent = QString()); + void writeResponseFileFiles(QTextStream &t, const ProStringList &files); int msvcVersion() const; void init(); static QStringList sourceFilesForImplicitRulesFilter(); -- cgit v1.2.3