Description
I was experimenting CXX Modules with Clang 19 on Ubuntu, and it suddently broke when I passed wrong parameters on -fmodule-file, but strangely this only occurred when -fstack-protector was enabled... I have no idea why.
This is the clang version:
$ clang++-19 --version
Ubuntu clang version 19.1.1 (1ubuntu1~24.04.2)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin
The files are:
// main.cc
import hello;
// import <string_view>;
import std;
int main() {
do_hello("world");
return 0;
}
// hello.cppm
export module hello;
import std;
export inline void do_hello(std::string_view const &name)
{
std::cout << "Hello " << name << "!\n";
}
First I compile both .pcm files:
clang++-19 -std=c++23 -stdlib=libc++ -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -Wunused-but-set-parameter -Wno-free-nonheap-object -fcolor-diagnostics -fno-omit-frame-pointer '-std=c++23' -fPIC -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile -o std.pcm /usr/lib/llvm-19/share/libc++/v1/std.cppm
clang++-19 -std=c++23 -stdlib=libc++ -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -Wunused-but-set-parameter -Wno-free-nonheap-object -fcolor-diagnostics -fno-omit-frame-pointer '-std=c++23' -fPIC -fmodule-file=std=std.pcm -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile -o hello.pcm hello.cppm std.pcm
The bug appears when I mistakenly pass 'std' twice:
clang++-19 -fstack-protector -fmodule-file=std=example/hello-world/std.pcm -fmodule-file=std=example/hello-world/hello.pcm -stdlib=libc++ -std=c++23 example/hello-world/main.cc -o main.pic.o
$ clang++-19 -fstack-protector -fmodule-file=std=example/hello-world/std.pcm -fmodule-file=std=example/hello-world/hello.pcm -stdlib=libc++ -std=c++23 example/hello-world/main.cc -o main.pic.o
example/hello-world/main.cc:2:8: fatal error: module 'hello' not found
2 | import hello;
| ~~~~~~~^~~~~
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: /usr/lib/llvm-19/bin/clang -cc1 -triple x86_64-pc-linux-gnu -emit-obj -dumpdir main.pic.o- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cc -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -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/imcoelho/git-reps/rules_cc_module -fcoverage-compilation-dir=/home/imcoelho/git-reps/rules_cc_module -resource-dir /usr/lib/llvm-19/lib/clang/19 -internal-isystem /usr/lib/llvm-19/bin/../include/c++/v1 -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/15/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++23 -fdeprecated-macro -ferror-limit 19 -stack-protector 1 -fgnuc-version=4.2.1 -fno-implicit-modules -fmodule-file=std=example/hello-world/std.pcm -fmodule-file=std=example/hello-world/hello.pcm -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/main-be446a.o -x c++ example/hello-world/main.cc
1. example/hello-world/main.cc:5:11: current parser token ';'
#0 0x000078607d8bd0af llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.1+0xebd0af)
#1 0x000078607d8badb9 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.1+0xebadb9)
#2 0x000078607d8bd800 (/usr/lib/llvm-19/bin/../lib/libLLVM.so.19.1+0xebd800)
#3 0x000078607c245330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x000078608711d3d1 clang::ASTReader::ReadASTBlock(clang::serialization::ModuleFile&, unsigned int) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2b1d3d1)
#5 0x0000786087124c75 clang::ASTReader::ReadAST(llvm::StringRef, clang::serialization::ModuleKind, clang::SourceLocation, unsigned int, clang::serialization::ModuleFile**) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2b24c75)
#6 0x00007860872f0029 clang::CompilerInstance::findOrCompileModuleAndReadAST(llvm::StringRef, clang::SourceLocation, clang::SourceLocation, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2cf0029)
#7 0x00007860872f1e94 clang::CompilerInstance::loadModule(clang::SourceLocation, llvm::ArrayRef<std::pair<clang::IdentifierInfo*, clang::SourceLocation>>, clang::Module::NameVisibilityKind, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2cf1e94)
#8 0x000078608610f1c1 clang::Sema::ActOnModuleImport(clang::SourceLocation, clang::SourceLocation, clang::SourceLocation, llvm::ArrayRef<std::pair<clang::IdentifierInfo*, clang::SourceLocation>>, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x1b0f1c1)
#9 0x00007860853200b9 clang::Parser::ParseModuleImport(clang::SourceLocation, clang::Sema::ModuleImportState&) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xd200b9)
#10 0x000078608531ece7 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xd1ece7)
#11 0x000078608524b44e clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0xc4b44e)
#12 0x000078608737a68c clang::FrontendAction::Execute() (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2d7a68c)
#13 0x00007860872eda04 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2ceda04)
#14 0x00007860873f9d2c clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm-19/bin/../lib/libclang-cpp.so.19.1+0x2df9d2c)
#15 0x000061625d4a71f2 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm-19/bin/clang+0x131f2)
#16 0x000061625d4a41c4 (/usr/lib/llvm-19/bin/clang+0x101c4)
#17 0x000061625d4a3362 clang_main(int, char**, llvm::ToolContext const&) (/usr/lib/llvm-19/bin/clang+0xf362)
#18 0x000061625d4b1723 main (/usr/lib/llvm-19/bin/clang+0x1d723)
#19 0x000078607c22a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#20 0x000078607c22a28b call_init ./csu/../csu/libc-start.c:128:20
#21 0x000078607c22a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#22 0x000061625d4a1dc5 _start (/usr/lib/llvm-19/bin/clang+0xddc5)
clang++-19: error: unable to execute command: Segmentation fault (core dumped)
clang++-19: error: clang frontend command failed due to signal (use -v to see invocation)
Ubuntu clang version 19.1.1 (1ubuntu1~24.04.2)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin
clang++-19: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++-19: note: diagnostic msg: /tmp/main-95dd6a.cpp
clang++-19: note: diagnostic msg: /tmp/main-95dd6a.sh
clang++-19: note: diagnostic msg:
********************
$ cat /tmp/main-95dd6a.sh
# Crash reproducer for Ubuntu clang version 19.1.1 (1ubuntu1~24.04.2)
# Driver args: "--driver-mode=g++" "-fstack-protector" "-fmodule-file=std=example/hello-world/std.pcm" "-fmodule-file=std=example/hello-world/hello.pcm" "-stdlib=libc++" "-std=c++23" "example/hello-world/main.cc" "-o" "main.pic.o"
# Original command: "/usr/lib/llvm-19/bin/clang" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-obj" "-dumpdir" "main.pic.o-" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "main.cc" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-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/imcoelho/git-reps/rules_cc_module" "-fcoverage-compilation-dir=/home/imcoelho/git-reps/rules_cc_module" "-resource-dir" "/usr/lib/llvm-19/lib/clang/19" "-internal-isystem" "/usr/lib/llvm-19/bin/../include/c++/v1" "-internal-isystem" "/usr/lib/llvm-19/lib/clang/19/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/15/../../../../x86_64-linux-gnu/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-std=c++23" "-fdeprecated-macro" "-ferror-limit" "19" "-stack-protector" "1" "-fgnuc-version=4.2.1" "-fno-implicit-modules" "-fmodule-file=std=example/hello-world/std.pcm" "-fmodule-file=std=example/hello-world/hello.pcm" "-fskip-odr-check-in-gmf" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "/tmp/main-be446a.o" "-x" "c++" "example/hello-world/main.cc"
"/usr/lib/llvm-19/bin/clang" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-obj" "-dumpdir" "main.pic.o-" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "main.cc" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-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/imcoelho/git-reps/rules_cc_module" "-fcoverage-compilation-dir=/home/imcoelho/git-reps/rules_cc_module" "-std=c++23" "-fdeprecated-macro" "-ferror-limit" "19" "-stack-protector" "1" "-fgnuc-version=4.2.1" "-fno-implicit-modules" "-fmodule-file=std=example/hello-world/std.pcm" "-fmodule-file=std=example/hello-world/hello.pcm" "-fskip-odr-check-in-gmf" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-faddrsig" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-x" "c++" "main-95dd6a.cpp"
$ cat /tmp/main-95dd6a.cpp
# 1 "example/hello-world/main.cc"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 484 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "example/hello-world/main.cc" 2
import hello;
import std;
int main() {
do_hello("world");
return 0;
}
It breaks with 1. example/hello-world/main.cc:5:11: current parser token ';'
But it seems to occur only if I enable -fstack-protector ... if I remove it, the bug is gone (but error correctly remains):
$ clang++-19 -fmodule-file=std=example/hello-world/std.pcm -fmodule-file=std=example/hello-world
/hello.pcm -stdlib=libc++ -std=c++23 example/hello-world/main.cc -o main.pic.o
example/hello-world/main.cc:2:8: fatal error: module 'hello' not found
2 | import hello;
| ~~~~~~~^~~~~
1 error generated.