Cisco-Talos / clamav

ClamAV - Documentation is here: https://docs.clamav.net
https://www.clamav.net/
GNU General Public License v2.0
4.49k stars 709 forks source link

Building with "-D BYTECODE_RUNTIME=llvm" builds fail with llvm >=14 #581

Open opoplawski opened 2 years ago

opoplawski commented 2 years ago

Describe the bug

Trying to build clamav 0.104.3 on Fedora rawhide. Get:

[ 16%] Building C object libclamav/CMakeFiles/tomsfastmath.dir/tomsfastmath/bin/fp_unsigned_bin_size.c.o
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp: In function 'void cli_detect_env_jit(cli_environment*)':
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:66:42: error: conversion from 'llvm::StringRef' to non-scalar type 'std::string' {aka 'std::__cxx11::basic_string<char>'} requested
   66 |     std::string cpu = sys::getHostCPUName();
      |                       ~~~~~~~~~~~~~~~~~~~^~
cd /home/orion/fedora/clamav/clamav-0.104.3/redhat-linux-build/libclamav && /usr/bin/gcc -DHAVE_CONFIG_H -DTHIS_IS_LIBCLAMAV -I/usr/include/libxml2 -I/home/orion/fedora/clamav/clamav-0.104.3/redhat-linux-build/libclamav -I/home/orion/fedora/clamav/clamav-0.104.3/libclamunrar_iface -I/home/orion/fedora/clamav/clamav-0.104.3/libclamav/.. -I/home/orion/fedora/clamav/clamav-0.104.3/redhat-linux-build -I/home/orion/fedora/clamav/clamav-0.104.3/libclamav -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1      -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -O2 -g   -fPIC  -Wall -Wextra -Wformat-security -std=gnu90 -MD -MT libclamav/CMakeFiles/tomsfastmath.dir/tomsfastmath/bin/fp_unsigned_bin_size.c.o -MF CMakeFiles/tomsfastmath.dir/tomsfastmath/bin/fp_unsigned_bin_size.c.o.d -o CMakeFiles/tomsfastmath.dir/tomsfastmath/bin/fp_unsigned_bin_size.c.o -c /home/orion/fedora/clamav/clamav-0.104.3/libclamav/tomsfastmath/bin/fp_unsigned_bin_size.c
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'Ananas' not handled in switch [-Wswitch]
  146 |     switch (os) {
      |            ^
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'CloudABI' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'Fuchsia' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'IOS' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'KFreeBSD' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'MacOSX' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'ZOS' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'RTEMS' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'NaCl' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'AIX' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'CUDA' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'NVCL' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'AMDHSA' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'PS4' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'ELFIAMCU' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'TvOS' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'WatchOS' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'Mesa3D' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'Contiki' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'AMDPAL' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'HermitCore' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'Hurd' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'WASI' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'Emscripten' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:146:12: warning: enumeration value 'LastOSType' not handled in switch [-Wswitch]
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:181:39: error: 'AllocateRWX' is not a member of 'llvm::sys::Memory'
  181 |     sys::MemoryBlock B = sys::Memory::AllocateRWX(4096, NULL, &ErrMsg);
      |                                       ^~~~~~~~~~~
/home/orion/fedora/clamav/clamav-0.104.3/libclamav/c++/detect.cpp:186:22: error: 'ReleaseRWX' is not a member of 'llvm::sys::Memory'
  186 |         sys::Memory::ReleaseRWX(B);
      |                      ^~~~~~~~~~

How to reproduce the problem

+ CFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-stro
ng -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1         -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection'
+ export CFLAGS
+ CXXFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-st
rong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1       -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection'
+ export CXXFLAGS
+ FFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-stro
ng -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1         -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -I/usr/lib64/gfortran/modules'
+ export FFLAGS
+ FCFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-str
ong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1        -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -I/usr/lib64/gfortran/modules'
+ export FCFLAGS
+ LDFLAGS='-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -Wl,--build-id=sha1 -Wl,-dT,/home/orion/fedora/clamav/clamav-0.104.3/.package_note-clamav-0
.104.3-1.fc37.x86_64.ld'
+ export LDFLAGS
+ LT_SYS_LIBRARY_PATH=/usr/lib64:
+ export LT_SYS_LIBRARY_PATH
+ CC=gcc
+ export CC
+ CXX=g++
+ export CXX
+ '[' -f /usr/lib/rpm/generate-rpm-note.sh ']'
+ /usr/lib/rpm/generate-rpm-note.sh clamav 0.104.3-1.fc37 x86_64
+ cd clamav-0.104.3
++ echo -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -Wl,-dT,/home/orion/fedora/clamav/clamav-0.104.3/.package_note-clamav-0.104.
3-1.fc37.x86_64.ld
++ sed '/-Wl,--as-needed/!s/$/ -Wl,--as-needed/'
+ export 'LDFLAGS=-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -Wl,-dT,/home/orion/fedora/clamav/clamav-0.104.3/.package_note-cla
mav-0.104.3-1.fc37.x86_64.ld'
+ LDFLAGS='-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -Wl,-dT,/home/orion/fedora/clamav/clamav-0.104.3/.package_note-clamav-0.1
04.3-1.fc37.x86_64.ld'
+ export have_cv_ipv6=yes
+ have_cv_ipv6=yes
+ CFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-stro
ng -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1         -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection'
+ export CFLAGS
+ CXXFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-st
rong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1       -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection'
+ export CXXFLAGS
+ FFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-stro
ng -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1         -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -I/usr/lib64/gfortran/modules'
+ export FFLAGS
+ FCFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-str
ong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1        -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -I/usr/lib64/gfortran/modules'
+ export FCFLAGS
+ LDFLAGS='-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -Wl,-dT,/home/orion/fedora/clamav/clamav-0.104.3/.package_note-clamav-0.104.3-1.fc37.x86_64.ld'
+ export LDFLAGS
+ LT_SYS_LIBRARY_PATH=/usr/lib64:
+ export LT_SYS_LIBRARY_PATH
+ CC=gcc
+ export CC
+ CXX=g++
+ export CXX
+ /usr/bin/cmake -S . -B redhat-linux-build -DCMAKE_C_FLAGS_RELEASE:STRING=-DNDEBUG -DCMAKE_CXX_FLAGS_RELEASE:STRING=-DNDEBUG -DCMAKE_Fortran_FLAGS_RELEASE:STRING=-DNDEBUG -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_INSTALL_DO_STRIP:BOOL=OFF -DCMAKE_INSTALL_PREFIX:PATH=/usr -DINCLUDE_INSTALL_DIR:PATH=/usr/include -DLIB_INSTALL_DIR:PATH=/usr/lib64 -DSYSCONF_INSTALL_DIR:PATH=/etc -DSHARE_INSTALL_PREFIX:PATH=/usr/share -DLIB_SUFFIX=64 -DBUILD_SHARED_LIBS:BOOL=ON -DCLAMAV_USER=clamupdate -DCLAMAV_GROUP=clamupdate -DBYTECODE_RUNTIME=llvm -D LLVM_FIND_VERSION=3.6.0 -DENABLE_UNRAR=OFF
ragusaa commented 2 years ago

Thank you for the report. I am working on reproducing the problem now, will let you know when I have something.

ragusaa commented 2 years ago

AllocateRWX and ReleaseRWX have been replaced by allocateMappedMemory and releaseMappedMemory. It appears that there are other changes that have been made as well. I do not know at this time when upgrading our code to work with llvm 14 will be scheduled. I will keep you updated.

opoplawski commented 2 years ago

Indeed, it looks like clamav doesn't support llvm > 3.6.2.

ragusaa commented 2 years ago

I have tested llvm 8 - 12 with clam. Are you having issues building with those versions?

EDITED: you are correct, llvm works on 0.105.

opoplawski commented 2 years ago

Thanks, we'll try again when we shift to 0.105 - which will probably be a while due to the shift to rust.

Kangie commented 1 year ago

@ragusaa Any update on the scheduling for this one? Gentoo has recently moved to the point that the only available versions of LLVM from the default repositories are >=14

ragusaa commented 1 year ago

Unfortunately, I don't have an update on when this will be scheduled.

Kangie commented 1 year ago

I just wanted to ping on this one again; it's been a few months and we're now looking at LLVM 14-16 marked stable for most arches in Gentoo, with 17 on the way. I'm quite interested in enabling our users to optionally set BYTECODE_RUNTIME=llvm to take advantage of the feature at some point.

It looks like clamav is gearing up for 1.2.0 (yay) but a quick test on main seems to indicate that it's still broken; I guess this will be at least 1.3.0 away!

Please consider this an 'I'm very interested' rather than another request for a scheduling update :smile:

Edit: Can we update the issue title, too? Something more descriptive like "-DBYTECODE_RUNTIME=llvm builds fail with llvm >=14"; I always forget which issue this is when I check back for updates, and everything else works fine with every version of LLVM I've tested!

micahsnyder commented 1 year ago

We're presently working on updating the LLVM support in the bytecode compiler and plan to address LLVM runtime support after that. But you're right, it won't make 1.2.0.