Issue 244580
Summary [PCM] `buckets should be 4-byte aligned` assertion failure with PCM + ASAN for COFF
Labels clang
Assignees
Reporter Steelskin
    Disclaimer: All of the investigation and repro steps come from Claude Code. I wrote the issue manually based on Claude Code's investigation.

### Summary

#242384 highlighted a pre-existing issue with building an implicit module with `-gmodules` / `-fmodule-format=obj` and `-fsanitize=address` for a Windows (COFF) target. Since it landed, this results in an assertion failure indicating that buckets are not 4-byte aligned. This was found from testing the aarch64 Swift toolchain, for which the `Profiler/coverage_with_asan.swift` test started failing when that PR was cherry-picked into the Swift fork, but the issue exists for all 3 Windows architectures.

The issue existed prior to #242384, it could be reproduced by running the clang invocation below twice. It now reproduces on the first call to clang. Reverting #242384 makes the first invocation pass, but the second still asserts.

cc @jansvoboda11

### Repro steps

`m.h`:
```c++
int m(void);
```

`t.c`:
```c++
#include "m.h"
```

`module.modulemap`:
```c++
module M { header "m.h" }
```

Using a recent ToT clang built with assertions enabled:
```bash
 clang \
    --target=aarch64-unknown-windows-msvc \
 -fsanitize=address \
    -fmodules \
    -fimplicit-module-maps \
 -fmodules-cache-path=cache \
    -Xclang -fmodule-format=obj \
 -Xclang -fno-modules-global-index \
    -fsyntax-only \
 t.c
```

Result:
```
clang: [...]/llvm-project/llvm/include/llvm/Support/OnDiskHashTable.h:304: static std::pair<offset_type, offset_type> llvm::OnDiskChainedHashTable<clang::serialization::reader::HeaderFileInfoTrait>::readNumBucketsAndEntries(const unsigned char *&) [Info = clang::serialization::reader::HeaderFileInfoTrait]: Assertion `(reinterpret_cast<uintptr_t>(Buckets) & 0x3) == 0 && "buckets should be 4-byte aligned."' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0.      Program arguments: ./build/clang/bin/clang --target=aarch64-unknown-windows-msvc -fsanitize=address -fmodules -fimplicit-module-maps -fmodules-cache-path=cache -Xclang -fmodule-format=obj -Xclang -fno-modules-global-index -fsyntax-only t.c
1.      t.c:1:2: current parser token 'include'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  clang     0x000064951ad0572b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 43
1  clang 0x000064951ad02735 llvm::sys::RunSignalHandlers() + 293
2  clang 0x000064951ac64e88
3  libc.so.6 0x00007aea63645330
4  libc.so.6 0x00007aea6369ebec pthread_kill + 284
5  libc.so.6 0x00007aea6364527e gsignal + 30
6  libc.so.6 0x00007aea636288ff abort + 223
7  libc.so.6 0x00007aea6362881b
8  libc.so.6 0x00007aea6363b517
9  clang 0x000064951ba720f9
10 clang     0x000064951ba6ef52 clang::ASTReader::ReadASTBlock(clang::serialization::ModuleFile&, unsigned int) + 10770
11 clang     0x000064951ba7353f clang::ASTReader::ReadAST(clang::ModuleFileName, clang::serialization::ModuleKind, clang::SourceLocation, unsigned int, clang::serialization::ModuleFile**) + 863
12 clang 0x000064951b900c28
13 clang     0x000064951b8fbe4a
14 clang 0x000064951b8fa637 clang::CompilerInstance::findOrCompileModuleAndReadAST(llvm::StringRef, clang::SourceLocation, clang::SourceRange, bool) + 2951
15 clang 0x000064951b8fcfe9 clang::CompilerInstance::loadModule(clang::SourceLocation, llvm::ArrayRef<clang::IdentifierLoc>, clang::Module::NameVisibilityKind, bool) + 4121
16 clang     0x000064951fe8a44b clang::Preprocessor::HandleHeaderIncludeOrImport(clang::SourceLocation, clang::Token&, clang::Token&, clang::SourceLocation, clang::detail::SearchDirIteratorImpl<true>, clang::FileEntry const*) + 5547
17 clang     0x000064951fe830a7 clang::Preprocessor::HandleIncludeDirective(clang::SourceLocation, clang::Token&, clang::detail::SearchDirIteratorImpl<true>, clang::FileEntry const*) + 663
18 clang     0x000064951fe83b14 clang::Preprocessor::HandleDirective(clang::Token&) + 2340
19 clang 0x000064951fe47b40 clang::Lexer::LexTokenInternal(clang::Token&) + 4912
20 clang     0x000064951fe449bf clang::Lexer::Lex(clang::Token&) + 143
21 clang 0x000064951fec004d clang::Preprocessor::Lex(clang::Token&) + 45
22 clang 0x000064951e7396b1 clang::ParseAST(clang::Sema&, bool, bool) + 401
23 clang     0x000064951b97f836 clang::FrontendAction::Execute() + 38
24 clang 0x000064951b8f4037 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1399
25 clang     0x000064951ba41958 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 584
26 clang 0x00006495194c69f0 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 6736
27 clang     0x00006495194c2c71
28 clang     0x00006495194c4f73
29 clang     0x000064951b7325a9
30 clang     0x000064951ac64b96 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 150
31 clang     0x000064951b7319ba clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const + 266
32 clang     0x000064951b6f15b7 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const + 263
33 clang 0x000064951b6f1b33 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const + 771
34 clang     0x000064951b711948 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) + 328
35 clang     0x00006495194c2555 clang_main(int, char**, llvm::ToolContext const&) + 6453
36 clang     0x00006495194d1ad6 main + 102
37 libc.so.6 0x00007aea6362a1ca
38 libc.so.6 0x00007aea6362a28b __libc_start_main + 139
39 clang     0x00006495194c0825 _start + 37
```

`llvm-readobj` shows the issue:
```bash
llvm-readobj --sections cache/*/M-*.pcm | grep -A 4 'Name: clangast'
```

```
Name: clangast (63 6C 61 6E 67 61 73 74)
VirtualSize: 0x0
VirtualAddress: 0x0
RawDataSize: 0x6BE0
PointerToRawData: 0x22E
```

`PointerToRawData` is not 4-byte aligned.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to