Author: Joseph Huber Date: 2026-02-26T14:00:04-06:00 New Revision: 25e15775da1c3e607f13bd40e85c54474f2f1ef7
URL: https://github.com/llvm/llvm-project/commit/25e15775da1c3e607f13bd40e85c54474f2f1ef7 DIFF: https://github.com/llvm/llvm-project/commit/25e15775da1c3e607f13bd40e85c54474f2f1ef7.diff LOG: [Clang] Add response file support to clang-linker-wrapper (#183598) Summary: This is needed on some platforms like Windows when the generated command line becomes too large. This seems to be occurring in practice so we need to support this. Uses the same basic support clang does. No test because there isn't any current infrastructure to support it, will likely be "tested" by ROCBLAS builds not failing anymore on Windows. Added: Modified: clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp Removed: ################################################################################ diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp index 619e539857fc6..c49ce44432e5a 100644 --- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp +++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp @@ -247,10 +247,38 @@ Error executeCommands(StringRef ExecutablePath, ArrayRef<StringRef> Args) { if (Verbose || DryRun) printCommands(Args); - if (!DryRun) + if (DryRun) + return Error::success(); + + // If the command line fits within system limits, execute directly. + if (sys::commandLineFitsWithinSystemLimits(ExecutablePath, Args)) { if (sys::ExecuteAndWait(ExecutablePath, Args)) return createStringError( "'%s' failed", sys::path::filename(ExecutablePath).str().c_str()); + return Error::success(); + } + + // Write the arguments to a response file and pass that instead. + auto TempFileOrErr = createOutputFile("response", "rsp"); + if (!TempFileOrErr) + return TempFileOrErr.takeError(); + + SmallString<0> Contents; + raw_svector_ostream OS(Contents); + for (StringRef Arg : llvm::drop_begin(Args)) { + sys::printArg(OS, Arg, /*Quote=*/true); + OS << " "; + } + + if (std::error_code EC = sys::writeFileWithEncoding(*TempFileOrErr, Contents)) + return createStringError("failed to write response file: %s", + EC.message().c_str()); + + std::string ResponseFile = ("@" + *TempFileOrErr).str(); + SmallVector<StringRef, 2> NewArgs = {Args.front(), ResponseFile}; + if (sys::ExecuteAndWait(ExecutablePath, NewArgs)) + return createStringError("'%s' failed", + sys::path::filename(ExecutablePath).str().c_str()); return Error::success(); } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
