elf: Always append ".COUNT" to local symbols
[binutils-gdb.git] / gold / fileread.cc
index 8c46a1fbb6cbf628590d2656c8464b5078182109..12ae1b4a6e86f328825fa5ab5d5f5980d857432b 100644 (file)
@@ -1,6 +1,6 @@
 // fileread.cc -- read files for gold
 
-// Copyright (C) 2006-2014 Free Software Foundation, Inc.
+// Copyright (C) 2006-2021 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
@@ -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<std::string> File_read::files_read;
 
 // Class File_read::View.
 
@@ -211,6 +212,9 @@ 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);
+      file_counts_initialize_lock.initialize();
+      Hold_optional_lock hl(file_counts_lock);
+      record_file_read(this->name_);
     }
 
   return this->descriptor_ >= 0;
@@ -293,6 +297,7 @@ void
 File_read::lock(const Task* task)
 {
   gold_assert(this->released_);
+  gold_debug(DEBUG_FILES, "Locking file \"%s\"", this->name_.c_str());
   this->token_.add_writer(task);
   this->released_ = false;
 }
@@ -302,6 +307,7 @@ File_read::lock(const Task* task)
 void
 File_read::unlock(const Task* task)
 {
+  gold_debug(DEBUG_FILES, "Unlocking file \"%s\"", this->name_.c_str());
   this->release();
   this->token_.remove_writer(task);
 }
@@ -1136,4 +1142,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<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::vector<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.