Index: ELF/Config.h =================================================================== --- ELF/Config.h +++ ELF/Config.h @@ -224,6 +224,9 @@ // True if we are creating position-independent code. bool Pic; + // True if we are running invocation from reproduce file for debug. + bool UsingReproduce; + // 4 for ELF32, 8 for ELF64. int Wordsize; }; Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -366,6 +366,8 @@ } } + Config->UsingReproduce = Args.hasArg(OPT_reproduce_use); + readConfigs(Args); initLLVM(Args); createFiles(Args); Index: ELF/DriverUtils.cpp =================================================================== --- ELF/DriverUtils.cpp +++ ELF/DriverUtils.cpp @@ -139,6 +139,9 @@ SmallString<0> Data; raw_svector_ostream OS(Data); + // Place marker argument informing it is debug invocation. + OS << "--reproduce-use\n"; + // Copy the command line to the output while rewriting paths. for (auto *Arg : Args) { switch (Arg->getOption().getID()) { Index: ELF/Options.td =================================================================== --- ELF/Options.td +++ ELF/Options.td @@ -207,6 +207,9 @@ def reproduce: S<"reproduce">, HelpText<"Dump linker invocation and input files for debugging">; +def reproduce_use: F<"reproduce-use">, + HelpText<"Informs linker about its running debug reproduce invocation">; + def rpath: S<"rpath">, HelpText<"Add a DT_RUNPATH to the output">; def relocatable: F<"relocatable">, HelpText<"Create relocatable object file">; Index: ELF/ScriptParser.cpp =================================================================== --- ELF/ScriptParser.cpp +++ ELF/ScriptParser.cpp @@ -256,7 +256,12 @@ } } + if (Config->UsingReproduce && + sys::path::is_absolute(S, sys::path::Style::posix)) + S = sys::path::relative_path(S, sys::path::Style::posix); + if (sys::path::is_absolute(S)) { + assert(!Config->UsingReproduce); Driver->addFile(S, /*WithLOption=*/false); } else if (S.startswith("=")) { if (Config->Sysroot.empty())