[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>
Mon, 3 Aug 2020 23:59:13 +0000 (16:59 -0700)
commit81eeabbd97f32f7cd7dbe403e2b15db6fd23ad81
treee9321a2090982a4fffab12d2cd4878751c0418ba
parent1beb00db1f5197efb73f839da681b8e439f37628
[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]