[v2,2/2] ld: write full paths to dependency-file

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

Checks

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

Commit Message

Thomas Weißschuh Sept. 16, 2023, 10:36 a.m. UTC
  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(-)
  

Comments

Jan Beulich Sept. 18, 2023, 1:38 p.m. UTC | #1
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
  
Thomas Weißschuh Sept. 18, 2023, 7:35 p.m. UTC | #2
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
  

Patch

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;