Skip to content

Clang plugin segfaulting with unregistered passes #766

@aaronmondal

Description

@aaronmondal

Bug summary
We are trying to get hipsycl to work with upstream Clang/LLVM. The fiber cpu backend seems to work, but when trying to use the plugin (-fpass-plugin) the compiler segfaults:

clang++:
.../llvm/include/llvm/IR/PassManager.h:782:
typename PassT::Result &llvm::AnalysisManager<llvm::Module>::getResult(IRUnitT &, ExtraArgTs...)
[IRUnitT = llvm::Module, ExtraArgTs = <>, PassT = llvm::PassInstrumentationAnalysis]:
  Assertion `AnalysisPasses.count(PassT::ID()) && "This analysis pass was not registered prior to being queried"' failed.

clang: error: clang frontend command failed with exit code 134

To Reproduce
Install upstream Clang/LLVM and try to use the hipSYCL plugin with HIPSYCL_USE_ACCELERATED_CPU for an OMPHOST target so that the plugin is used.

Expected behavior
No crash 🥲

Describe your setup

  • Using the branch from [CBS] Fix runtime issues with opaque pointers #765 which fixed compile-time issues with upstream Clang/LLVM.
  • We are building hipsycl using a custom Bazel overlay which we will push into https://github.com/eomii/rules_ll as soon as we get this to work. For the plugin itself we are using LLVM_ON_UNIX, HIPSYCL_WITH_ACCELERATED_CPU, HIPSYCL_COMPILER_COMPONENT.
  • For executables we emulate the syclcc-clang python script by adding -D__HIPSYCL_OMPHOST_TARGET__, -fpass-plugin=..., -D__HIPSYCL_USE_ACCELERATED_CPU__.

Optional additional diagnostic information
When using only -fpass-plugin, we get the error above. With -mllvm -opt-bisect-limit=<various limits> (and trying various optimization levels) we only get

Additional context

  • With -fplugin, the compiler just segfaults without any warnings, backtrace or anything. Just says (Segmentation fault): clang++ failed: error executing command ....
  • With -fpass-plugin we get the error posted at the top and a debug stacktrace (trying to make this somewhat readable 😅)
clang++:
  external/@rules_ll.override.llvm_project_overlay.llvm-project/llvm/include/llvm/IR/PassManager.h:782:
    typename PassT::Result&llvm::AnalysisManager<llvm::Module>::getResult(IRUnitT &, ExtraArgTs...) [IRUnitT = llvm::Module, ExtraArgTs = <>, PassT = llvm::PassInstrumentationAnalysis]:
      Assertion `AnalysisPasses.count(PassT::ID()) && "This analysis pass was not registered prior to being queried"' failed.


0.     Program arguments: bazel-out/k8-dbg-ST-d2d72091753b/bin/external/@rules_ll.override.llvm_project_overlay.llvm-project/clang/clang++ 
-fcolor-diagnostics -v -fdebug-default-version=5 -fdebug-compilation-dir=. -Xarch_host -glldb 
-c -fPIC 
-D__HIPSYCL_ENABLE_OMPHOST_TARGET__ 
-fpass-plugin=bazel-out/k8-dbg/bin/external/@hipsycl.override/hipsycl-plugin.so 
-D__HIPSYCL_USE_ACCELERATED_CPU__ 
-Xarch_host -MJbazel-out/k8-dbg-ST-0fdaae6d89e0/bin/sycl_example/main.cdf 
-nostdlib++
-nostdinc++ 
-nostdlib 
--gcc-toolchain=NONE 
-resource-dir=bazel-out/k8-dbg-ST-0fdaae6d89e0/bin/external/@rules_ll.override.llvm_project_overlay.llvm-project/clang/staging 
-isystembazel-out/k8-dbg-ST-0fdaae6d89e0/bin/external/@rules_ll.override.llvm_project_overlay.llvm-project/libcxx/include 
-isystembazel-out/k8-dbg-ST-0fdaae6d89e0/bin/external/@rules_ll.override.llvm_project_overlay.llvm-project/libcxxabi/include 
-isystembazel-out/k8-dbg-ST-0fdaae6d89e0/bin/externa//@rules_ll.override.llvm_project_overlay.llvm-project/libunwind/include 
-isystembazel-out/k8-dbg-ST-0fdaae6d89e0/bin/external/@rules_ll.override.llvm_project_overlay.llvm-project/clang/staging 
-isystemexternal/@rules_ll.override.llvm_project_overlay.llvm-project/libcxx/include 
-isystemexternal/@rules_ll.override.llvm_project_overlay.llvm-project/libcxxabi/include 
-isystemexternal/@rules_ll.override.llvm_project_overlay.llvm-project/libunwind/include 
-std=c++17 
-I/mnt/hipSYCL/include -g -O0 
-fno-omit-frame-pointer sycl_example/main.cpp 
-o bazel-out/k8-dbg-ST-0fdaae6d89e0/bin/sycl_example/main.o

1.      <eof> parser at end of file
                                                                                                                                             
2.      Optimizer                                                                                                                                                               
 #0 0x0000558af98250fa llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) .../llvm/lib/Support/Unix/Signals.inc:569:11                                                                                                                                                                
 #1 0x0000558af98252ab PrintStackTraceSignalHandler(void*) .../llvm/lib/Support/Unix/Signals.inc:636:1 
 #2 0x0000558af98232b6 llvm::sys::RunSignalHandlers() .../llvm/lib/Support/Signals.cpp:103:5           
 #3 0x0000558af982493e llvm::sys::CleanupOnSignal(unsigned long) .../llvm/lib/Support/Unix/Signals.inc:362:1                                                                                                                                                                           
 #4 0x0000558af9757ffe (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) .../llvm/lib/Support/CrashRecoveryContext.cpp:0:7                                                                                                                              
 #5 0x0000558af9758463 CrashRecoverySignalHandler(int) .../llvm/lib/Support/CrashRecoveryContext.cpp:390:1                                                                                                                                                                             
 #6 0x00007f62f65111a0 (/lib64/libc.so.6+0x3e1a0)                                                                                                                               
 #7 0x00007f62f6560f9c __pthread_kill_implementation /usr/src/debug/sys-libs/glibc-2.34-r13/glibc-2.34/nptl/pthread_kill.c:44:76                                                
 #8 0x00007f62f65110f2 gsignal /usr/src/debug/sys-libs/glibc-2.34-r13/glibc-2.34/signal/../sysdeps/posix/raise.c:27:6                                                           
 #9 0x00007f62f64fb46a abort /usr/src/debug/sys-libs/glibc-2.34-r13/glibc-2.34/stdlib/abort.c:81:7                                                                              
#10 0x00007f62f64fb395 _nl_load_domain /usr/src/debug/sys-libs/glibc-2.34-r13/glibc-2.34/intl/loadmsgcat.c:1177:9                                                               
#11 0x00007f62f6509df2 (/lib64/libc.so.6+0x36df2)                                                                                                                               
#12 0x00007f62f00e1f6b llvm::PassInstrumentationAnalysis::Result& llvm::AnalysisManager<llvm::Module>::getResult<llvm::PassInstrumentationAnalysis>(llvm::Module&) .../llvm/include/llvm/IR/PassManager.h:784:23

clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)

I will try to create a reproducer ready with CMake and upstream Clang/LLVM to make sure this is not coming from our custom toolchain. I believe this issue comes somewhere from changes in the passmanager implementations in upstream. Seems like pass registration is somehow broken.

I will investigate this further and post any findings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions