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>
This commit is contained in:
parent
0d2791c5f6
commit
1b46872cde
@ -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
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user