Skip to content

Ninja 1.13.0 with MSVC link.exe fails, apparently due to RSP line limit of 16,383 characters #2616

@Grimrukh

Description

@Grimrukh

When using Ninja 1.13.0 and MSVC 17 2022 to build a configured CMake project (whether via CMake with CMAKE_MAKE_PROGRAM set or directly via ninja -C build), it seems to run into issues when generated RSP files contain space-separated entries producing lines that are longer than 16,383 characters. When this happens, the first prefix of the first path in the long line is stripped, appearing to link.exe as an invalid absolute path. This does not happen with Ninja 1.12.1; it links and builds fine.

Here's the output with some names stripped:

[636/692] Linking CXX executable bin\some_test.exe
FAILED: [code=4294967295] bin/some_test.exe
C:\WINDOWS\system32\cmd.exe /C "cd . && "C:\path\to\cmake.exe" -E vs_link_exe --msvc-ver=1943 --intdir=dev\package\tests\CMakeFiles\some_test.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\mt.exe --manifests  -- C:\PROGRA~1\MICROS~4\2022\PROFES~1\VC\Tools\MSVC\1443~1.348\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\some_test.rsp  /out:bin\some_test.exe /implib:lib\some_test.lib /pdb:bin\some_test.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console  /GUARD:CF /CETCOMPAT /DYNAMICBASE && cd ."

LINK Pass 1: command "C:\PROGRA~1\MICROS~4\2022\PROFES~1\VC\Tools\MSVC\1443~1.348\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\some_test.rsp /out:bin\some_test.exe /implib:lib\some_test.lib /pdb:bin\some_test.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console /GUARD:CF /CETCOMPAT /DYNAMICBASE /MANIFEST /MANIFESTFILE:dev\package\tests\CMakeFiles\some_test.dir/intermediate.manifest dev\package\tests\CMakeFiles\some_test.dir/manifest.res" failed (exit code 1104) with the following output:
LINK : bin\some_test.exe not found or not built by the last incremental link; performing full link
LINK : fatal error LNK1104: cannot open file '\package\tests\CMakeFiles\some_test.dir\source\some_source.cpp.obj'

The contents of some_test.rsp:

dev\package\tests\CMakeFiles\some_test.dir\source\good_source.cpp.obj
dev\package\tests\CMakeFiles\some_test.dir\source\working_source.cpp.obj
dev\package\tests\CMakeFiles\some_test.dir\source\found_source.cpp.obj
dev\package\tests\CMakeFiles\some_test.dir\source\some_source.cpp.obj other.lib another.lib yet_another.lib ... [>16,383 chars]

You can see that the linker is trying to open the fourth OBJ file for this EXE at path '\package...' rather than 'dev\package...' (relative to the build directory). Weirdly, if I rename the 'dev' subfolder to anything else, then the linker complains it can't find the real file at its real path (which no longer exists).

Also, if I manually edit the problematic CMakeFiles\some_test.rsp and add a newline anywhere to break up the giant final line full of many external libraries to link, the linker will work.

I know this seems like an issue with the linker or RSP generally, but for whatever reason, it only happens with the new version of Ninja. Using -d keeprsp with Ninja 1.12.1, the build succeeds and I can see that the same RSP line still has a final line >16,383 chars.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions