ld: write full path to included file to dependency-file

Message ID 20230914064235.275964-1-thomas@t-8ch.de
State New
Headers
Series ld: write full path to included file to dependency-file |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Testing passed

Commit Message

Thomas Weißschuh Sept. 14, 2023, 6:42 a.m. UTC
  In ldfile_open_command_file_1() name written to the dependency files is
the name as specified passed to the "INCLUDE" directive.
This is before include-path processing so the tracked dependency
location is most likely wrong.

Instead track the opened file at the point where the full path is
actually available, in ldfile_find_command_file().
---
 ld/ldfile.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)


base-commit: 95ebc6fdec5780bf59685739cdd55cd41d0f55ac
  

Comments

Alan Modra Sept. 16, 2023, 8:20 a.m. UTC | #1
On Thu, Sep 14, 2023 at 08:42:27AM +0200, Thomas Weißschuh wrote:
> In ldfile_open_command_file_1() name written to the dependency files is
> the name as specified passed to the "INCLUDE" directive.
> This is before include-path processing so the tracked dependency
> location is most likely wrong.
> 
> Instead track the opened file at the point where the full path is
> actually available, in ldfile_find_command_file().

This patch is incomplete.  ldfile_find_command_file possibly opens a
file in two places.

> ---
>  ld/ldfile.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/ld/ldfile.c b/ld/ldfile.c
> index b8fd4e5d8e0a..56b221c25d68 100644
> --- a/ld/ldfile.c
> +++ b/ld/ldfile.c
> @@ -643,6 +643,8 @@ ldfile_find_command_file (const char *name,
>      {
>        path = concat (search->name, slash, name, (const char *) NULL);
>        result = try_open (path, sysrooted);
> +      if (result)
> +	track_dependency_files (path);
>        free (path);
>        if (result)
>  	break;
> @@ -711,8 +713,6 @@ 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;
> 
> base-commit: 95ebc6fdec5780bf59685739cdd55cd41d0f55ac
> -- 
> 2.42.0
  

Patch

diff --git a/ld/ldfile.c b/ld/ldfile.c
index b8fd4e5d8e0a..56b221c25d68 100644
--- a/ld/ldfile.c
+++ b/ld/ldfile.c
@@ -643,6 +643,8 @@  ldfile_find_command_file (const char *name,
     {
       path = concat (search->name, slash, name, (const char *) NULL);
       result = try_open (path, sysrooted);
+      if (result)
+	track_dependency_files (path);
       free (path);
       if (result)
 	break;
@@ -711,8 +713,6 @@  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;