ld: testsuite: Fix a few backslash-related issues on MinGW.
Fixes ld test cases on MinGW that fail due to incorrect use of backslashes in file paths.
Several test cases in the ld test suite are failing on MinGW due to incorrect path handling. On Windows, paths are typically constructed using backslashes (\). The test cases, however, are expecting forward slashes (/). The patch aims to correct this by ensuring that file paths are generated in a way that is compatible with MinGW’s environment. The discussion involves questions about whether ld could simply use forward slashes universally, even on Windows, to simplify path handling.
- proposer
Submits a patch to fix test case failures on MinGW related to backslash usage in file paths.
“Several relatively new test cases fail on MinGW: [...] This is because on Windows ld uses "\" instead of "/" to create full file names as shown in the log below:”
- reviewer
Questions if `ld` could use forward slashes consistently, even on Windows, to avoid such issues.
“Yet: Does it need to? If slashes work, can't ld simply use slashes?”
- reviewer
Seconded Jan Beulich's question about the root cause of the backslash usage.
“Seconded: what's the root cause, i.e. where does the backslash exactly come from?”
- proposer
Explains that the backslash originates from the linker's construction of file names.
“From the linker. It is invoked as follows: /d/Works/xcomp/build-binutils-h8300-mingw/ld/ld-new -o tmpdir/absc -L/d/Works/binutils/ld/testsuite/ld-archive -e ff tmpdir/abc.o /d/Works/binutils/ld/testsuite/ld-archive/ab.t --verbose --print-map For each library listed in ld/testsuite/ld-archive/ab.t, the linker takes the library name, prepends the libr”
- proposer
Clarifies that the tools built with MinGW are native Windows executables and use the WinAPI, which can behave differently depending on the shell.
“Don't ask me — I wasn't involved in porting the GNU tools to Windows/MinGW. :-) In any case, the tools built with MinGW are native Windows executables. They use the WinAPI directly, without a compatibility layer such as Cygwin. As a result, they can be invoked either from a Unix-like shell or from the rather crappy native”
Technical Tradeoffs
- Fixing test cases to use platform-specific path separators maintains strict adherence to OS conventions but increases test complexity.
- Modifying `ld` to always use forward slashes would simplify path handling but might deviate from native Windows conventions.
In Details
This patch addresses a cross-platform compatibility issue in the ld test suite, specifically on the MinGW (Minimalist GNU for Windows) environment. Native Windows executables, like those built by MinGW, often use backslashes (\) as path separators, whereas Unix-like systems and consequently many test scripts use forward slashes (/). The test cases in ld/testsuite/ld-archive/archive.exp were failing because ld was generating paths with backslashes, which the test harness did not expect. The discussion revolves around whether ld should be modified to always use forward slashes or if…
- ld
- The GNU linker, responsible for combining object files and libraries into an executable or shared library.
- testsuite
- A collection of tests designed to verify the correctness of a software component.
- MinGW
- Minimalist GNU for Windows, a software development environment that allows the development of native Windows applications using the GNU Compiler Collection.
- backslash
- The '\' character, commonly used as a path separator in Windows file systems.
- forward slash
- The '/' character, commonly used as a path separator in Unix-like file systems.
- WinAPI
- The Windows API (Application Programming Interface), a collection of functions and data structures used by Windows applications to interact with the operating system.