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.
This commit is contained in:
Roland McGrath
2020-06-23 12:01:24 -07:00
parent 236ef0346d
commit f37b21b481
16 changed files with 230 additions and 60 deletions

View File

@@ -142,6 +142,8 @@ ldfile_try_open_bfd (const char *attempt,
return FALSE;
}
track_dependency_files (attempt);
/* Linker needs to decompress sections. */
entry->the_bfd->flags |= BFD_DECOMPRESS;
@@ -416,21 +418,21 @@ ldfile_open_file (lang_input_statement_type *entry)
bfd_boolean found = FALSE;
/* If extra_search_path is set, entry->filename is a relative path.
Search the directory of the current linker script before searching
other paths. */
Search the directory of the current linker script before searching
other paths. */
if (entry->extra_search_path)
{
char *path = concat (entry->extra_search_path, slash, entry->filename,
(const char *)0);
if (ldfile_try_open_bfd (path, entry))
{
entry->filename = path;
entry->flags.search_dirs = FALSE;
return;
}
{
char *path = concat (entry->extra_search_path, slash, entry->filename,
(const char *)0);
if (ldfile_try_open_bfd (path, entry))
{
entry->filename = path;
entry->flags.search_dirs = FALSE;
return;
}
free (path);
}
}
/* Try to open <filename><suffix> or lib<filename><suffix>.a. */
for (arch = search_arch_head; arch != NULL; arch = arch->next)
@@ -675,6 +677,8 @@ ldfile_open_command_file_1 (const char *name, enum script_open_style open_how)
return;
}
track_dependency_files (name);
lex_push_file (ldlex_input_stack, name, sysrooted);
lineno = 1;