llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.43k stars 11.75k forks source link

Failed to build pytorch from source with libFuzzer flags #95791

Open Wakotu opened 3 months ago

Wakotu commented 3 months ago

I encountered the fatal error: error in backend: Cannot emit physreg copy instruction error when I tried to build pytorch with clang-14.0.0 with the following script:

export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}
export CC="clang"
export CFLAGS="-fsanitize=address,fuzzer-no-link"
export CXX="clang++"
export CXXFLAGS="-fsanitize=address,fuzzer-no-link"
export LDSHARED="clang -shared"
python3 setup.py develop

I run the above script in a conda virtual env. env specs at the end environment.yml section.

Preprocessed source(s) and associated run script(s) are attached. fbgemm.zip

Reported Error

failed target:

FAILED: third_party/fbgemm/CMakeFiles/fbgemm_avx512.dir/src/FbgemmSparseDenseInt8Avx512.cc.o

stack dump:

0.      Program arguments: /usr/local/bin/clang++ -DFBGEMM_STATIC -I/root/atheris/pytorch/third_party/cpuinfo/include -I/root/atheris/pytorch/third_party/fbgemm/third_party/asmjit/src -I/root/atheris/pytorch/third_party/fbgemm/include -I/root/atheris/pytorch/third_party/fbgemm -I/root/atheris/pytorch/cmake/../third_party/benchmark/include -isystem /root/atheris/pytorch/cmake/../third_party/googletest/googlemock/include -isystem /root/atheris/pytorch/cmake/../third_party/googletest/googletest/include -isystem /root/atheris/pytorch/third_party/protobuf/src -isystem /root/miniconda3/envs/atheris/include -isystem /root/atheris/pytorch/third_party/XNNPACK/include -fsanitize=address,fuzzer-no-link -D_GLIBCXX_USE_CXX11_ABI=1 -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp=libomp -Wall -Wextra -Werror -Wno-deprecated-declarations -Wimplicit-fallthrough -O3 -DNDEBUG -std=c++17 -fPIC -fvisibility=hidden -DMKL_HAS_SBGEMM -m64 -mavx2 -mfma -mavx512f -mavx512bw -mavx512dq -mavx512vl -MD -MT third_party/fbgemm/CMakeFiles/fbgemm_avx512.dir/src/FbgemmSparseDenseInt8Avx512.cc.o -MF third_party/fbgemm/CMakeFiles/fbgemm_avx512.dir/src/FbgemmSparseDenseInt8Avx512.cc.o.d -o third_party/fbgemm/CMakeFiles/fbgemm_avx512.dir/src/FbgemmSparseDenseInt8Avx512.cc.o -c /root/atheris/pytorch/third_party/fbgemm/src/FbgemmSparseDenseInt8Avx512.cc
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module '/root/atheris/pytorch/third_party/fbgemm/src/FbgemmSparseDenseInt8Avx512.cc'.
4.      Running pass 'Post-RA pseudo instruction expansion pass' on function '@_ZN6fbgemm8internalL19interleave4RowsTileILi2EEEviiPKhPhii'
 #0 0x00000000027152c3 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/local/bin/clang+++0x27152c3)
 #1 0x000000000271321e llvm::sys::RunSignalHandlers() (/usr/local/bin/clang+++0x271321e)
 #2 0x000000000271476d llvm::sys::CleanupOnSignal(unsigned long) (/usr/local/bin/clang+++0x271476d)
 #3 0x0000000002689e4a (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) CrashRecoveryContext.cpp:0:0
 #4 0x0000000002689deb (/usr/local/bin/clang+++0x2689deb)
 #5 0x000000000270fdc7 llvm::sys::Process::Exit(int, bool) (/usr/local/bin/clang+++0x270fdc7)
 #6 0x0000000000a1a832 (/usr/local/bin/clang+++0xa1a832)
 #7 0x000000000268dce1 llvm::report_fatal_error(llvm::Twine const&, bool) (/usr/local/bin/clang+++0x268dce1)
 #8 0x000000000268dbb6 (/usr/local/bin/clang+++0x268dbb6)
 #9 0x000000000183e703 llvm::X86InstrInfo::copyPhysReg(llvm::MachineBasicBlock&, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>, llvm::DebugLoc const&, llvm::MCRegister, llvm::MCRegister, bool) const (/usr/local/bin/clang+++0x183e703)
#10 0x0000000001e9c0bb (anonymous namespace)::ExpandPostRA::runOnMachineFunction(llvm::MachineFunction&) ExpandPostRAPseudos.cpp:0:0
#11 0x0000000001c50a3e llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/usr/local/bin/clang+++0x1c50a3e)
#12 0x00000000020034cd llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/local/bin/clang+++0x20034cd)
#13 0x000000000200a843 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/local/bin/clang+++0x200a843)
#14 0x00000000020040a0 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/local/bin/clang+++0x20040a0)
#15 0x000000000295f15d clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/usr/local/bin/clang+++0x295f15d)
#16 0x00000000034bd94c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/usr/local/bin/clang+++0x34bd94c)
#17 0x0000000004102814 clang::ParseAST(clang::Sema&, bool, bool) (/usr/local/bin/clang+++0x4102814)
#18 0x0000000002f4d989 clang::FrontendAction::Execute() (/usr/local/bin/clang+++0x2f4d989)
#19 0x0000000002ecac96 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/local/bin/clang+++0x2ecac96)
#20 0x0000000002ffe83b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/local/bin/clang+++0x2ffe83b)
#21 0x0000000000a1a452 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/local/bin/clang+++0xa1a452)
#22 0x0000000000a187fb ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#23 0x0000000002d6c032 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const::$_1>(long) Job.cpp:0:0
#24 0x0000000002689dcd llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/usr/local/bin/clang+++0x2689dcd)
#25 0x0000000002d6bca5 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const (/usr/local/bin/clang+++0x2d6bca5)
#26 0x0000000002d39f6d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Comman
d const*&) const (/usr/local/bin/clang+++0x2d39f6d)
#27 0x0000000002d3a1b7 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/usr/local/bin/clang+++0x2d3a1b7)
#28 0x0000000002d518d8 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/usr/local/bin/clang+++0x2d518d8)
#29 0x0000000000a17f6c main (/usr/local/bin/clang+++0xa17f6c)
#30 0x00007f1fb5cacd90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#31 0x00007f1fb5cace40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#32 0x0000000000a1562a _start (/usr/local/bin/clang+++0xa1562a)
clang-14: error: clang frontend command failed with exit code 70 (use -v to see invocation)

Clang version info

clang version 14.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin

Environment.yml

name: atheris
channels:
  - pytorch
  - defaults
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - astunparse=1.6.3=py_0
  - blas=1.0=mkl
  - brotli-python=1.0.9=py310h6a678d5_8
  - bzip2=1.0.8=h5eee18b_6
  - c-ares=1.19.1=h5eee18b_0
  - ca-certificates=2024.3.11=h06a4308_0
  - certifi=2024.6.2=py310h06a4308_0
  - cffi=1.16.0=py310h5eee18b_1
  - charset-normalizer=2.0.4=pyhd3eb1b0_0
  - cmake=3.26.4=h96355d8_0
  - dataclasses=0.8=pyh6d0b6a4_7
  - expat=2.6.2=h6a678d5_0
  - future=0.18.3=py310h06a4308_0
  - idna=3.7=py310h06a4308_0
  - intel-openmp=2023.1.0=hdb19cb5_46306
  - krb5=1.20.1=h143b758_1
  - ld_impl_linux-64=2.38=h1181459_1
  - libcurl=8.7.1=h251f7ec_0
  - libedit=3.1.20230828=h5eee18b_0
  - libev=4.33=h7f8727e_1
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libnghttp2=1.57.0=h2d74bed_0
  - libssh2=1.11.0=h251f7ec_0
  - libstdcxx-ng=11.2.0=h1234567_1
  - libuuid=1.41.5=h5eee18b_0
  - libuv=1.44.2=h5eee18b_0
  - lz4-c=1.9.4=h6a678d5_1
  - magma-cuda121=2.6.1=1
  - mkl=2023.1.0=h213fc3f_46344
  - mkl-include=2023.1.0=h06a4308_46344
  - mkl-service=2.4.0=py310h5eee18b_1
  - mkl_fft=1.3.8=py310h5eee18b_0
  - mkl_random=1.2.4=py310hdb19cb5_0
  - ncurses=6.4=h6a678d5_0
  - ninja=1.10.2=h06a4308_5
  - ninja-base=1.10.2=hd09550d_5
  - numpy=1.26.4=py310h5f9d8c6_0
  - numpy-base=1.26.4=py310hb5e798b_0
  - openssl=3.0.14=h5eee18b_0
  - pip=24.0=py310h06a4308_0
  - pycparser=2.21=pyhd3eb1b0_0
  - pysocks=1.7.1=py310h06a4308_0
  - python=3.10.14=h955ad1f_1
  - pyyaml=6.0.1=py310h5eee18b_0
  - readline=8.2=h5eee18b_0
  - requests=2.32.2=py310h06a4308_0
  - rhash=1.4.3=hdbd6064_0
  - setuptools=69.5.1=py310h06a4308_0
  - six=1.16.0=pyhd3eb1b0_1
  - sqlite=3.45.3=h5eee18b_0
  - tbb=2021.8.0=hdb19cb5_0
  - tk=8.6.14=h39e8969_0
  - typing_extensions=4.11.0=py310h06a4308_0
  - tzdata=2024a=h04d1e81_0
  - urllib3=2.2.1=py310h06a4308_0
  - wheel=0.43.0=py310h06a4308_0
  - xz=5.4.6=h5eee18b_1
  - yaml=0.2.5=h7b6447c_0
  - zlib=1.2.13=h5eee18b_1
  - zstd=1.5.5=hc292b87_2
  - pip:
      - atheris==2.3.0
EugeneZelenko commented 3 months ago

Could you please try 18 or main branch?

Wakotu commented 3 months ago

Could you please try 18 or main branch?

the pytorch cmake build system requires clang version to be less than 15. I may try clang 15 at some time.

EugeneZelenko commented 3 months ago

@Wakotu: Even 18 is no longer maintained.

Wakotu commented 3 months ago

@Wakotu: Even 18 is no longer maintained.

I succeed with llvm-11 in Debian v11(bullseye). Thanks for answering.