From f37b21b481a7804a13c5806098c19b6119288ba4 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Tue, 23 Jun 2020 12:01:24 -0700 Subject: PR 22843: ld, gold: Add --dependency-file option. gold/ * options.h (class General_options): Add --dependency-file option. * fileread.cc (File_read::files_read): New static variable. (File_read::open): Add the file to the files_read list. (File_read::record_file_read): New static member function. (File_read::write_dependency_file): New static member function. * fileread.h (class File_read): Declare them. * layout.cc (Layout::read_layout_from_file): Call record_file_read. (Close_task_runner::run): Call write_dependency_file if --dependency-file was passed. ld/ * NEWS: Note --dependency-file. * ld.texi (Options): Document --dependency-file. * ldlex.h (enum option_values): Add OPTION_DEPENDENCY_FILE. * ld.h (ld_config_type): New member dependency_file. * lexsup.c (ld_options, parse_args): Parse --dependency-file. * ldmain.c (struct dependency_file): New type. (dependency_files, dependency_files_tail): New static variables. (track_dependency_files): New function. (write_dependency_file): New function. (main): Call it when --dependency-file was passed. * ldfile.c (ldfile_try_open_bfd): Call track_dependency_files. (ldfile_open_command_file_1): Likewise. * ldelf.c (ldelf_try_needed): Likewise. * pe-dll.c (pe_implied_import_dll): Likewise. --- gold/fileread.cc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'gold/fileread.cc') diff --git a/gold/fileread.cc b/gold/fileread.cc index bebe0ab..f5ca719 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::vector 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); + record_file_read(this->name_); } return this->descriptor_ >= 0; @@ -1138,4 +1141,31 @@ Input_file::open_binary(const Task* task, const std::string& name) binary_to_elf.converted_size()); } +void +File_read::record_file_read(const std::string& name) +{ + File_read::files_read.push_back(name); +} + +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::vector::const_iterator it = files_read.begin(); + it != files_read.end(); + ++it) + fprintf(depfile, " \\\n %s", it->c_str()); + fprintf(depfile, "\n"); + + for (std::vector::const_iterator it = files_read.begin(); + it != files_read.end(); + ++it) + fprintf(depfile, "\n%s:\n", it->c_str()); + + fclose(depfile); +} + } // End namespace gold. -- cgit v1.1