Index: lld/ELF/Driver.cpp =================================================================== --- lld/ELF/Driver.cpp +++ lld/ELF/Driver.cpp @@ -329,6 +329,18 @@ if (ErrorCount) return; + // If -o contains a directory, create the directory in the tar archive + // so that "lld @response.txt" won't fail. This is for -reproduce. + if (Tar && !Config->OutputFile.empty()) { + SmallString<256> S(Config->OutputFile); + sys::path::remove_filename(S); + + // Tar files cannot contain empty directoreis, + // so create a dummy file instead. + if (!S.empty()) + Tar->append((S + "/.keep").str(), ""); + } + switch (Config->EKind) { case ELF32LEKind: link(Args); Index: lld/ELF/DriverUtils.cpp =================================================================== --- lld/ELF/DriverUtils.cpp +++ lld/ELF/DriverUtils.cpp @@ -135,17 +135,11 @@ case OPT_INPUT: OS << quote(rewritePath(Arg->getValue())) << "\n"; break; - case OPT_o: - // If -o path contains directories, "lld @response.txt" will likely - // fail because the archive we are creating doesn't contain empty - // directories for the output path (-o doesn't create directories). - // Strip directories to prevent the issue. - OS << "-o " << quote(sys::path::filename(Arg->getValue())) << "\n"; - break; case OPT_L: + case OPT_alias_script_T: case OPT_dynamic_list: + case OPT_o: case OPT_rpath: - case OPT_alias_script_T: case OPT_script: case OPT_version_script: OS << Arg->getSpelling() << " " << quote(rewritePath(Arg->getValue())) Index: lld/test/ELF/reproduce.s =================================================================== --- lld/test/ELF/reproduce.s +++ lld/test/ELF/reproduce.s @@ -60,13 +60,12 @@ # CHECK-NEXT: repro2/{{.*}}/file2 # CHECK-NEXT: repro2/{{.*}}/file -## Check that directory path is stripped from -o +## Check that we create a directory for -o. # RUN: mkdir -p %t.dir/build3/a/b/c # RUN: cd %t.dir # RUN: ld.lld build1/foo.o -o build3/a/b/c/bar -shared --as-needed --reproduce repro3.tar -# RUN: tar xf repro3.tar -# RUN: FileCheck %s --check-prefix=RSP3 < repro3/response.txt -# RSP3: -o bar +# RUN: tar tf repro3.tar | FileCheck --check-prefix=RSP3 %s +# RSP3: repro3/build3/a/b/c/.keep .globl _start _start: