<div dir="ltr">Hi,<div><br></div><div>I'd like to propose a new feature and a flag (`--write-dependencies=<path>`) for lld so that the linker can generate a dependency file (.d file). This is analogous to `-MD` compiler flag.</div><div><br></div><div>Background:</div><div>Clang and GCC have a feature (`-MD` flag) to create a dependency file in a format that `make` and other build tools can read, so that you don't have to manually maintain dependencies between .c files and .h files. There's no similar feature for the linker, even though it seems useful in some situations.</div><div><br></div><div>In particular, if a compiler driver automatically appends a static library to the final executable but you don't know the exact path of the library, there's currently no way to keep track of that dependency. A typical example of it is `-fsanitizer=asan` which adds libasan to the linker command line. If libasan is updated, you may want to rebuild your program, but you don't want to manually write its path to a build file because that may change.</div><div><br></div><div>Proposal:</div><div>Add a new command line flag `--write-dependencies=<path>` to lld. If the flag is given, lld creates a file at a given path with the following contents:</div><div><br></div><div>  <output-file>: <input-file> ...<br></div><div><br></div>where <output-file> is a pathname of an output file and <input-file> ... is a list of pathnames of all input files. This file format is the same as the `-MD` compiler flag output.<div><br></div><div><div>Here is a change to implement the above feature: <a href="https://reviews.llvm.org/D65430">https://reviews.llvm.org/D65430</a><br></div></div><div><br></div><div>Any comments?</div><div><br></div><div>Thanks,</div><div>Rui</div></div>