aboutsummaryrefslogtreecommitdiff
path: root/ld/ldmain.c
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 /ld/ldmain.c
parent236ef0346d88efffd1ca1da1a5d80724cb145660 (diff)
downloadgdb-f37b21b481a7804a13c5806098c19b6119288ba4.zip
gdb-f37b21b481a7804a13c5806098c19b6119288ba4.tar.gz
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 'ld/ldmain.c')
-rw-r--r--ld/ldmain.c52
1 files changed, 51 insertions, 1 deletions
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 94a745e..08be903 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -160,6 +160,53 @@ static bfd_error_handler_type default_bfd_error_handler;
struct bfd_link_info link_info;
+struct dependency_file
+{
+ struct dependency_file *next;
+ char *name;
+};
+
+static struct dependency_file *dependency_files, *dependency_files_tail;
+
+void
+track_dependency_files (const char *filename)
+{
+ struct dependency_file *dep
+ = (struct dependency_file *) xmalloc (sizeof (*dep));
+ dep->name = xstrdup (filename);
+ dep->next = NULL;
+ if (dependency_files == NULL)
+ dependency_files = dep;
+ else
+ dependency_files_tail->next = dep;
+ dependency_files_tail = dep;
+}
+
+static void
+write_dependency_file (void)
+{
+ FILE *out;
+ struct dependency_file *dep;
+
+ out = fopen (config.dependency_file, FOPEN_WT);
+ if (out == NULL)
+ {
+ einfo (_("%F%P: cannot open dependency file %s: %E\n"),
+ config.dependency_file);
+ }
+
+ fprintf (out, "%s:", output_filename);
+
+ for (dep = dependency_files; dep != NULL; dep = dep->next)
+ fprintf (out, " \\\n %s", dep->name);
+
+ fprintf (out, "\n");
+ for (dep = dependency_files; dep != NULL; dep = dep->next)
+ fprintf (out, "\n%s:\n", dep->name);
+
+ fclose (out);
+}
+
static void
ld_cleanup (void)
{
@@ -239,7 +286,7 @@ main (int argc, char **argv)
/* is_sysrooted_pathname() relies on no trailing dirsep. */
if (ld_canon_sysroot_len > 0
&& IS_DIR_SEPARATOR (ld_canon_sysroot [ld_canon_sysroot_len - 1]))
- ld_canon_sysroot [--ld_canon_sysroot_len] = '\0';
+ ld_canon_sysroot [--ld_canon_sysroot_len] = '\0';
}
else
ld_canon_sysroot_len = -1;
@@ -481,6 +528,9 @@ main (int argc, char **argv)
ldexp_finish ();
lang_finish ();
+ if (config.dependency_file != NULL)
+ write_dependency_file ();
+
/* Even if we're producing relocatable output, some non-fatal errors should
be reported in the exit status. (What non-fatal errors, if any, do we
want to ignore for relocatable output?) */