[v2,1/2] ld: write resolved path to included file to dependency-file

Message ID 20230916103619.819791-2-thomas@t-8ch.de
State New
Headers
Series Improve handling of included linker scripts in dependency-file |

Checks

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

Commit Message

Thomas Weißschuh Sept. 16, 2023, 10:36 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 resolved path is
actually available, in try_open().

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
---
 ld/ldfile.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Jan Beulich Sept. 18, 2023, 1:28 p.m. UTC | #1
On 16.09.2023 12:36, 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 resolved path is
> actually available, in try_open().
> 
> Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>

Looks okay to me, with (nit) ...

> --- a/ld/ldfile.c
> +++ b/ld/ldfile.c
> @@ -528,8 +528,10 @@ try_open (const char *name, bool *sysrooted)
>  
>    result = fopen (name, "r");
>  
> -  if (result != NULL)
> +  if (result != NULL) {

... style corrected here:

  if (result != NULL)
    {
      *sysrooted = is_sysrooted_pathname (name);
      track_dependency_files (name);
    }

Jan
  

Patch

diff --git a/ld/ldfile.c b/ld/ldfile.c
index b8fd4e5d8e0a..29938eca0bc0 100644
--- a/ld/ldfile.c
+++ b/ld/ldfile.c
@@ -528,8 +528,10 @@  try_open (const char *name, bool *sysrooted)
 
   result = fopen (name, "r");
 
-  if (result != NULL)
+  if (result != NULL) {
     *sysrooted = is_sysrooted_pathname (name);
+    track_dependency_files (name);
+  }
 
   if (verbose)
     {
@@ -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;