[ELF] Add --dependency-file option
authorPetr Hosek <phosek@google.com>
Wed, 24 Jun 2020 03:00:04 +0000 (20:00 -0700)
committerPetr Hosek <phosek@google.com>
Thu, 30 Jul 2020 19:31:20 +0000 (12:31 -0700)
commitb4c7657ba602acde1c2ea5391c973949b9c3ce09
treef2c94731cc76d14753e73843963eb71f92fb7585
parent4c16eafe12a5f0c82303511d9d3d7acb5ffe84e4
[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
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/InputFiles.cpp
lld/ELF/Options.td
lld/test/ELF/dependency-file.s [new file with mode: 0644]