[PATCH] ld: Unify the directory separator on Windows.

Jan Dubiec <[email protected]> Wed, 22 Jul 2026 10:42:55 +0200
Newsgroups gmane.comp.gnu.binutils
Message-ID <[email protected]>
This patch is a spin-off of the following discussion:
https://inbox.sourceware.org/binutils/[email protected]/

When the linker searches for a file, it constructs the full file name by
concatenating the search path, the directory separator, and the file name.
As a result, on Windows users may encounter paths like this:

[...]
attempt to open D:/Works/binutils/ld/testsuite/ld-archive\tmpdir/a.o failed
[...]

or even like this:

[...]
D:\Works\xcomp\build-binutils-h8300-mingw\ld\ld-new.exe: cannot open linker script file D:/Works/binutils/ld/testsuite/ld-scripts\././././.\././././.\././././.\././././.\././././.\././././.\././././.\././././.\././././.\././././.\././././.\././././.\././././.\././././.\././././.\././././.\././././.\././././.\././././.\././././.\./././././/libpr33265-2.a: No such file or directory
[...]

This is a safe change, as the linker has been using forward slashes on
Windows for a long time, and this piece of code appears to be a leftover
from the dark Windows 9x era.

Signed-off-by: Jan Dubiec <[email protected]>
---
 ld/ldfile.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/ld/ldfile.c b/ld/ldfile.c
index f47e860d437..00fe1d90d44 100644
--- a/ld/ldfile.c
+++ b/ld/ldfile.c
@@ -47,12 +47,8 @@ search_dirs_type *search_head;
 #ifdef VMS
 static char *slash = "";
 #else
-#if defined (_WIN32) && !defined (__CYGWIN32__)
-static char *slash = "\\";
-#else
 static char *slash = "/";
 #endif
-#endif
 
 typedef struct search_arch
 {
-- 
2.54.0