Skip to content

After 7740565f56ce, "Assertion failed: (isa<Function>(Callee) || isa<GlobalAlias>(Callee)), function analyzeAllUses" with -asan-use-stack-safety #87923

@DimitryAndric

Description

@DimitryAndric

Commit 7740565 enabled StackSafetyAnalysis (-asan-use-stack-safety=1) by default. Afterwards, clang crashes with ASan enabled on https://github.com/freebsd/freebsd-src/blob/main/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c :

Assertion failed: (isa<Function>(Callee) || isa<GlobalAlias>(Callee)), function analyzeAllUses, file /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/lib/Analysis/StackSafetyAnalysis.cpp, line 514.
PLEASE submit a bug report to https://bugs.freebsd.org/submit/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: clang -cc1 -triple x86_64-unknown-freebsd15.0 -emit-obj -disable-free -clear-ast-before-backend -main-file-name dtrace.c -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -ffp-contract=on -fno-rounding-math -mconstructor-aliases -ffreestanding -mcmodel=kernel -target-cpu x86-64 -target-feature -mmx -target-feature -sse -target-feature -aes -target-feature -avx -disable-red-zone -no-implicit-float -tune-cpu generic -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=gdb -fdebug-compilation-dir=/home/dim/obj/home/dim/src/freebsd/src/amd64.amd64/sys/GENERIC-KASAN/modules/home/dim/src/freebsd/src/sys/modules/dtrace/dtrace -fdebug-prefix-map=./machine=/home/dim/src/freebsd/src/sys/amd64/include -fdebug-prefix-map=./x86=/home/dim/src/freebsd/src/sys/x86/include -fdebug-prefix-map=./i386=/home/dim/src/freebsd/src/sys/i386/include -fcoverage-compilation-dir=/home/dim/obj/home/dim/src/freebsd/src/amd64.amd64/sys/GENERIC-KASAN/modules/home/dim/src/freebsd/src/sys/modules/dtrace/dtrace -nostdsysteminc -nobuiltininc -sys-header-deps -D _SYS_VMEM_H_ -D __KERNEL__ -D SMP -D DIS_MEM -D _KERNEL -D KLD_MODULE -D KLD_TIED -D HAVE_KERNEL_OPTION_HEADERS -D SAN_NEEDS_INTERCEPTORS -D SAN_INTERCEPTOR_PREFIX=kasan -D __printf__=__freebsd_kprintf__ -O2 -Werror -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wcast-qual -Wundef -Wno-pointer-sign -Wmissing-include-dirs -Wno-unknown-pragmas -Wswitch -Wno-error=tautological-compare -Wno-error=empty-body -Wno-error=parentheses-equality -Wno-error=unused-function -Wno-error=pointer-sign -Wno-error=shift-negative-value -Wno-address-of-packed-member -Wno-format-zero-length -Wno-parentheses -Wno-cast-qual -Wno-unused -std=gnu99 -ferror-limit 19 -fsanitize=kernel-address -fsanitize-recover=kernel-address -fno-sanitize-memory-param-retval -fno-sanitize-address-use-odr-indicator -fwrapv -stack-protector 1 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -mllvm -asan-stack=true -mllvm -asan-instrument-dynamic-allocas=true -mllvm -asan-globals=true -mllvm -asan-use-after-scope=true -mllvm -asan-instrumentation-with-call-threshold=0 -mllvm -asan-instrument-byval=false -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -x c dtrace-5c7112.c
1.      <eof> parser at end of file
2.      Optimizer
 #0 0x0000000005ab54c1 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:13
 #1 0x0000000005ab34b5 llvm::sys::RunSignalHandlers() /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/lib/Support/Signals.cpp:106:18
 #2 0x0000000005ab5ac2 SignalHandler(int) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/lib/Support/Unix/Signals.inc:0:3
 #3 0x000000082b949570 handle_signal /share/dim/src/freebsd/llvm-18-update/lib/libthr/thread/thr_sig.c:0:3
 #4 0x000000082b948b2b thr_sighandler /share/dim/src/freebsd/llvm-18-update/lib/libthr/thread/thr_sig.c:244:1
 #5 0x00000008282642d3 ([vdso]+0x2d3)
 #6 0x000000082e43819a thr_kill /usr/obj/share/dim/src/freebsd/llvm-18-update/amd64.amd64/lib/libsys/thr_kill.S:4:0
 #7 0x000000082eb4bf54 _raise /share/dim/src/freebsd/llvm-18-update/lib/libc/gen/raise.c:0:10
 #8 0x000000082ebff509 abort /share/dim/src/freebsd/llvm-18-update/lib/libc/stdlib/abort.c:67:17
 #9 0x000000082eb2f8d1 (/lib/libc.so.7+0x9c8d1)
#10 0x0000000005029acc (anonymous namespace)::StackSafetyLocalAnalysis::analyzeAllUses(llvm::Value*, (anonymous namespace)::UseInfo<llvm::GlobalValue>&, llvm::StackLifetime const&) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/lib/Analysis/StackSafetyAnalysis.cpp:0:9
#11 0x000000000502406f (anonymous namespace)::StackSafetyLocalAnalysis::run() /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/lib/Analysis/StackSafetyAnalysis.cpp:550:20
#12 0x000000000502406f llvm::StackSafetyInfo::getInfo() const /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/lib/Analysis/StackSafetyAnalysis.cpp:876:32
#13 0x0000000005024c98 llvm::StackSafetyGlobalInfo::getInfo() const /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/lib/Analysis/StackSafetyAnalysis.cpp:891:19
#14 0x000000000502782e std::__1::__tree<llvm::Instruction const*, std::__1::less<llvm::Instruction const*>, std::__1::allocator<llvm::Instruction const*>>::__root[abi:sn180100]() const /usr/obj/share/dim/src/freebsd/llvm-18-update/amd64.amd64/tmp/usr/include/c++/v1/__tree:972:54
#15 0x000000000502782e std::__1::__tree_const_iterator<llvm::Instruction const*, std::__1::__tree_node<llvm::Instruction const*, void*>*, long> std::__1::__tree<llvm::Instruction const*, std::__1::less<llvm::Instruction const*>, std::__1::allocator<llvm::Instruction const*>>::find<llvm::Instruction const*>(llvm::Instruction const* const&) const /usr/obj/share/dim/src/freebsd/llvm-18-update/amd64.amd64/tmp/usr/include/c++/v1/__tree:2098:43
#16 0x000000000502782e std::__1::set<llvm::Instruction const*, std::__1::less<llvm::Instruction const*>, std::__1::allocator<llvm::Instruction const*>>::find[abi:sn180100](llvm::Instruction const* const&) const /usr/obj/share/dim/src/freebsd/llvm-18-update/amd64.amd64/tmp/usr/include/c++/v1/set:826:89
#17 0x000000000502782e llvm::StackSafetyGlobalInfo::stackAccessIsSafe(llvm::Instruction const&) const /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/lib/Analysis/StackSafetyAnalysis.cpp:983:30
#18 0x0000000006e4274d (anonymous namespace)::AddressSanitizer::ignoreAccess(llvm::Instruction*, llvm::Value*) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:1317:57
#19 0x0000000006e36970 (anonymous namespace)::AddressSanitizer::getInterestingMemoryOperands(llvm::Instruction*, llvm::SmallVectorImpl<llvm::InterestingMemoryOperand>&) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:1331:9
#20 0x0000000006e36970 (anonymous namespace)::AddressSanitizer::instrumentFunction(llvm::Function&, llvm::TargetLibraryInfo const*) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:2905:7
#21 0x0000000006e33dae llvm::DenseMap<llvm::AllocaInst const*, bool, llvm::DenseMapInfo<llvm::AllocaInst const*, void>, llvm::detail::DenseMapPair<llvm::AllocaInst const*, bool>>::~DenseMap() /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/include/llvm/ADT/DenseMap.h:782:23
#22 0x0000000006e33dae (anonymous namespace)::AddressSanitizer::~AddressSanitizer() /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:647:8
#23 0x0000000006e33dae llvm::AddressSanitizerPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:1191:3
#24 0x000000000315f522 llvm::detail::PassModel<llvm::Module, llvm::AddressSanitizerPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:89:5
#25 0x00000000056cdea1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/include/llvm/IR/PassManager.h:547:10
#26 0x0000000003155d2b llvm::SmallPtrSetImplBase::isSmall() const /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:195:33
#27 0x0000000003155d2b llvm::SmallPtrSetImplBase::~SmallPtrSetImplBase() /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:83:10
#28 0x0000000003155d2b llvm::PreservedAnalyses::~PreservedAnalyses() /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/include/llvm/IR/PassManager.h:172:7
#29 0x0000000003155d2b (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream>>&, std::__1::unique_ptr<llvm::ToolOutputFile, std::__1::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1101:5
#30 0x000000000314e8a8 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:0:3
#31 0x000000000314e8a8 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::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1328:13
#32 0x0000000003163ff4 std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream>>::reset[abi:sn180100](llvm::raw_pwrite_stream*) /usr/obj/share/dim/src/freebsd/llvm-18-update/amd64.amd64/tmp/usr/include/c++/v1/__memory/unique_ptr.h:263:29
#33 0x0000000003163ff4 std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream>>::~unique_ptr[abi:sn180100]() /usr/obj/share/dim/src/freebsd/llvm-18-update/amd64.amd64/tmp/usr/include/c++/v1/__memory/unique_ptr.h:236:71
#34 0x0000000003163ff4 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:379:3
#35 0x0000000003af9d06 std::__1::vector<std::__1::unique_ptr<clang::TemplateInstantiationCallback, std::__1::default_delete<clang::TemplateInstantiationCallback>>, std::__1::allocator<std::__1::unique_ptr<clang::TemplateInstantiationCallback, std::__1::default_delete<clang::TemplateInstantiationCallback>>>>::begin[abi:sn180100]() /usr/obj/share/dim/src/freebsd/llvm-18-update/amd64.amd64/tmp/usr/include/c++/v1/vector:1369:28
#36 0x0000000003af9d06 void clang::finalize<std::__1::vector<std::__1::unique_ptr<clang::TemplateInstantiationCallback, std::__1::default_delete<clang::TemplateInstantiationCallback>>, std::__1::allocator<std::__1::unique_ptr<clang::TemplateInstantiationCallback, std::__1::default_delete<clang::TemplateInstantiationCallback>>>>>(std::__1::vector<std::__1::unique_ptr<clang::TemplateInstantiationCallback, std::__1::default_delete<clang::TemplateInstantiationCallback>>, std::__1::allocator<std::__1::unique_ptr<clang::TemplateInstantiationCallback, std::__1::default_delete<clang::TemplateInstantiationCallback>>>>&, clang::Sema const&) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/clang/include/clang/Sema/TemplateInstCallback.h:54:16
#37 0x0000000003af9d06 clang::ParseAST(clang::Sema&, bool, bool) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/clang/lib/Parse/ParseAST.cpp:183:3
#38 0x000000000342c6ff clang::FrontendAction::Execute() /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1073:10
#39 0x000000000335cd0d llvm::Error::getPtr() const /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/include/llvm/Support/Error.h:276:42
#40 0x000000000335cd0d llvm::Error::operator bool() /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/llvm/include/llvm/Support/Error.h:239:16
#41 0x000000000335cd0d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1057:23
#42 0x00000000034f769c clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:272:25
#43 0x00000000027390a1 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/clang/tools/driver/cc1_main.cpp:294:15
#44 0x000000000274842b ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/clang/tools/driver/driver.cpp:365:12
#45 0x0000000002747517 clang_main(int, char**, llvm::ToolContext const&) /share/dim/src/freebsd/llvm-18-update/contrib/llvm-project/clang/tools/driver/driver.cpp:405:12
#46 0x0000000002744c2d main /share/dim/src/freebsd/llvm-18-update/usr.bin/clang/clang/clang-driver.cpp:17:10
#47 0x000000082eb20e2a __libc_start1 /share/dim/src/freebsd/llvm-18-update/lib/libc/csu/libc_start1.c:157:2
Abort trap

Minimized test case:

// clang -cc1 -triple x86_64-- -S -O2 -fsanitize=address dtrace-min.c
long cpu_core_0_1;
long dtrace_fuword64_nocheck(void *)
    __attribute__((ifunc("dtrace_fuword64_nocheck"
                         "_resolver")));
void dtrace_fuword64(void *uaddr) {
  cpu_core_0_1 = dtrace_fuword64_nocheck(uaddr);
}
long *dtrace_fuword64_nocheck_resolver() { return 0; }

Metadata

Metadata

Assignees

Labels

llvm:analysisIncludes value tracking, cost tables and constant folding

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions