llvm / llvm-project

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

Pass manager crashes when StackProtectorPass is removed from pipeline #69816

Open reSHARMA opened 10 months ago

reSHARMA commented 10 months ago

Clang crashes on any valid c code when StackProtectorPass is removed from the pass pipeline by commenting addPass(createStackProtectorPass()); in TargetPassConfig::addISelPrepare

Crash dump:

Unable to schedule 'Function Alias Analysis Results' required by 'X86 DAG->DAG Instruction Selection'
Unable to schedule pass
UNREACHABLE executed at /home/reshabhsh/llvm-upstream/llvm/lib/IR/LegacyPassManager.cpp:1289!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.  Program arguments: /home/reshabhsh/llvm-upstream/build/bin/clang-18 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name test.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/reshabhsh/SLVA/test-suite -fcoverage-compilation-dir=/home/reshabhsh/SLVA/test-suite -resource-dir /home/reshabhsh/llvm-upstream/build/lib/clang/18 -internal-isystem /home/reshabhsh/llvm-upstream/build/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -ferror-limit 19 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/test-ffe224.o -x c test.c
1.  <eof> parser at end of file
 #0 0x00007fb9113e3f38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/reshabhsh/llvm-upstream/llvm/lib/Support/Unix/Signals.inc:723:22
 #1 0x00007fb9113e4354 PrintStackTraceSignalHandler(void*) /home/reshabhsh/llvm-upstream/llvm/lib/Support/Unix/Signals.inc:798:1
 #2 0x00007fb9113e17a1 llvm::sys::RunSignalHandlers() /home/reshabhsh/llvm-upstream/llvm/lib/Support/Signals.cpp:105:20
 #3 0x00007fb9113e37d0 SignalHandler(int) /home/reshabhsh/llvm-upstream/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x00007fb910d0e520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #5 0x00007fb910d629fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x00007fb910d629fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #7 0x00007fb910d629fc pthread_kill ./nptl/pthread_kill.c:89:10
 #8 0x00007fb910d0e476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #9 0x00007fb910cf47f3 abort ./stdlib/abort.c:81:7
#10 0x00007fb9112ab33e bindingsErrorHandler(void*, char const*, bool) /home/reshabhsh/llvm-upstream/llvm/lib/Support/ErrorHandling.cpp:221:55
#11 0x00007fb91233cd73 /home/reshabhsh/llvm-upstream/llvm/lib/IR/LegacyPassManager.cpp:1289:3
#12 0x00007fb91233bc43 llvm::PMDataManager::add(llvm::Pass*, bool) /home/reshabhsh/llvm-upstream/llvm/lib/IR/LegacyPassManager.cpp:1075:3
#13 0x00007fb91233eca3 llvm::FunctionPass::assignPassManager(llvm::PMStack&, llvm::PassManagerType) /home/reshabhsh/llvm-upstream/llvm/lib/IR/LegacyPassManager.cpp:1769:1
#14 0x00007fb912339fcd llvm::PMTopLevelManager::schedulePass(llvm::Pass*) /home/reshabhsh/llvm-upstream/llvm/lib/IR/LegacyPassManager.cpp:753:31
#15 0x00007fb912342fde llvm::legacy::PassManagerImpl::add(llvm::Pass*) /home/reshabhsh/llvm-upstream/llvm/lib/IR/LegacyPassManager.cpp:481:3
#16 0x00007fb91233e70f llvm::legacy::PassManager::add(llvm::Pass*) /home/reshabhsh/llvm-upstream/llvm/lib/IR/LegacyPassManager.cpp:1672:1
#17 0x00007fb918004c9e llvm::TargetPassConfig::addPass(llvm::Pass*) /home/reshabhsh/llvm-upstream/llvm/lib/CodeGen/TargetPassConfig.cpp:750:27
#18 0x00007fb91a9b6114 (anonymous namespace)::X86PassConfig::addInstSelector() /home/reshabhsh/llvm-upstream/llvm/lib/Target/X86/X86TargetMachine.cpp:476:7
#19 0x00007fb918005d5b llvm::TargetPassConfig::addCoreISelPasses() /home/reshabhsh/llvm-upstream/llvm/lib/CodeGen/TargetPassConfig.cpp:1075:10
#20 0x00007fb918005f4e llvm::TargetPassConfig::addISelPasses() /home/reshabhsh/llvm-upstream/llvm/lib/CodeGen/TargetPassConfig.cpp:1102:1
#21 0x00007fb917a3cd65 addPassesToGenerateCode(llvm::LLVMTargetMachine&, llvm::legacy::PassManagerBase&, bool, llvm::MachineModuleInfoWrapperPass&) /home/reshabhsh/llvm-upstream/llvm/lib/CodeGen/LLVMTargetMachine.cpp:125:3
#22 0x00007fb917a3d674 llvm::LLVMTargetMachine::addPassesToEmitFile(llvm::legacy::PassManagerBase&, llvm::raw_pwrite_stream&, llvm::raw_pwrite_stream*, llvm::CodeGenFileType, bool, llvm::MachineModuleInfoWrapperPass*) /home/reshabhsh/llvm-upstream/llvm/lib/CodeGen/LLVMTargetMachine.cpp:239:30
#23 0x00007fb918b7ce35 (anonymous namespace)::EmitAssemblyHelper::AddEmitPasses(llvm::legacy::PassManager&, clang::BackendAction, llvm::raw_pwrite_stream&, llvm::raw_pwrite_stream*) /home/reshabhsh/llvm-upstream/clang/lib/CodeGen/BackendUtil.cpp:598:30
#24 0x00007fb918b81051 (anonymous namespace)::EmitAssemblyHelper::RunCodegenPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&) /home/reshabhsh/llvm-upstream/clang/lib/CodeGen/BackendUtil.cpp:1144:9
#25 0x00007fb918b812f4 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) /home/reshabhsh/llvm-upstream/clang/lib/CodeGen/BackendUtil.cpp:1187:17
#26 0x00007fb918b8242b clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) /home/reshabhsh/llvm-upstream/clang/lib/CodeGen/BackendUtil.cpp:1347:25
#27 0x00007fb9193e2e8e clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /home/reshabhsh/llvm-upstream/clang/lib/CodeGen/CodeGenAction.cpp:386:24
#28 0x00007fb90b2c617b clang::ParseAST(clang::Sema&, bool, bool) /home/reshabhsh/llvm-upstream/clang/lib/Parse/ParseAST.cpp:183:14
#29 0x00007fb91610755a clang::ASTFrontendAction::ExecuteAction() /home/reshabhsh/llvm-upstream/clang/lib/Frontend/FrontendAction.cpp:1184:11
#30 0x00007fb9193dd738 clang::CodeGenAction::ExecuteAction() /home/reshabhsh/llvm-upstream/clang/lib/CodeGen/CodeGenAction.cpp:1208:5
#31 0x00007fb916106e04 clang::FrontendAction::Execute() /home/reshabhsh/llvm-upstream/clang/lib/Frontend/FrontendAction.cpp:1074:38
#32 0x00007fb915ffafaf clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/reshabhsh/llvm-upstream/clang/lib/Frontend/CompilerInstance.cpp:1045:42
#33 0x00007fb919ed9c15 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/reshabhsh/llvm-upstream/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:272:38
#34 0x000055ce525ee5e2 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/reshabhsh/llvm-upstream/clang/tools/driver/cc1_main.cpp:294:40
#35 0x000055ce525ddc8e ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /home/reshabhsh/llvm-upstream/clang/tools/driver/driver.cpp:366:20
#36 0x000055ce525de201 clang_main(int, char**, llvm::ToolContext const&) /home/reshabhsh/llvm-upstream/clang/tools/driver/driver.cpp:407:26
#37 0x000055ce526193a3 main /home/reshabhsh/llvm-upstream/build/tools/clang/tools/driver/clang-driver.cpp:15:58
#38 0x00007fb910cf5d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#39 0x00007fb910cf5e40 call_init ./csu/../csu/libc-start.c:128:20
#40 0x00007fb910cf5e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#41 0x000055ce525dc0c5 _start (/home/reshabhsh/llvm-upstream/build/bin/clang-18+0xe0c5)
clang: error: unable to execute command: Aborted (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 18.0.0 (https://github.com/llvm/llvm-project.git af253043190668f8b2030c168ed25903eee531f7)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/reshabhsh/llvm-upstream/build/bin
clang: note: diagnostic msg: 

Preprocessed source:

# 1 "<built-in>"
# 1 "test.c"
int main () {
    return 0;
}

Run script

# Crash reproducer for clang version 18.0.0 (https://github.com/llvm/llvm-project.git af253043190668f8b2030c168ed25903eee531f7)
# Driver args: "-O2" "test.c"
# Original command:  "/home/reshabhsh/llvm-upstream/build/bin/clang-18" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-dumpdir" "a-" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "test.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=none" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/home/reshabhsh/SLVA/test-suite" "-fcoverage-compilation-dir=/home/reshabhsh/SLVA/test-suite" "-resource-dir" "/home/reshabhsh/llvm-upstream/build/lib/clang/18" "-internal-isystem" "/home/reshabhsh/llvm-upstream/build/lib/clang/18/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-O2" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-vectorize-loops" "-vectorize-slp" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "/tmp/test-ffe224.o" "-x" "c" "test.c"
 "/home/reshabhsh/llvm-upstream/build/bin/clang-18" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-dumpdir" "a-" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "test.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=none" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/home/reshabhsh/SLVA/test-suite" "-fcoverage-compilation-dir=/home/reshabhsh/SLVA/test-suite" "-O2" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-vectorize-loops" "-vectorize-slp" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c" "test-dfb0bc.c"

It also crashes when I try to change the position of StackProtectorPass in the pipeline.

reSHARMA commented 10 months ago

I've also reproduced the same with previous llvm versions

llvmbot commented 10 months ago

@llvm/issue-subscribers-backend-x86

Author: Reshabh Sharma (reSHARMA)

Clang crashes on any valid c code when StackProtectorPass is removed from the pass pipeline by commenting [addPass(createStackProtectorPass());](https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/TargetPassConfig.cpp#L989) in [TargetPassConfig::addISelPrepare](https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/TargetPassConfig.cpp#L989) Crash dump: ``` Unable to schedule 'Function Alias Analysis Results' required by 'X86 DAG->DAG Instruction Selection' Unable to schedule pass UNREACHABLE executed at /home/reshabhsh/llvm-upstream/llvm/lib/IR/LegacyPassManager.cpp:1289! PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script. Stack dump: 0. Program arguments: /home/reshabhsh/llvm-upstream/build/bin/clang-18 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name test.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/reshabhsh/SLVA/test-suite -fcoverage-compilation-dir=/home/reshabhsh/SLVA/test-suite -resource-dir /home/reshabhsh/llvm-upstream/build/lib/clang/18 -internal-isystem /home/reshabhsh/llvm-upstream/build/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -ferror-limit 19 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/test-ffe224.o -x c test.c 1. <eof> parser at end of file #0 0x00007fb9113e3f38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/reshabhsh/llvm-upstream/llvm/lib/Support/Unix/Signals.inc:723:22 #1 0x00007fb9113e4354 PrintStackTraceSignalHandler(void*) /home/reshabhsh/llvm-upstream/llvm/lib/Support/Unix/Signals.inc:798:1 #2 0x00007fb9113e17a1 llvm::sys::RunSignalHandlers() /home/reshabhsh/llvm-upstream/llvm/lib/Support/Signals.cpp:105:20 #3 0x00007fb9113e37d0 SignalHandler(int) /home/reshabhsh/llvm-upstream/llvm/lib/Support/Unix/Signals.inc:413:1 #4 0x00007fb910d0e520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #5 0x00007fb910d629fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76 #6 0x00007fb910d629fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10 #7 0x00007fb910d629fc pthread_kill ./nptl/pthread_kill.c:89:10 #8 0x00007fb910d0e476 gsignal ./signal/../sysdeps/posix/raise.c:27:6 #9 0x00007fb910cf47f3 abort ./stdlib/abort.c:81:7 #10 0x00007fb9112ab33e bindingsErrorHandler(void*, char const*, bool) /home/reshabhsh/llvm-upstream/llvm/lib/Support/ErrorHandling.cpp:221:55 #11 0x00007fb91233cd73 /home/reshabhsh/llvm-upstream/llvm/lib/IR/LegacyPassManager.cpp:1289:3 #12 0x00007fb91233bc43 llvm::PMDataManager::add(llvm::Pass*, bool) /home/reshabhsh/llvm-upstream/llvm/lib/IR/LegacyPassManager.cpp:1075:3 #13 0x00007fb91233eca3 llvm::FunctionPass::assignPassManager(llvm::PMStack&, llvm::PassManagerType) /home/reshabhsh/llvm-upstream/llvm/lib/IR/LegacyPassManager.cpp:1769:1 #14 0x00007fb912339fcd llvm::PMTopLevelManager::schedulePass(llvm::Pass*) /home/reshabhsh/llvm-upstream/llvm/lib/IR/LegacyPassManager.cpp:753:31 #15 0x00007fb912342fde llvm::legacy::PassManagerImpl::add(llvm::Pass*) /home/reshabhsh/llvm-upstream/llvm/lib/IR/LegacyPassManager.cpp:481:3 #16 0x00007fb91233e70f llvm::legacy::PassManager::add(llvm::Pass*) /home/reshabhsh/llvm-upstream/llvm/lib/IR/LegacyPassManager.cpp:1672:1 #17 0x00007fb918004c9e llvm::TargetPassConfig::addPass(llvm::Pass*) /home/reshabhsh/llvm-upstream/llvm/lib/CodeGen/TargetPassConfig.cpp:750:27 #18 0x00007fb91a9b6114 (anonymous namespace)::X86PassConfig::addInstSelector() /home/reshabhsh/llvm-upstream/llvm/lib/Target/X86/X86TargetMachine.cpp:476:7 #19 0x00007fb918005d5b llvm::TargetPassConfig::addCoreISelPasses() /home/reshabhsh/llvm-upstream/llvm/lib/CodeGen/TargetPassConfig.cpp:1075:10 #20 0x00007fb918005f4e llvm::TargetPassConfig::addISelPasses() /home/reshabhsh/llvm-upstream/llvm/lib/CodeGen/TargetPassConfig.cpp:1102:1 #21 0x00007fb917a3cd65 addPassesToGenerateCode(llvm::LLVMTargetMachine&, llvm::legacy::PassManagerBase&, bool, llvm::MachineModuleInfoWrapperPass&) /home/reshabhsh/llvm-upstream/llvm/lib/CodeGen/LLVMTargetMachine.cpp:125:3 #22 0x00007fb917a3d674 llvm::LLVMTargetMachine::addPassesToEmitFile(llvm::legacy::PassManagerBase&, llvm::raw_pwrite_stream&, llvm::raw_pwrite_stream*, llvm::CodeGenFileType, bool, llvm::MachineModuleInfoWrapperPass*) /home/reshabhsh/llvm-upstream/llvm/lib/CodeGen/LLVMTargetMachine.cpp:239:30 #23 0x00007fb918b7ce35 (anonymous namespace)::EmitAssemblyHelper::AddEmitPasses(llvm::legacy::PassManager&, clang::BackendAction, llvm::raw_pwrite_stream&, llvm::raw_pwrite_stream*) /home/reshabhsh/llvm-upstream/clang/lib/CodeGen/BackendUtil.cpp:598:30 #24 0x00007fb918b81051 (anonymous namespace)::EmitAssemblyHelper::RunCodegenPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&) /home/reshabhsh/llvm-upstream/clang/lib/CodeGen/BackendUtil.cpp:1144:9 #25 0x00007fb918b812f4 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) /home/reshabhsh/llvm-upstream/clang/lib/CodeGen/BackendUtil.cpp:1187:17 #26 0x00007fb918b8242b clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) /home/reshabhsh/llvm-upstream/clang/lib/CodeGen/BackendUtil.cpp:1347:25 #27 0x00007fb9193e2e8e clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /home/reshabhsh/llvm-upstream/clang/lib/CodeGen/CodeGenAction.cpp:386:24 #28 0x00007fb90b2c617b clang::ParseAST(clang::Sema&, bool, bool) /home/reshabhsh/llvm-upstream/clang/lib/Parse/ParseAST.cpp:183:14 #29 0x00007fb91610755a clang::ASTFrontendAction::ExecuteAction() /home/reshabhsh/llvm-upstream/clang/lib/Frontend/FrontendAction.cpp:1184:11 #30 0x00007fb9193dd738 clang::CodeGenAction::ExecuteAction() /home/reshabhsh/llvm-upstream/clang/lib/CodeGen/CodeGenAction.cpp:1208:5 #31 0x00007fb916106e04 clang::FrontendAction::Execute() /home/reshabhsh/llvm-upstream/clang/lib/Frontend/FrontendAction.cpp:1074:38 #32 0x00007fb915ffafaf clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/reshabhsh/llvm-upstream/clang/lib/Frontend/CompilerInstance.cpp:1045:42 #33 0x00007fb919ed9c15 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/reshabhsh/llvm-upstream/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:272:38 #34 0x000055ce525ee5e2 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/reshabhsh/llvm-upstream/clang/tools/driver/cc1_main.cpp:294:40 #35 0x000055ce525ddc8e ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /home/reshabhsh/llvm-upstream/clang/tools/driver/driver.cpp:366:20 #36 0x000055ce525de201 clang_main(int, char**, llvm::ToolContext const&) /home/reshabhsh/llvm-upstream/clang/tools/driver/driver.cpp:407:26 #37 0x000055ce526193a3 main /home/reshabhsh/llvm-upstream/build/tools/clang/tools/driver/clang-driver.cpp:15:58 #38 0x00007fb910cf5d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16 #39 0x00007fb910cf5e40 call_init ./csu/../csu/libc-start.c:128:20 #40 0x00007fb910cf5e40 __libc_start_main ./csu/../csu/libc-start.c:379:5 #41 0x000055ce525dc0c5 _start (/home/reshabhsh/llvm-upstream/build/bin/clang-18+0xe0c5) clang: error: unable to execute command: Aborted (core dumped) clang: error: clang frontend command failed due to signal (use -v to see invocation) clang version 18.0.0 (https://github.com/llvm/llvm-project.git af253043190668f8b2030c168ed25903eee531f7) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /home/reshabhsh/llvm-upstream/build/bin clang: note: diagnostic msg: ``` Preprocessed source: ```c # 1 "<built-in>" # 1 "test.c" int main () { return 0; } ``` Run script ``` # Crash reproducer for clang version 18.0.0 (https://github.com/llvm/llvm-project.git af253043190668f8b2030c168ed25903eee531f7) # Driver args: "-O2" "test.c" # Original command: "/home/reshabhsh/llvm-upstream/build/bin/clang-18" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-dumpdir" "a-" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "test.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=none" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/home/reshabhsh/SLVA/test-suite" "-fcoverage-compilation-dir=/home/reshabhsh/SLVA/test-suite" "-resource-dir" "/home/reshabhsh/llvm-upstream/build/lib/clang/18" "-internal-isystem" "/home/reshabhsh/llvm-upstream/build/lib/clang/18/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-O2" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-vectorize-loops" "-vectorize-slp" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "/tmp/test-ffe224.o" "-x" "c" "test.c" "/home/reshabhsh/llvm-upstream/build/bin/clang-18" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-dumpdir" "a-" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "test.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=none" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/home/reshabhsh/SLVA/test-suite" "-fcoverage-compilation-dir=/home/reshabhsh/SLVA/test-suite" "-O2" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-vectorize-loops" "-vectorize-slp" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c" "test-dfb0bc.c" ``` It also crashes when I try to change the position of StackProtectorPass in the pipeline.
reSHARMA commented 10 months ago

@dtcxzyw I was also able to reproduce this on aarch64

LizzyHP commented 1 month ago

I've encountered the same issue on Arm. It seems related to the order of adding AAResultsWrapperPass and StackProtector in SelectionDAGISel::getAnalysisUsage(). Specifically, after the StackProtector pass is the ARMDAGToDAGISel pass, which inherits from SelectionDAGISel. In SelectionDAGISel::getAnalysisUsage(), it requires AAResultsWrapperPass and StackProtector.

void SelectionDAGISel::getAnalysisUsage(AnalysisUsage &AU) const {
  if (OptLevel != CodeGenOptLevel::None)
      AU.addRequired<AAResultsWrapperPass>();
  AU.addRequired<GCModuleInfo>();
  AU.addRequired<StackProtector>();
  AU.addPreserved<GCModuleInfo>();
  AU.addRequired<TargetLibraryInfoWrapperPass>();
  AU.addRequired<TargetTransformInfoWrapperPass>();
  AU.addRequired<AssumptionCacheTracker>();
  if (UseMBPI && OptLevel != CodeGenOptLevel::None)
      AU.addRequired<BranchProbabilityInfoWrapperPass>();
  AU.addRequired<ProfileSummaryInfoWrapperPass>();
  // AssignmentTrackingAnalysis only runs if assignment tracking is enabled for
  // the module.
  AU.addRequired<AssignmentTrackingAnalysis>();
  AU.addPreserved<AssignmentTrackingAnalysis>();
  if (OptLevel != CodeGenOptLevel::None)
      LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AU);
  MachineFunctionPass::getAnalysisUsage(AU);
}

Debugging under normal conditions shows that when scheduling ARMDAGToDAGISel, the pass manager finds the AAResultsWrapperPass is not preserved, so it schedules it again. And the StackProtector pass doesn't get rescheduled because it has already been executed and preserved. If addPass(createStackProtectorPass()) is commented in TargetPassConfig::addISelPasses(), the pass manager will then schedule the StackProtector pass. However, the StackProtector pass will remove the preservation of AAResultsWrapperPass, causing ARMDAGToDAGISel to fail the requirement check for AAResultsWrapperPass later and resulting in an "Unable to schedule pass" error. Adjusting the order of AAResultsWrapperPass and StackProtector in SelectionDAGISel::getAnalysisUsage() can resolve this issue.

void SelectionDAGISel::getAnalysisUsage(AnalysisUsage &AU) const {
  AU.addRequired<GCModuleInfo>();
  AU.addRequired<StackProtector>();
  if (OptLevel != CodeGenOptLevel::None)
      AU.addRequired<AAResultsWrapperPass>();
  AU.addPreserved<GCModuleInfo>();
  AU.addRequired<TargetLibraryInfoWrapperPass>();
  AU.addRequired<TargetTransformInfoWrapperPass>();
  AU.addRequired<AssumptionCacheTracker>();
  if (UseMBPI && OptLevel != CodeGenOptLevel::None)
      AU.addRequired<BranchProbabilityInfoWrapperPass>();
  AU.addRequired<ProfileSummaryInfoWrapperPass>();
  // AssignmentTrackingAnalysis only runs if assignment tracking is enabled for
  // the module.
  AU.addRequired<AssignmentTrackingAnalysis>();
  AU.addPreserved<AssignmentTrackingAnalysis>();
  if (OptLevel != CodeGenOptLevel::None)
      LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AU);
  MachineFunctionPass::getAnalysisUsage(AU);
}

However, I still don't understand the Legacy Pass Manager's mechanism. For instance, if I add a Module pass after addPass(createStackProtectorPass()), and its getAnalysisUsage() has setPreservesAll(), it also causes an "Unable to schedule pass" error. Does this mean that the Module pass automatically removes the previously preserved passes?