Skip to content

Windows, clang: LINK_ARGS escaping broken in 0.58 #8981

@PlushBeaver

Description

@PlushBeaver

Describe the bug
If link arguments contain a backslash, it's not escaped in LINK_ARGS in ninja.build, resulting link failure.

To Reproduce

meson.build

project('example', 'C')
def = custom_target('def',
    command: ['xcopy', '@INPUT@', '@OUTPUT@'],
    input: 'lib.def', output: 'lib.def')
lib = shared_library('lib',
    sources: files('lib.c'),
    link_args: ['-Wl,/def:' + def.full_path()])

lib.c

void func(void) {}

lib.def

EXPORTS
    func

Configure:

PS C:\Users\Administrator\Desktop\backslash> meson build
The Meson build system
Version: 0.58.1
Source dir: C:\Users\Administrator\Desktop\backslash
Build dir: C:\Users\Administrator\Desktop\backslash\build
Build type: native build
Project name: example
Project version: undefined
C compiler for the host machine: clang (clang 10.0.0 "clang version 10.0.0 ")
C linker for the host machine: clang link 14.24.28316.0
Host machine cpu family: x86_64
Host machine cpu: x86_64
Program xcopy found: YES (C:\Windows\system32\xcopy.EXE)
Build targets in project: 2

Build:

Found ninja-1.10.2 at "C:\Program Files\Meson\ninja.EXE"
PS C:\Users\Administrator\Desktop\backslash> ninja -C build
ninja: Entering directory `build'
[2/2] Linking target lib.dll
FAILED: lib.dll lib.pdb
"clang"  -Wl,/MACHINE:X64 -Wl,/OUT:lib.dll lib.dll.p/lib.c.obj "-Wl,/nologo" "-Wl,/release" "-Wl,/nologo" "-Wl,/DEBUG" "-Wl,/PDB:lib.pdb" "-Wl,/DLL" "-Wl,/IMPLIB:lib.lib" "-Wl,/def:C:\Users\Administrator\Desktop\backslash\build\lib.def" "-lkernel32" "-luser32" "-lgdi32" "-lwinspool" "-lshell32" "-lole32" "-loleaut32" "-luuid" "-lcomdlg32" "-ladvapi32"
LINK : fatal error LNK1104: cannot open file 'C:\Users\Administrator\Desktop\backslash\build\lib.def'
clang: error: linker command failed with exit code 1104 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Root cause:

build.ninja

build lib.dll | lib.pdb: c_LINKER lib.dll.p/lib.c.obj
 LINK_ARGS = "-Wl,/nologo" "-Wl,/release" "-Wl,/nologo" "-Wl,/DEBUG" "-Wl,/PDB:lib.pdb" "-Wl,/DLL" "-Wl,/IMPLIB:lib.lib" "-Wl,/def:C:\Users\Administrator\Desktop\backslash\build\lib.def" "-lkernel32" "-luser32" "-lgdi32" "-lwinspool" "-lshell32" "-lole32" "-loleaut32" "-luuid" "-lcomdlg32" "-ladvapi32"

Notice unescaped \, they are escaped (doubled) with older versions of meson. If you manually change them to double \ or to /, the build will pass.

Expected behavior
DLL builds OK, as with meson 0.57 and older.

System parameters

  • Native build
  • Windows 10
  • LLVM 10.0.0
  • Python 3.8.1
  • Meson 0.58.1
  • Ninja 1.10.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions