Re: [PATCH] ld: don't use SAME_INODE for the duplicate-script check on hosts without inodes
Alan Modra <[email protected]>
| Newsgroups | gmane.comp.gnu.binutils |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Aug 19, 2026 at 03:44:21PM +0930, Alan Modra wrote:
> Right. binutils-2.33 through binutils-2.45 had checks that compared
> file names, which worked on windows except when people were creative
> with paths. binutils-2.46 had no check on windows and binutile-2.47
> was broken by me noticing the check wasn't enabled.
>
> I'll apply your patch.
I pushed an edited version, because I'm not sure all hosts will avoid
using a zero st_ino for files. Posix doesn't say anything about
st_ino values as far as I could see, just "The st_ino and st_dev
fields taken together uniquely identify the file within the system"
and further wording that says this is true for networked filesystems
too.
diff --git a/ld/ldfile.c b/ld/ldfile.c
index 00fe1d90d44..cad1e168af0 100644
--- a/ld/ldfile.c
+++ b/ld/ldfile.c
@@ -881,15 +881,30 @@ ldfile_find_command_file (const char *name,
the same linker script twice. */
if (stat (filename, &sbuf1) == 0)
{
- struct stat sbuf2;
+#if defined _WIN32 && ! defined __CYGWIN__
+ /* Native Windows stat reports st_ino as zero on most file
+ systems. Compare file names there. */
+ bool have_inode = sbuf1.st_ino != 0;
+#else
+ bool have_inode = true;
+#endif
+
for (script = processed_scripts;
script != NULL;
script = script->next)
- if ((open_how != script_nonT || script->open_how != script_nonT)
- && stat (script->name, &sbuf2) == 0
- && SAME_INODE (sbuf1, sbuf2))
- fatal (_("%P: error: linker script file '%s (%s)'"
- " appears multiple times\n"), filename, script->name);
+ {
+ struct stat sbuf2;
+
+ if (open_how == script_nonT && script->open_how == script_nonT)
+ continue;
+
+ if (have_inode
+ ? (stat (script->name, &sbuf2) == 0
+ && SAME_INODE (sbuf1, sbuf2))
+ : filename_cmp (filename, script->name) == 0)
+ fatal (_("%P: error: linker script file '%s (%s)'"
+ " appears multiple times\n"), filename, script->name);
+ }
}
len = strlen (filename);
--
Alan Modra