[v3] ld: write resolved path to included file to dependency-file

Message ID 20230918194226.1200853-1-thomas@t-8ch.de
State Accepted
Headers
Series [v3] ld: write resolved path to included file to dependency-file |

Checks

Context Check Description
snail/binutils-gdb-check success Github commit url

Commit Message

Thomas Weißschuh Sept. 18, 2023, 7:42 p.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>
---

v2: https://sourceware.org/pipermail/binutils/2023-September/129503.html
v2 -> v3:

  * drop "write absolute paths to dependencies"
  * fix code style in conditional

v1: https://sourceware.org/pipermail/binutils/2023-September/129475.html
v1 -> v2:
  * push call to track_dependencies() into try_open() to catch all
    dependencies
  * sign-off commits
  * write absolute paths to dependencies

 ld/ldfile.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)


base-commit: 95ebc6fdec5780bf59685739cdd55cd41d0f55ac
  

Comments

Jan Beulich Sept. 21, 2023, 6:03 a.m. UTC | #1
On 18.09.2023 21:42, 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>

Thanks, committed.

Jan
  

Patch

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