[ELF] Add --dependency-file option

Clang and GCC have a feature (-MD flag) to create a dependency file
in a format that build systems such as Make or Ninja can read, which
specifies all the additional inputs such .h files.

This change introduces the same functionality to lld bringing it to
feature parity with ld and gold which gained this feature recently.
See https://sourceware.org/bugzilla/show_bug.cgi?id=22843 for more
details and discussion.

The implementation corresponds to -MD -MP compiler flag where the
generated dependency file also includes phony targets which works
around the errors where the dependency is removed. This matches the
format used by ld and gold.

Fixes PR42806

Differential Revision: https://reviews.llvm.org/D82437
This commit is contained in:
Petr Hosek
2020-06-23 20:00:04 -07:00
parent 1beb00db1f
commit 81eeabbd97
5 changed files with 105 additions and 1 deletions

View File

@@ -110,6 +110,7 @@ Optional<MemoryBufferRef> elf::readFile(StringRef path) {
path = saver.save(config->chroot + path);
log(path);
config->dependencyFiles.insert(llvm::CachedHashString(path));
auto mbOrErr = MemoryBuffer::getFile(path, -1, false);
if (auto ec = mbOrErr.getError()) {