Hi, thanks for the report. This is not a bug in ldc, but a regression in meson 1.12.0, so I'm reassigning it accordingly.
Meson passes the dpkg-buildflags LDFLAGS (-Wl,-z,relro) verbatim to ldc2 in the compiler sanity check, without translating them to the LDC/DMD syntax (-L=-z -L=relro). ldc2 rejects the GNU-style flag and meson reports the misleading "Compiler ldc2 cannot compile programs": Sanity check compiler command line: ldc2 -of=sanity_check_for_d.exe \sanity_check_for_d.d -release -wi -g -O2 -fcf-protection=full -Wl,-z,relro ...
ldc2: Unknown command line argument '-Wl,-z,relro'.
../meson.build:1:0: ERROR: Compiler ldc2 cannot compile programs.
Note that in the very same log meson's own linker detection does use
the correct syntax (`ldc2 -L=--version ... -L=-z -L=relro`); only the
sanity check path is broken.
The cause is in DCompiler._sanity_check_compile_args() in
mesonbuild/compilers/d.py: it appends the external link args from
get_external_link_args() without passing them through
unix_args_to_native(), which is what performs the GNU -> LDC/DMD
translation. Sanity check external args were introduced in 1.12.0
(upstream commit 797decc3e), hence the regression.
Minimal reproducer (sid chroot, meson 1.12.0-2, ldc 1:1.42.0-2):
$ cat > meson.build <<'EOT'
project('t', 'd')
executable('t', 'main.d')
EOT
$ echo 'void main(){}' > main.d
$ LDFLAGS=-Wl,-z,relro meson setup build
../meson.build:1:0: ERROR: Compiler ldc2 cannot compile programs.
Without LDFLAGS it succeeds, and with meson 1.11.1 it succeeds as
well (there the sanity check command line carries no external args at
all). This matches the failures observed in the archive: all the
affected packages failed with meson 1.12.0, while e.g. the last
successful rebuild of sambamba on reproducible-builds was done with
meson 1.11.1.
This was already reported upstream from Fedora (same -Wl,-z,relro
coming from the rpm build flags) as
https://github.com/mesonbuild/meson/issues/16115
and fixed on master by
https://github.com/mesonbuild/meson/pull/16166
commit 8ffb200b70ac75c468c5da4a9693675ac97f2e22
"d: pass link arguments through unix_args_to_native"
The fix is a one-liner and is not part of any upstream release yet
(latest tag is still 1.12.0), so it would need to be cherry-picked
into the Debian package:
--- a/mesonbuild/compilers/d.py
+++ b/mesonbuild/compilers/d.py
@@ -402,6 +402,7 @@ def _sanity_check_source_code(self) -> str:
def _sanity_check_compile_args(self, sourcename: str, binname: str
) -> T.Tuple[T.List[str],
T.List[str]]:
args, largs = super()._sanity_check_compile_args(sourcename,
binname)
+ largs = self.unix_args_to_native(largs) largs.extend(self._get_target_arch_args()) return args, largs I applied exactly this on top of the meson 1.12.0-2 package in a sid chroot and the sanity check then gets `-L=-z -L=relro` and passes, so the D packages configure again. Thanks.
OpenPGP_signature.asc
Description: OpenPGP digital signature

