aboutsummaryrefslogtreecommitdiff
path: root/gold
diff options
context:
space:
mode:
authorRoland McGrath <mcgrathr@google.com>2020-06-23 12:01:24 -0700
committerRoland McGrath <mcgrathr@google.com>2020-06-23 12:01:24 -0700
commitf37b21b481a7804a13c5806098c19b6119288ba4 (patch)
tree3949b039081a31a28f9c9c227c7810e13ea2f25a /gold
parent236ef0346d88efffd1ca1da1a5d80724cb145660 (diff)
downloadfsf-binutils-gdb-f37b21b481a7804a13c5806098c19b6119288ba4.zip
fsf-binutils-gdb-f37b21b481a7804a13c5806098c19b6119288ba4.tar.gz
fsf-binutils-gdb-f37b21b481a7804a13c5806098c19b6119288ba4.tar.bz2
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.
Diffstat (limited to 'gold')
-rw-r--r--gold/ChangeLog13
-rw-r--r--gold/fileread.cc30
-rw-r--r--gold/fileread.h14
-rw-r--r--gold/layout.cc70
-rw-r--r--gold/options.h14
5 files changed, 103 insertions, 38 deletions
diff --git a/gold/ChangeLog b/gold/ChangeLog
index f4679f9..4d524d7 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -1,3 +1,16 @@
+2020-06-23 Roland McGrath <mcgrathr@google.com>
+
+ PR 22843
+ * 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.
+
2020-06-18 Fangrui Song <i@maskray.me>
PR gold/26039
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<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);
+ 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<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.
diff --git a/gold/fileread.h b/gold/fileread.h
index cf92367..2120135 100644
--- a/gold/fileread.h
+++ b/gold/fileread.h
@@ -207,6 +207,15 @@ 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);
+
+ // Record that a file was read. File_read::open does this.
+ static void
+ record_file_read(const std::string& name);
+
// Return the open file descriptor (for plugins).
int
descriptor()
@@ -214,7 +223,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 +256,9 @@ class File_read
// --stats.
static unsigned long long maximum_mapped_bytes;
+ // Set of names of all files read.
+ static std::vector<std::string> files_read;
+
// A view into the file.
class View
{
diff --git a/gold/layout.cc b/gold/layout.cc
index 0c7be85..13e533a 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -1183,11 +1183,11 @@ Layout::layout(Sized_relobj_file<size, big_endian>* object, unsigned int shndx,
// All ".text.unlikely.*" sections can be moved to a unique
// segment with --text-unlikely-segment option.
bool text_unlikely_segment
- = (parameters->options().text_unlikely_segment()
- && is_prefix_of(".text.unlikely",
- object->section_name(shndx).c_str()));
+ = (parameters->options().text_unlikely_segment()
+ && is_prefix_of(".text.unlikely",
+ object->section_name(shndx).c_str()));
if (text_unlikely_segment)
- {
+ {
elfcpp::Elf_Xword flags
= this->get_output_section_flags(shdr.get_sh_flags());
@@ -1196,11 +1196,11 @@ Layout::layout(Sized_relobj_file<size, big_endian>* object, unsigned int shndx,
&name_key);
os = this->get_output_section(os_name, name_key, sh_type, flags,
ORDER_INVALID, false);
- // Map this output section to a unique segment. This is done to
- // separate "text" that is not likely to be executed from "text"
- // that is likely executed.
+ // Map this output section to a unique segment. This is done to
+ // separate "text" that is not likely to be executed from "text"
+ // that is likely executed.
os->set_is_unique_segment();
- }
+ }
else
{
// Plugins can choose to place one or more subsets of sections in
@@ -1221,7 +1221,7 @@ Layout::layout(Sized_relobj_file<size, big_endian>* object, unsigned int shndx,
// We know the name of the output section, directly call
// get_output_section here by-passing choose_output_section.
elfcpp::Elf_Xword flags
- = this->get_output_section_flags(shdr.get_sh_flags());
+ = this->get_output_section_flags(shdr.get_sh_flags());
const char* os_name = it->second->name;
Stringpool::Key name_key;
@@ -1229,11 +1229,11 @@ Layout::layout(Sized_relobj_file<size, big_endian>* object, unsigned int shndx,
os = this->get_output_section(os_name, name_key, sh_type, flags,
ORDER_INVALID, false);
if (!os->is_unique_segment())
- {
- os->set_is_unique_segment();
- os->set_extra_segment_flags(it->second->flags);
- os->set_segment_alignment(it->second->align);
- }
+ {
+ os->set_is_unique_segment();
+ os->set_extra_segment_flags(it->second->flags);
+ os->set_segment_alignment(it->second->align);
+ }
}
}
if (os == NULL)
@@ -2268,9 +2268,9 @@ Layout::layout_gnu_property(unsigned int note_type,
const int size = parameters->target().get_size();
const bool is_big_endian = parameters->target().is_big_endian();
if (size == 32)
- {
- if (is_big_endian)
- {
+ {
+ if (is_big_endian)
+ {
#ifdef HAVE_TARGET_32_BIG
parameters->sized_target<32, true>()->
record_gnu_property(note_type, pr_type, pr_datasz, pr_data,
@@ -2278,9 +2278,9 @@ Layout::layout_gnu_property(unsigned int note_type,
#else
gold_unreachable();
#endif
- }
- else
- {
+ }
+ else
+ {
#ifdef HAVE_TARGET_32_LITTLE
parameters->sized_target<32, false>()->
record_gnu_property(note_type, pr_type, pr_datasz, pr_data,
@@ -2288,12 +2288,12 @@ Layout::layout_gnu_property(unsigned int note_type,
#else
gold_unreachable();
#endif
- }
- }
+ }
+ }
else if (size == 64)
- {
- if (is_big_endian)
- {
+ {
+ if (is_big_endian)
+ {
#ifdef HAVE_TARGET_64_BIG
parameters->sized_target<64, true>()->
record_gnu_property(note_type, pr_type, pr_datasz, pr_data,
@@ -2301,9 +2301,9 @@ Layout::layout_gnu_property(unsigned int note_type,
#else
gold_unreachable();
#endif
- }
- else
- {
+ }
+ else
+ {
#ifdef HAVE_TARGET_64_LITTLE
parameters->sized_target<64, false>()->
record_gnu_property(note_type, pr_type, pr_datasz, pr_data,
@@ -2311,10 +2311,10 @@ Layout::layout_gnu_property(unsigned int note_type,
#else
gold_unreachable();
#endif
- }
- }
+ }
+ }
else
- gold_unreachable();
+ gold_unreachable();
return;
}
@@ -2922,6 +2922,8 @@ Layout::read_layout_from_file()
gold_fatal(_("unable to open --section-ordering-file file %s: %s"),
filename, strerror(errno));
+ File_read::record_file_read(filename);
+
std::getline(in, line); // this chops off the trailing \n, if any
unsigned int position = 1;
this->set_section_ordering_specified();
@@ -3299,7 +3301,7 @@ Layout::create_gnu_properties_note()
write_sized_value(datasz, 4, p + 4, is_big_endian);
memcpy(p + 8, prop->second.pr_data, datasz);
if (aligned_datasz > datasz)
- memset(p + 8 + datasz, 0, aligned_datasz - datasz);
+ memset(p + 8 + datasz, 0, aligned_datasz - datasz);
p += 8 + aligned_datasz;
}
Output_section_data* posd = new Output_data_const(desc, descsz, 4);
@@ -6156,6 +6158,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 f0e9fbd..3c8d25a 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"));
@@ -1501,10 +1505,10 @@ class General_options
DEFINE_uint64(stack_size, options::DASH_Z, '\0', 0,
N_("Set PT_GNU_STACK segment p_memsz to SIZE"), N_("SIZE"));
DEFINE_enum(start_stop_visibility, options::DASH_Z, '\0', "protected",
- N_("ELF symbol visibility for synthesized "
- "__start_* and __stop_* symbols"),
- ("[default,internal,hidden,protected]"),
- {"default", "internal", "hidden", "protected"});
+ N_("ELF symbol visibility for synthesized "
+ "__start_* and __stop_* symbols"),
+ ("[default,internal,hidden,protected]"),
+ {"default", "internal", "hidden", "protected"});
DEFINE_bool(text, options::DASH_Z, '\0', false,
N_("Do not permit relocations in read-only segments"),
N_("Permit relocations in read-only segments"));