Skip to content

Commit

Permalink
[backport: 2.0] prevents the jsonscript command from exceeding the ma…
Browse files Browse the repository at this point in the history
…ximum length of a command line during linking (nim-lang#21186)
  • Loading branch information
rockcavera authored and survivorm committed Feb 28, 2023
1 parent bf200d8 commit 2df9af8
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions compiler/extccomp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,17 @@ proc displayProgressCC(conf: ConfigRef, path, compileCmd: string): string =
else:
result = MsgKindToStr[hintCC] % demangleModuleName(path.splitFile.name)

proc preventLinkCmdMaxCmdLen(conf: ConfigRef, linkCmd: string) =
# Prevent linkcmd from exceeding the maximum command line length.
# Windows's command line limit is about 8K (8191 characters) so C compilers on
# Windows support a feature where the command line can be passed via ``@linkcmd``
# to them.
const MaxCmdLen = when defined(windows): 8_000 else: 32_000
if linkCmd.len > MaxCmdLen:
linkViaResponseFile(conf, linkCmd)
else:
execLinkCmd(conf, linkCmd)

proc callCCompiler*(conf: ConfigRef) =
var
linkCmd: string
Expand Down Expand Up @@ -927,14 +938,7 @@ proc callCCompiler*(conf: ConfigRef) =
linkCmd = getLinkCmd(conf, mainOutput, objfiles, removeStaticFile = true)
extraCmds = getExtraCmds(conf, mainOutput)
if optCompileOnly notin conf.globalOptions:
const MaxCmdLen = when defined(windows): 8_000 else: 32_000
if linkCmd.len > MaxCmdLen:
# Windows's command line limit is about 8K (don't laugh...) so C compilers on
# Windows support a feature where the command line can be passed via ``@linkcmd``
# to them.
linkViaResponseFile(conf, linkCmd)
else:
execLinkCmd(conf, linkCmd)
preventLinkCmdMaxCmdLen(conf, linkCmd)
for cmd in extraCmds:
execExternalProgram(conf, cmd, hintExecuting)
else:
Expand Down Expand Up @@ -1035,7 +1039,7 @@ proc runJsonBuildInstructions*(conf: ConfigRef; jsonFile: AbsoluteFile) =
cmds.add cmd
prettyCmds.add displayProgressCC(conf, name, cmd)
execCmdsInParallel(conf, cmds, prettyCb)
execLinkCmd(conf, bcache.linkcmd)
preventLinkCmdMaxCmdLen(conf, bcache.linkcmd)
for cmd in bcache.extraCmds: execExternalProgram(conf, cmd, hintExecuting)

proc genMappingFiles(conf: ConfigRef; list: CfileList): Rope =
Expand Down

0 comments on commit 2df9af8

Please sign in to comment.