diff options
author | Roland McGrath <mcgrathr@google.com> | 2020-06-12 15:51:36 -0700 |
---|---|---|
committer | Roland McGrath <mcgrathr@google.com> | 2020-06-12 16:12:50 -0700 |
commit | ed7ff53cb66151038262d5fdc4f2f388a4415703 (patch) | |
tree | c746368865cc7b5690ecc8be3809502e12fce5d0 | |
parent | 6a17d503c45b69dbf92c4c2a1aa2148db458c6b1 (diff) | |
download | binutils-gdb-users/roland/gold-depfile.tar.gz |
gold: Add --dependency-file option.users/roland/gold-depfile
gold/
* options.h (class General_options): Add --dependency-file option.
* fileread.cc (File_read::files_read): New static variable.
(File_read::write_dependency_file): New static member function.
* fileread.h (class File_read): Declare them.
* layout.cc (Close_task_runner::run): Call write_dependency_file
if --dependency-file was passed.
-rw-r--r-- | gold/ChangeLog | 9 | ||||
-rw-r--r-- | gold/fileread.cc | 24 | ||||
-rw-r--r-- | gold/fileread.h | 11 | ||||
-rw-r--r-- | gold/layout.cc | 4 | ||||
-rw-r--r-- | gold/options.h | 6 |
5 files changed, 52 insertions, 2 deletions
diff --git a/gold/ChangeLog b/gold/ChangeLog index f3d37159362..357ea22d0e8 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,12 @@ +2020-06-12 Roland McGrath <mcgrathr@google.com> + + * options.h (class General_options): Add --dependency-file option. + * fileread.cc (File_read::files_read): New static variable. + (File_read::write_dependency_file): New static member function. + * fileread.h (class File_read): Declare them. + * layout.cc (Close_task_runner::run): Call write_dependency_file + if --dependency-file was passed. + 2020-06-06 Alan Modra <amodra@gmail.com> * powerpc.cc: Update throughout for reloc renaming. diff --git a/gold/fileread.cc b/gold/fileread.cc index bebe0aba8d0..e0306e7fabb 100644 --- a/gold/fileread.cc +++ b/gold/fileread.cc @@ -124,6 +124,7 @@ static Initialize_lock file_counts_initialize_lock(&file_counts_lock); unsigned long long File_read::total_mapped_bytes; unsigned long long File_read::current_mapped_bytes; unsigned long long File_read::maximum_mapped_bytes; +std::set<std::string> File_read::files_read; // Class File_read::View. @@ -211,6 +212,8 @@ File_read::open(const Task* task, const std::string& name) gold_debug(DEBUG_FILES, "Attempt to open %s succeeded", this->name_.c_str()); this->token_.add_writer(task); + Hold_optional_lock hl(file_counts_lock); + File_read::files_read.insert(this->name_); } return this->descriptor_ >= 0; @@ -1138,4 +1141,25 @@ Input_file::open_binary(const Task* task, const std::string& name) binary_to_elf.converted_size()); } +void +File_read::write_dependency_file(const char* dependency_file_name, + const char* output_file_name) +{ + FILE *depfile = fopen(dependency_file_name, "w"); + + fprintf(depfile, "%s: ", output_file_name); + for (std::set<std::string>::const_iterator it = files_read.begin(); + it != files_read.end(); + ++it) + fprintf(depfile, "\\\n %s", it->c_str()); + fprintf(depfile, "\n"); + + for (std::set<std::string>::const_iterator it = files_read.begin(); + it != files_read.end(); + ++it) + fprintf(depfile, "\n%s:\n", it->c_str()); + + fclose(depfile); +} + } // End namespace gold. diff --git a/gold/fileread.h b/gold/fileread.h index cf92367c2ca..005d2e28c84 100644 --- a/gold/fileread.h +++ b/gold/fileread.h @@ -27,6 +27,7 @@ #include <list> #include <map> +#include <set> #include <string> #include <vector> @@ -207,6 +208,11 @@ class File_read static void print_stats(); + // Write the dependency file listing all files read. + static void + write_dependency_file(const char* dependency_file_name, + const char* output_file_name); + // Return the open file descriptor (for plugins). int descriptor() @@ -214,7 +220,7 @@ class File_read this->reopen_descriptor(); return this->descriptor_; } - + // Return the file last modification time. Calls gold_fatal if the stat // system call failed. Timespec @@ -247,6 +253,9 @@ class File_read // --stats. static unsigned long long maximum_mapped_bytes; + // Set of names of all files read. + static std::set<std::string> files_read; + // A view into the file. class View { diff --git a/gold/layout.cc b/gold/layout.cc index be437f3900e..85102108682 100644 --- a/gold/layout.cc +++ b/gold/layout.cc @@ -6153,6 +6153,10 @@ Close_task_runner::run(Workqueue*, const Task*) if (this->options_->oformat_enum() != General_options::OBJECT_FORMAT_ELF) this->layout_->write_binary(this->of_); + if (this->options_->dependency_file()) + File_read::write_dependency_file(this->options_->dependency_file(), + this->options_->output_file_name()); + this->of_->close(); } diff --git a/gold/options.h b/gold/options.h index b2059d984cd..eaf8727ba3c 100644 --- a/gold/options.h +++ b/gold/options.h @@ -472,7 +472,7 @@ struct Struct_special : public Struct_var options::String_set::const_iterator \ varname__##_end() const \ { return this->varname__##_.value.end(); } \ - \ + \ options::String_set::size_type \ varname__##_size() const \ { return this->varname__##_.value.size(); } \ @@ -800,6 +800,10 @@ class General_options N_("Do not demangle C++ symbols in log messages"), NULL); + DEFINE_string(dependency_file, options::TWO_DASHES, '\0', NULL, + N_("Write a dependency file listing all files read"), + N_("FILE")); + DEFINE_bool(detect_odr_violations, options::TWO_DASHES, '\0', false, N_("Look for violations of the C++ One Definition Rule"), N_("Do not look for violations of the C++ One Definition Rule")); |