diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2017-02-08 13:20:09 +0100 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2017-02-13 14:48:15 +0000 |
commit | 1b46872cde7fb50652f55bfe1e286e6af5124200 (patch) | |
tree | 2ca9133917358b12b4afd5af47d61bc8db51374f /qmake | |
parent | 0d2791c5f64fcb7f0ce4c2027d78fc39de514ab4 (diff) |
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 <oswald.buddenhagen@qt.io>
Diffstat (limited to 'qmake')
-rw-r--r-- | qmake/generators/win32/msvc_nmake.cpp | 41 | ||||
-rw-r--r-- | qmake/generators/win32/msvc_nmake.h | 1 |
2 files changed, 35 insertions, 7 deletions
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" <<var("QMAKE_PRE_LINK"); if(project->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(); |