error: Invalid record (Producer: 'LLVM14.0.0git' Reader: 'LLVM 14.0.0git')
zyz9740 opened this issue · 7 comments
When I build using cheerp, I encounter similar problem as https://github.com/leaningtech/cheerp-meta/issues/115
This is my source file. I try to reduce it thus helping your bug tracing
#include <stdio.h>
union {
// This will succeed
// unsigned a;
// This will fail
unsigned a : 5;
int b;
} c;
int main() {
printf("%d\n", c.a);
}
Try to reproduce this bug by /opt/cheerp/bin/clang -target cheerp-wasm random.c -O3 -o random_cheerp.js -v
And I got the log as below:
Cheerp 2.7-1~focal clang version 14.0.0
Target: cheerp-leaningtech-webbrowser-wasm
Thread model: posix
InstalledDir: /opt/cheerp/bin
"/opt/cheerp/bin/clang-14" -cc1 -triple cheerp-leaningtech-webbrowser-wasm -emit-llvm-bc -emit-llvm-uselists -disable-free -disable-llvm-verifier -discard-value-names -main-file-name random.c -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -fno-verbose-asm -no-integrated-as -mconstructor-aliases -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -fno-dwarf-directory-asm -v -fcoverage-compilation-dir=/home/oem/zyz/issues/producer_and_reader -resource-dir /opt/cheerp/lib/clang/14.0.0 -internal-isystem /opt/cheerp/lib/clang/14.0.0/include -internal-externc-isystem /opt/cheerp/bin/../include -internal-externc-isystem /opt/cheerp/bin/../include/client -O3 -fdebug-compilation-dir=/home/oem/zyz/issues/producer_and_reader -ferror-limit 19 -fgnuc-version=4.2.1 -fno-threadsafe-statics -fcolor-diagnostics -vectorize-loops -vectorize-slp -o /tmp/random-256c9a.bc -x c random.c
clang -cc1 version 14.0.0 based upon LLVM 14.0.0git default target cheerp-leaningtech-webbrowser-wasm
#include "..." search starts here:
#include <...> search starts here:
/opt/cheerp/lib/clang/14.0.0/include
/opt/cheerp/bin/../include
/opt/cheerp/bin/../include/client
End of search list.
"/opt/cheerp/bin/llvm-link" -o /tmp/random-0e53ac.bc /tmp/random-256c9a.bc /opt/cheerp/bin/../lib/asmjs/libc.bc /opt/cheerp/bin/../lib/asmjs/libm.bc /opt/cheerp/bin/../lib/libwasm.bc
error: Invalid record (Producer: 'LLVM14.0.0git' Reader: 'LLVM 14.0.0git')
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
If needed any other information, just ask me. I will reply as fast as I can.
I will need to investigate on this, will come back if I need more info.
Thanks,
Carlo
My understanding of the situation is the following: errors like this are due to the fact that the release version has assertion disabled, so there might code-paths that are normally guarded by assertions and that will generate an invalid IR, and when the linker step parse and validate the IR that it fails.
When compiling with assertions enabled, I see the following trace
...
#11 0x000056300f5594d8 llvm::Type::getContainedType(unsigned int) const /home/carlo/cheerp-rebased/cheerp-compiler-new/llvm/include/llvm/IR/Type.h:338:5
#12 0x000056300f5594d8 llvm::Type::getScalarType() const /home/carlo/cheerp-rebased/cheerp-compiler-new/llvm/include/llvm/IR/Type.h:310:14
#13 0x000056300f5594d8 llvm::ConstantInt::get(llvm::Type*, llvm::APInt const&) /home/carlo/cheerp-rebased/cheerp-compiler-new/llvm/lib/IR/Constants.cpp:951:3
#14 0x000056300f81bbd2 llvm::IRBuilderBase::CreateAnd(llvm::Value*, llvm::APInt const&, llvm::Twine const&) /home/carlo/cheerp-rebased/cheerp-compiler-new/llvm/include/llvm/IR/IRBuilder.h:1389:27
#15 0x00005630102cf69d clang::CodeGen::CodeGenFunction::EmitLoadOfBitfieldLValue(clang::CodeGen::LValue, clang::SourceLocation) /home/carlo/cheerp-rebased/cheerp-compiler-new/clang/lib/CodeGen/CGExpr.cpp:2029:21
#16 0x00005630102cc22e clang::CodeGen::CodeGenFunction::EmitLoadOfLValue(clang::CodeGen::LValue, clang::SourceLocation) /home/carlo/cheerp-rebased/cheerp-compiler-new/clang/lib/CodeGen/CGExpr.cpp:0:10
#17 0x0000563010311275 llvm::PointerIntPair<llvm::Value*, 2u, clang::CodeGen::RValue::Flavor, llvm::PointerLikeTypeTraits<llvm::Value*>, llvm::PointerIntPairInfo<llvm::Value*, 2u, llvm::PointerLikeTypeTraits<llvm::Value*> > >::getInt() const /home/carlo/cheerp-rebased/cheerp-compiler-new/llvm/include/llvm/ADT/PointerIntPair.h:62:57
...
I believe this (and other bugs currently open) to be all related to the same underlying problem, I will come back when I have the solution.
My understanding of the situation is the following: errors like this are due to the fact that the release version has assertion disabled, so there might code-paths that are normally guarded by assertions and that will generate an invalid IR, and when the linker step parse and validate the IR that it fails.
When compiling with assertions enabled, I see the following trace
... #11 0x000056300f5594d8 llvm::Type::getContainedType(unsigned int) const /home/carlo/cheerp-rebased/cheerp-compiler-new/llvm/include/llvm/IR/Type.h:338:5 #12 0x000056300f5594d8 llvm::Type::getScalarType() const /home/carlo/cheerp-rebased/cheerp-compiler-new/llvm/include/llvm/IR/Type.h:310:14 #13 0x000056300f5594d8 llvm::ConstantInt::get(llvm::Type*, llvm::APInt const&) /home/carlo/cheerp-rebased/cheerp-compiler-new/llvm/lib/IR/Constants.cpp:951:3 #14 0x000056300f81bbd2 llvm::IRBuilderBase::CreateAnd(llvm::Value*, llvm::APInt const&, llvm::Twine const&) /home/carlo/cheerp-rebased/cheerp-compiler-new/llvm/include/llvm/IR/IRBuilder.h:1389:27 #15 0x00005630102cf69d clang::CodeGen::CodeGenFunction::EmitLoadOfBitfieldLValue(clang::CodeGen::LValue, clang::SourceLocation) /home/carlo/cheerp-rebased/cheerp-compiler-new/clang/lib/CodeGen/CGExpr.cpp:2029:21 #16 0x00005630102cc22e clang::CodeGen::CodeGenFunction::EmitLoadOfLValue(clang::CodeGen::LValue, clang::SourceLocation) /home/carlo/cheerp-rebased/cheerp-compiler-new/clang/lib/CodeGen/CGExpr.cpp:0:10 #17 0x0000563010311275 llvm::PointerIntPair<llvm::Value*, 2u, clang::CodeGen::RValue::Flavor, llvm::PointerLikeTypeTraits<llvm::Value*>, llvm::PointerIntPairInfo<llvm::Value*, 2u, llvm::PointerLikeTypeTraits<llvm::Value*> > >::getInt() const /home/carlo/cheerp-rebased/cheerp-compiler-new/llvm/include/llvm/ADT/PointerIntPair.h:62:57 ...
I believe this (and other bugs currently open) to be all related to the same underlying problem, I will come back when I have the solution.
Hi, I reproduce this bug, and confuse why the crash happens in the link step? Because I just run
/opt/cheerp/bin/clang-14 -cc1 -triple cheerp-leaningtech-webbrowser-wasm -emit-llvm-bc -emit-llvm-uselists -disable-free -main-file-name random.c -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -fno-verbose-asm -no-integrated-as -mconstructor-aliases -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -fno-dwarf-directory-asm -v -fcoverage-compilation-dir=/home/ruiying/test-input -resource-dir /opt/cheerp/lib/clang/14.0.0 -internal-isystem /opt/cheerp/lib/clang/14.0.0/include -internal-externc-isystem /opt/cheerp/bin/../include -internal-externc-isystem /opt/cheerp/bin/../include/client -O3 -fdebug-compilation-dir=/home/ruiying/test-input -ferror-limit 19 -fgnuc-version=4.2.1 -fno-threadsafe-statics -fcolor-diagnostics -vectorize-loops -vectorize-slp -o /tmp/random-4cb084.bc -x c random.c
and there also exists the same crash, so I think maybe there is something wrong during first compilation to LLVM IR?
Looking forward to your answer, Thanks!
@sun-ruijiang Can you please provide a reproducible use case for your problem? It is not likely that it is actually the same.
@sun-ruijiang Why do you think that issue is connected to this? Just the error message is similar since both tools are clang/LLVM based.
When I asked Bing AI this question, they told me your link. Sorry, I just wanted some help so I asked.
The original issues was most likely about bitfields in the global space, and it is now fixed in Cheerp master