public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Improve handling of included linker scripts in dependency-file
@ 2023-09-16 10:36 Thomas Weißschuh
  2023-09-16 10:36 ` [PATCH v2 1/2] ld: write resolved path to included file to dependency-file Thomas Weißschuh
  2023-09-16 10:36 ` [PATCH v2 2/2] ld: write full paths " Thomas Weißschuh
  0 siblings, 2 replies; 6+ messages in thread
From: Thomas Weißschuh @ 2023-09-16 10:36 UTC (permalink / raw)
  To: binutils; +Cc: Thomas Weißschuh, Alan Modra

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

Thomas Weißschuh (2):
  ld: write resolved path to included file to dependency-file
  ld: write full paths to dependency-file

 ld/ldfile.c | 6 +++---
 ld/ldmain.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)


base-commit: 95ebc6fdec5780bf59685739cdd55cd41d0f55ac
-- 
2.42.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/2] ld: write resolved path to included file to dependency-file
  2023-09-16 10:36 [PATCH v2 0/2] Improve handling of included linker scripts in dependency-file Thomas Weißschuh
@ 2023-09-16 10:36 ` Thomas Weißschuh
  2023-09-18 13:28   ` Jan Beulich
  2023-09-16 10:36 ` [PATCH v2 2/2] ld: write full paths " Thomas Weißschuh
  1 sibling, 1 reply; 6+ messages in thread
From: Thomas Weißschuh @ 2023-09-16 10:36 UTC (permalink / raw)
  To: binutils; +Cc: Thomas Weißschuh, Alan Modra

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(-)

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;
-- 
2.42.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] ld: write full paths to dependency-file
  2023-09-16 10:36 [PATCH v2 0/2] Improve handling of included linker scripts in dependency-file Thomas Weißschuh
  2023-09-16 10:36 ` [PATCH v2 1/2] ld: write resolved path to included file to dependency-file Thomas Weißschuh
@ 2023-09-16 10:36 ` Thomas Weißschuh
  2023-09-18 13:38   ` Jan Beulich
  1 sibling, 1 reply; 6+ messages in thread
From: Thomas Weißschuh @ 2023-09-16 10:36 UTC (permalink / raw)
  To: binutils; +Cc: Thomas Weißschuh, Alan Modra

When relative paths are written to the dependency-file it forces the
users of it to run from the same directory.
To avoid this only write absolute paths.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
---
 ld/ldmain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ld/ldmain.c b/ld/ldmain.c
index 25cc89b72f90..f11ee6696125 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -174,7 +174,7 @@ track_dependency_files (const char *filename)
 {
   struct dependency_file *dep
     = (struct dependency_file *) xmalloc (sizeof (*dep));
-  dep->name = xstrdup (filename);
+  dep->name = lrealpath (filename);
   dep->next = NULL;
   if (dependency_files == NULL)
     dependency_files = dep;
-- 
2.42.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/2] ld: write resolved path to included file to dependency-file
  2023-09-16 10:36 ` [PATCH v2 1/2] ld: write resolved path to included file to dependency-file Thomas Weißschuh
@ 2023-09-18 13:28   ` Jan Beulich
  0 siblings, 0 replies; 6+ messages in thread
From: Jan Beulich @ 2023-09-18 13:28 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: Alan Modra, binutils

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/2] ld: write full paths to dependency-file
  2023-09-16 10:36 ` [PATCH v2 2/2] ld: write full paths " Thomas Weißschuh
@ 2023-09-18 13:38   ` Jan Beulich
  2023-09-18 19:35     ` Thomas Weißschuh
  0 siblings, 1 reply; 6+ messages in thread
From: Jan Beulich @ 2023-09-18 13:38 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: Alan Modra, binutils

On 16.09.2023 12:36, Thomas Weißschuh wrote:
> When relative paths are written to the dependency-file it forces the
> users of it to run from the same directory.
> To avoid this only write absolute paths.

Using relative paths, otoh, may allow to move build trees around. First and
foremost the two behaviors may relevant when (not) building in the source
tree itself. Furthermore the compiler, gcc at least, looks to also write
relative paths when relative paths were given.

Jan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/2] ld: write full paths to dependency-file
  2023-09-18 13:38   ` Jan Beulich
@ 2023-09-18 19:35     ` Thomas Weißschuh
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Weißschuh @ 2023-09-18 19:35 UTC (permalink / raw)
  To: Jan Beulich; +Cc: Alan Modra, binutils

On 2023-09-18 15:38:21+0200, Jan Beulich wrote:
> On 16.09.2023 12:36, Thomas Weißschuh wrote:
> > When relative paths are written to the dependency-file it forces the
> > users of it to run from the same directory.
> > To avoid this only write absolute paths.
> 
> Using relative paths, otoh, may allow to move build trees around. First and
> foremost the two behaviors may relevant when (not) building in the source
> tree itself. Furthermore the compiler, gcc at least, looks to also write
> relative paths when relative paths were given.

Fair enough. Let's drop this patch then.

Thomas

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-09-18 19:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-16 10:36 [PATCH v2 0/2] Improve handling of included linker scripts in dependency-file Thomas Weißschuh
2023-09-16 10:36 ` [PATCH v2 1/2] ld: write resolved path to included file to dependency-file Thomas Weißschuh
2023-09-18 13:28   ` Jan Beulich
2023-09-16 10:36 ` [PATCH v2 2/2] ld: write full paths " Thomas Weißschuh
2023-09-18 13:38   ` Jan Beulich
2023-09-18 19:35     ` Thomas Weißschuh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).