[PATCH] D131270: MC: make section classification a bit more thorough
Matthias Braun via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 24 17:37:35 PDT 2022
MatzeB added a comment.
Hey, I started hitting assertions when creating assembly and subsequently assembling things. In my case I am building the llvm-test-suite with `-save-temps=obj` but I can reproduce with something smaller/simpler:
struct C {
C(int x) { a = x; }
int a;
};
inline C& getNullInstance() {
static C instance(42);
return instance;
}
void* used = (void*)getNullInstance;
$ CLANG=~/local/llvm-builds/e41dd0205242/bin/clang
$ $CLANG -S repro.cpp && $CLANG -c repro.s
# no error
$ CLANG=~/local/llvm-builds/73a9dfcee24d/bin/clang
$ $CLANG -S repro.cpp && $CLANG -c repro.s
clang: /tmp/tmpssp98atc/llvm-project/llvm/lib/MC/MCAssembler.cpp:767: void llvm::MCAssembler::writeSectionData(llvm::raw_ostream &, const llvm::MCSection *, const llvm::MCAsmLayout &) const: Assertion `(cast<MCAlignFragment>(F).getValueSize() == 0 || cast<MCAlignFragment>(F).getValue() == 0) && "Invalid align in virtual section!"' failed.
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: /home/matthiasb/local/llvm-builds/73a9dfcee24d/bin/clang -c repro.s
#0 0x0000000001d15c23 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/matthiasb/local/llvm-builds/73a9dfcee24d/bin/clang+0x1d15c23)
#1 0x0000000001d13a5e llvm::sys::RunSignalHandlers() (/home/matthiasb/local/llvm-builds/73a9dfcee24d/bin/clang+0x1d13a5e)
#2 0x0000000001d1502d llvm::sys::CleanupOnSignal(unsigned long) (/home/matthiasb/local/llvm-builds/73a9dfcee24d/bin/clang+0x1d1502d)
#3 0x0000000001c8a2de (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) CrashRecoveryContext.cpp:0:0
#4 0x0000000001c8a530 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#5 0x00007f919418dce0 __restore_rt (/lib64/libpthread.so.0+0x12ce0)
#6 0x00007f9192eb0a9f raise (/lib64/libc.so.6+0x4ea9f)
#7 0x00007f9192e83e05 abort (/lib64/libc.so.6+0x21e05)
#8 0x00007f9192e83cd9 _nl_load_domain.cold.0 (/lib64/libc.so.6+0x21cd9)
#9 0x00007f9192ea93f6 (/lib64/libc.so.6+0x473f6)
#10 0x000000000195b462 llvm::MCAssembler::writeSectionData(llvm::raw_ostream&, llvm::MCSection const*, llvm::MCAsmLayout const&) const (/home/matthiasb/local/llvm-builds/73a9dfcee24d/bin/clang+0x195b462)
#11 0x00000000019e0c0a (anonymous namespace)::ELFWriter::writeObject(llvm::MCAssembler&, llvm::MCAsmLayout const&) ELFObjectWriter.cpp:0:0
#12 0x00000000019df1f5 (anonymous namespace)::ELFSingleObjectWriter::writeObject(llvm::MCAssembler&, llvm::MCAsmLayout const&) ELFObjectWriter.cpp:0:0
#13 0x000000000195c4a6 llvm::MCAssembler::Finish() (/home/matthiasb/local/llvm-builds/73a9dfcee24d/bin/clang+0x195c4a6)
#14 0x000000000197ba46 llvm::MCELFStreamer::finishImpl() (/home/matthiasb/local/llvm-builds/73a9dfcee24d/bin/clang+0x197ba46)
#15 0x00000000019e86d1 (anonymous namespace)::AsmParser::Run(bool, bool) AsmParser.cpp:0:0
#16 0x00000000009e2244 cc1as_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/matthiasb/local/llvm-builds/73a9dfcee24d/bin/clang+0x9e2244)
#17 0x00000000009dc4c6 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#18 0x0000000002586082 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
#19 0x0000000001c8a159 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/matthiasb/local/llvm-builds/73a9dfcee24d/bin/clang+0x1c8a159)
#20 0x0000000002585ad0 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/matthiasb/local/llvm-builds/73a9dfcee24d/bin/clang+0x2585ad0)
#21 0x00000000025457e8 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/matthiasb/local/llvm-builds/73a9dfcee24d/bin/clang+0x25457e8)
#22 0x0000000002545aee clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/matthiasb/local/llvm-builds/73a9dfcee24d/bin/clang+0x2545aee)
#23 0x00000000025656d0 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/matthiasb/local/llvm-builds/73a9dfcee24d/bin/clang+0x25656d0)
#24 0x00000000009db8d1 clang_main(int, char**) (/home/matthiasb/local/llvm-builds/73a9dfcee24d/bin/clang+0x9db8d1)
#25 0x00007f9192e9ccf3 __libc_start_main (/lib64/libc.so.6+0x3acf3)
#26 0x00000000009d8cfe _start (/home/matthiasb/local/llvm-builds/73a9dfcee24d/bin/clang+0x9d8cfe)
Looking at the assembly files with this diff we start emitting `.p2align 2, 0x90` instead of just `.p2align 3` for some weak-symbol things. This subsequently triggers the compiler assertion.
Once I generated the "bad" assembly it hits an assert even in clang/llvm versions before this change...
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D131270/new/
https://reviews.llvm.org/D131270
More information about the llvm-commits
mailing list