LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 50838 - error in backend: Misaligned constant address: 0x00000007 has alignment 1, but the memory access requires 4
Summary: error in backend: Misaligned constant address: 0x00000007 has alignment 1, bu...
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Backend: Hexagon (show other bugs)
Version: trunk
Hardware: PC Linux
: P enhancement
Assignee: Krzysztof Parzyszek
URL: https://github.com/ClangBuiltLinux/li...
Keywords:
Depends on:
Blocks: 4068
  Show dependency tree
 
Reported: 2021-06-23 20:51 PDT by Nathan Chancellor
Modified: 2021-07-06 13:23 PDT (History)
8 users (show)

See Also:
Fixed By Commit(s):


Attachments
lockdep IR (1.20 KB, text/plain)
2021-06-23 21:08 PDT, Brian Cain
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Chancellor 2021-06-23 20:51:54 PDT
When building an ARCH=hexagon allmodconfig Linux kernel, Arnd reported a crash in kernel/locking/lockdep.c:

$ make -skj"$(nproc)" ARCH=hexagon CROSS_COMPILE=hexagon-linux- LLVM=1 LLVM_IAS=1 O=build/hexagon distclean allmodconfig kernel/locking/lockdep.o
...
fatal error: error in backend: Misaligned constant address: 0x00000007 has alignment 1, but the memory access requires 4
...

Running cvise on the file spits out:

$ cat lockdep.i
struct list_head {
  struct list_head *next, *prev
};
struct lock_list {
  struct list_head entry;
  int class
} check_prevs_add() {
  struct lock_list *target_entry1 = find_exclusive_match(target_entry1->class);
}

$ clang -O2 --target=hexagon-linux -ftrivial-auto-var-init=pattern -c -o /dev/null lockdep.i
lockdep.i:2:32: warning: expected ';' at end of declaration list
  struct list_head *next, *prev
                               ^
                               ;
lockdep.i:6:12: warning: expected ';' at end of declaration list
  int class
           ^
           ;
lockdep.i:8:37: warning: implicit declaration of function 'find_exclusive_match' is invalid in C99 [-Wimplicit-function-declaration]
  struct lock_list *target_entry1 = find_exclusive_match(target_entry1->class);
                                    ^
lockdep.i:8:21: warning: incompatible integer to pointer conversion initializing 'struct lock_list *' with an expression of type 'int' [-Wint-conversion]
  struct lock_list *target_entry1 = find_exclusive_match(target_entry1->class);
                    ^               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lockdep.i:9:1: warning: non-void function does not return a value [-Wreturn-type]
}
^
fatal error: error in backend: Misaligned constant address: 0x00000007 has alignment 1, but the memory access requires 4
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: clang -O2 --target=hexagon-linux -ftrivial-auto-var-init=pattern -c -o /dev/null lockdep.i
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module 'lockdep.i'.
4.	Running pass 'Hexagon DAG->DAG Pattern Instruction Selection' on function '@check_prevs_add'
 #0 0x0000000003008f93 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x3008f93)
 #1 0x0000000003006dde llvm::sys::RunSignalHandlers() (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x3006dde)
 #2 0x0000000002f90633 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) CrashRecoveryContext.cpp:0:0
 #3 0x0000000002f905af llvm::CrashRecoveryContext::HandleExit(int) (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x2f905af)
 #4 0x0000000003003307 llvm::sys::Process::Exit(int, bool) (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x3003307)
 #5 0x0000000001b18b60 llvm::DenseMapBase<llvm::DenseMap<llvm::AliasSetTracker::ASTCallbackVH, llvm::AliasSet::PointerRec*, llvm::AliasSetTracker::ASTCallbackVHDenseMapInfo, llvm::detail::DenseMapPair<llvm::AliasSetTracker::ASTCallbackVH, llvm::AliasSet::PointerRec*> >, llvm::AliasSetTracker::ASTCallbackVH, llvm::AliasSet::PointerRec*, llvm::AliasSetTracker::ASTCallbackVHDenseMapInfo, llvm::detail::DenseMapPair<llvm::AliasSetTracker::ASTCallbackVH, llvm::AliasSet::PointerRec*> >::destroyAll() cc1_main.cpp:0:0
 #6 0x0000000002f94e82 llvm::report_fatal_error(llvm::Twine const&, bool) (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x2f94e82)
 #7 0x0000000002f94f57 (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x2f94f57)
 #8 0x0000000001b54ef0 llvm::HexagonTargetLowering::validateConstPtrAlignment(llvm::SDValue, llvm::SDLoc const&, unsigned int) const HexagonISelLowering.cpp:0:0
 #9 0x0000000001b5b936 llvm::HexagonTargetLowering::LowerLoad(llvm::SDValue, llvm::SelectionDAG&) const HexagonISelLowering.cpp:0:0
#10 0x0000000001b5d408 llvm::HexagonTargetLowering::LowerOperation(llvm::SDValue, llvm::SelectionDAG&) const HexagonISelLowering.cpp:0:0
#11 0x0000000003d92198 (anonymous namespace)::SelectionDAGLegalize::LegalizeLoadOps(llvm::SDNode*) LegalizeDAG.cpp:0:0
#12 0x0000000003d7f9b6 (anonymous namespace)::SelectionDAGLegalize::LegalizeOp(llvm::SDNode*) LegalizeDAG.cpp:0:0
#13 0x0000000003d7e931 llvm::SelectionDAG::Legalize() (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x3d7e931)
#14 0x0000000003e3edab llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x3e3edab)
#15 0x0000000003e3cc1e llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x3e3cc1e)
#16 0x0000000003e394a1 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x3e394a1)
#17 0x0000000001c62ba4 llvm::HexagonDAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) HexagonISelDAGToDAG.cpp:0:0
#18 0x000000000236490d llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x236490d)
#19 0x00000000027eac58 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x27eac58)
#20 0x00000000027f3121 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x27f3121)
#21 0x00000000027eb751 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x27eb751)
#22 0x00000000036e27cf (anonymous namespace)::EmitAssemblyHelper::EmitAssemblyWithNewPassManager(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) BackendUtil.cpp:0:0
#23 0x00000000036dcf2c 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> >) (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x36dcf2c)
#24 0x0000000003a14f80 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) CodeGenAction.cpp:0:0
#25 0x0000000004130ca4 clang::ParseAST(clang::Sema&, bool, bool) (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x4130ca4)
#26 0x00000000039697e0 clang::FrontendAction::Execute() (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x39697e0)
#27 0x00000000038dcd6f clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x38dcd6f)
#28 0x0000000003a0f007 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x3a0f007)
#29 0x0000000001b18838 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x1b18838)
#30 0x0000000001b1638d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#31 0x000000000377fc72 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
#32 0x0000000002f90547 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x2f90547)
#33 0x000000000377f7d7 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x377f7d7)
#34 0x0000000003747868 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x3747868)
#35 0x0000000003747b37 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x3747b37)
#36 0x0000000003760201 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x3760201)
#37 0x0000000001b15c56 main (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x1b15c56)
#38 0x00007f28ea015b25 __libc_start_main (/usr/lib/libc.so.6+0x27b25)
#39 0x0000000001b12ffe _start (/home/nathan/cbl/github/tc-build/build/llvm/stage1/bin/clang-13+0x1b12ffe)
clang-13: error: clang frontend command failed with exit code 70 (use -v to see invocation)
ClangBuiltLinux clang version 13.0.0 (https://github.com/llvm/llvm-project e8c8ce0974edca7bc21ce53826ff7b2c0456d70a)
Target: hexagon-unknown-linux
Thread model: posix
InstalledDir: /home/nathan/cbl/github/tc-build/build/llvm/stage1/bin
clang-13: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.

$ clang -O2 --target=hexagon-linux -c -o /dev/null lockdep.i
lockdep.i:2:32: warning: expected ';' at end of declaration list
  struct list_head *next, *prev
                               ^
                               ;
lockdep.i:6:12: warning: expected ';' at end of declaration list
  int class
           ^
           ;
lockdep.i:8:37: warning: implicit declaration of function 'find_exclusive_match' is invalid in C99 [-Wimplicit-function-declaration]
  struct lock_list *target_entry1 = find_exclusive_match(target_entry1->class);
                                    ^
lockdep.i:8:21: warning: incompatible integer to pointer conversion initializing 'struct lock_list *' with an expression of type 'int' [-Wint-conversion]
  struct lock_list *target_entry1 = find_exclusive_match(target_entry1->class);
                    ^               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lockdep.i:9:1: warning: non-void function does not return a value [-Wreturn-type]
}
^
5 warnings generated.

I can reproduce this with current ToT (e8c8ce0974edca7bc21ce53826ff7b2c0456d70a).
Comment 1 Brian Cain 2021-06-23 21:08:29 PDT
Created attachment 24980 [details]
lockdep IR
Comment 2 Eli Friedman 2021-06-23 22:46:02 PDT
https://reviews.llvm.org/D50405 / https://reviews.llvm.org/D50524 for the initial implementation/discussion of this diagnostic.
Comment 3 Brian Cain 2021-06-24 06:18:36 PDT
Am I correct in assuming that the `-ftrivial-auto-var-init=pattern` is the critical factor here?  Is it initializing a pointer to an invalid/unaligned value that gets dereferenced without initialization in some paths? 

Does this feature invalidate the assumption that this issue is typically caused by invalid code?  Per the discussion, should the backend emit a trap in this case?
Comment 4 Nathan Chancellor 2021-06-24 10:14:43 PDT
(In reply to Brian Cain from comment #3)
> Am I correct in assuming that the `-ftrivial-auto-var-init=pattern` is the
> critical factor here?

Yes, that flag is critical for reproducing this.

> Is it initializing a pointer to an invalid/unaligned
> value that gets dereferenced without initialization in some paths? 

It is certainly possible. I guess that is the case in the example?

> Does this feature invalidate the assumption that this issue is typically
> caused by invalid code?  Per the discussion, should the backend emit a trap
> in this case?

I am not sure about this unfortunately.
Comment 5 Nick Desaulniers 2021-06-24 12:29:01 PDT
(In reply to Nathan Chancellor from comment #4)
> (In reply to Brian Cain from comment #3)
> > Am I correct in assuming that the `-ftrivial-auto-var-init=pattern` is the
> > critical factor here?
> 
> Yes, that flag is critical for reproducing this.

Does the kernel's LOCKDEP enable INIT_STACK_ALL_PATTERN?
Comment 6 Nick Desaulniers 2021-06-24 12:29:26 PDT
(In reply to Nick Desaulniers from comment #5)
> (In reply to Nathan Chancellor from comment #4)
> > (In reply to Brian Cain from comment #3)
> > > Am I correct in assuming that the `-ftrivial-auto-var-init=pattern` is the
> > > critical factor here?
> > 
> > Yes, that flag is critical for reproducing this.
> 
> Does the kernel's LOCKDEP enable INIT_STACK_ALL_PATTERN?

Ah, sorry, the LKML thread mentions allmodconfig.
Comment 7 Krzysztof Parzyszek 2021-06-24 17:49:36 PDT
Actually https://reviews.llvm.org/D50524 should fix this.

We can discuss whether we want a message to be printed or not.
Comment 8 Krzysztof Parzyszek 2021-07-06 13:23:54 PDT
Fixed in https://reviews.llvm.org/rG94e01d579c19.