mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.54k stars 1.61k forks source link

meson strips --config from LDFLAGS when it shouldn't #13278

Open DaanDeMeyer opened 4 months ago

DaanDeMeyer commented 4 months ago

Describe the bug

When detecting the linker, LDFLAGS contains -Wl,-z,now --config /usr/lib/rpm/redhat/redhat-hardened-clang-ld.cfg, when sanity testing clang, this has been reduced to -Wl,-z,now /usr/lib/rpm/redhat/redhat-hardened-clang-ld.cfg which causes ld.lld to treat the config file as an argument which fails with:

Sanity check compile stderr:
ld.lld: error: /usr/lib/rpm/redhat/redhat-hardened-clang-ld.cfg:1: unexpected EOF
>>> -pie
>>> ^
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Full logs:

bash-5.2# cat /work/build/meson-logs/meson-log.txt
Build started at 2024-05-31T20:04:18.989266
Main binary: /usr/bin/python3
Build Options: -Dmode=developer -Dsysvinit-path=/etc/rc.d/init.d -Drc-local=/etc/rc.d/rc.local '-Dntp-servers=0.fedora.pool.ntp.org 1.fedora.pool.ntp.org 2.fedora.pool.ntp.org 3.fedora.pool.ntp.org' -Ddns-servers= -Duser-path=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin -Dservice-watchdog= -Ddev-kvm-mode=0666 -Dkmod=enabled -Dxkbcommon=enabled -Dblkid=enabled -Dfdisk=enabled -Dseccomp=enabled -Dima=true -Dselinux=enabled -Dbpf-framework=enabled -Dapparmor=disabled -Dpolkit=enabled -Dxz=enabled -Dzlib=enabled -Dbzip2=enabled -Dlz4=enabled -Dzstd=enabled -Dpam=enabled -Dacl=enabled -Dsmack=true -Dopenssl=enabled -Dcryptolib=openssl -Dp11kit=enabled -Dgcrypt=disabled -Daudit=enabled -Delfutils=enabled -Dlibcryptsetup=enabled -Dpwquality=enabled -Dqrencode=enabled -Dgnutls=enabled -Dmicrohttpd=enabled -Dvmspawn=enabled -Dlibidn2=enabled -Dlibiptc=disabled -Dlibcurl=enabled -Dlibfido2=enabled -Dxenctrl=enabled -Defi=true -Dtpm=true -Dtpm2=enabled -Dhwdb=true -Dsysusers=true -Dstandalone-binaries=true -Ddefault-kill-user-processes=false -Dfirst-boot-full-preset=true -Ddefault-network=true -Dtests=unsafe -Dinstall-tests=true -Dnobody-user=nobody -Dnobody-group=nobody -Dcompat-mutable-uid-boundaries=true -Dsplit-bin=true -Db_ndebug=false -Dman=enabled '-Dversion-tag=256~rc3' -Dshared-lib-tag=256-rc3 -Dfallback-hostname=localhost -Ddefault-dnssec=no -Ddefault-dns-over-tls=no -Ddefault-mdns=no -Ddefault-llmnr=resolve -Dstatus-unit-format-default=combined -Ddefault-timeout-sec=45 -Ddefault-user-timeout-sec=45 -Dconfigfiledir=/usr/lib -Doomd=true -Dadm-gid=4 -Dtty-gid=5 -Ddisk-gid=6 -Dlp-gid=7 -Dkmem-gid=9 -Dwheel-gid=10 -Dcdrom-gid=11 -Ddialout-gid=18 -Dutmp-gid=22 -Dtape-gid=33 -Dkvm-gid=36 -Dvideo-gid=39 -Daudio-gid=63 -Dusers-gid=100 -Dinput-gid=104 -Drender-gid=105 -Dsgx-gid=106 -Dsystemd-journal-gid=190 -Dsystemd-network-uid=192 -Dsystemd-resolve-uid=193 -Dbootloader=enabled -Dukify=enabled -Db_sanitize=address,undefined -Dprefix=/usr -Dbindir=/usr/bin -Ddatadir=/usr/share -Dincludedir=/usr/include -Dinfodir=/usr/share/info -Dlibdir=/usr/lib64 -Dlibexecdir=/usr/libexec -Dlocaledir=/usr/share/locale -Dlocalstatedir=/var -Dmandir=/usr/share/man -Dsbindir=/usr/sbin -Dsharedstatedir=/var/lib -Dsysconfdir=/etc -Dauto_features=enabled -Dbuildtype=plain -Dwrap_mode=nodownload
Python system: Linux
The Meson build system
Version: 1.4.0
Source dir: /work/src
Build dir: /work/build
Build type: native build
Project name: systemd
Project version: 256~rc3
-----------
Detecting compiler via: `clang --version` -> 0
stdout:
clang version 18.1.6 (Fedora 18.1.6-3.fc41)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Configuration file: /etc/clang/x86_64-redhat-linux-gnu-clang.cfg
-----------
Running command: clang -E -dM -
-----
-----------
Detecting linker via: `clang -Wl,--version -Wl,-z,relro -Wl,--as-needed -Wl,-z,pack-relative-relocs -Wl,-z,now --config /usr/lib/rpm/redhat/redhat-hardened-clang-ld.cfg -flto=thin -ffat-lto-objects -Wl,--build-id=sha1 -Wl,-rpath=/usr/bin/../lib/clang/18/lib/linux -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_GLIBCXX_ASSERTIONS --config /usr/lib/rpm/redhat/redhat-hardened-clang.cfg -fstack-protector-strong -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -O0 -Wp,-U_FORTIFY_SOURCE -shared-libasan -fno-sanitize=function -fuse-ld=lld` -> 0
stdout:
LLD 18.1.6 (compatible with GNU linkers)
-----------
-----------
Detecting LLD linker via: `clang -fuse-ld=lld -Wl,-v -Wl,-z,relro -Wl,--as-needed -Wl,-z,pack-relative-relocs -Wl,-z,now --config /usr/lib/rpm/redhat/redhat-hardened-clang-ld.cfg -flto=thin -ffat-lto-objects -Wl,--build-id=sha1 -Wl,-rpath=/usr/bin/../lib/clang/18/lib/linux -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_GLIBCXX_ASSERTIONS --config /usr/lib/rpm/redhat/redhat-hardened-clang.cfg -fstack-protector-strong -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -O0 -Wp,-U_FORTIFY_SOURCE -shared-libasan -fno-sanitize=function` -> 1
stdout:
LLD 18.1.6 (compatible with GNU linkers)
-----------
stderr:
ld.lld: error: undefined symbol: main
>>> referenced by /usr/bin/../lib/gcc/x86_64-redhat-linux/14/../../../../lib64/Scrt1.o:(_start)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
-----------
Sanity testing C compiler: clang
Is cross compiler: False.
Sanity check compiler command line: clang sanitycheckc.c -o sanitycheckc.exe -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_GLIBCXX_ASSERTIONS --config /usr/lib/rpm/redhat/redhat-hardened-clang.cfg -fstack-protector-strong -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -O0 -Wp,-U_FORTIFY_SOURCE -shared-libasan -fno-sanitize=function -D_FILE_OFFSET_BITS=64 -fuse-ld=lld -Wl,-z,relro -Wl,--as-needed -Wl,-z,pack-relative-relocs -Wl,-z,now /usr/lib/rpm/redhat/redhat-hardened-clang-ld.cfg -flto=thin -ffat-lto-objects -Wl,--build-id=sha1 -Wl,-rpath=/usr/bin/../lib/clang/18/lib/linux
Sanity check compile stdout:

-----
Sanity check compile stderr:
ld.lld: error: /usr/lib/rpm/redhat/redhat-hardened-clang-ld.cfg:1: unexpected EOF
>>> -pie
>>> ^
clang: error: linker command failed with exit code 1 (use -v to see invocation)

-----

meson.build:3:0: ERROR: Compiler clang cannot compile programs.

To Reproduce

Can provide reproducer if needed but it won't be a simple one.

Expected behavior

meson can sanity test clang without failing

system parameters

DaanDeMeyer commented 4 months ago

I'm pretty sure this is causing the issue from _get_basic_compiler_args:

# Add LDFLAGS from the env
sys_ld_args = env.coredata.get_external_link_args(self.for_machine, self.language)
# CFLAGS and CXXFLAGS go to both linking and compiling, but we want them
# to only appear on the command line once. Remove dupes.
largs += [x for x in sys_ld_args if x not in sys_args]

This erronously removes --config from $LDFLAGS as it's already in $CFLAGS

DaanDeMeyer commented 4 months ago

cc @jpakkane as you introduced this in 74611ecb1f06203fdd08357b3d8cc23af0f897cd