Skip to content

assert in BitcodeWriter running llvm-as with partial LTO summaries #44287

@sbc100

Description

@sbc100
Bugzilla Link 44942
Version trunk
OS Linux

Extended Description

I'm seeing this assert fire if ThinLTO summaries are missing for any symbol:

llvm-as test.o.ll
llvm-as: /usr/local/google/home/sbc/dev/wasm/llvm-project/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:3854: void (anonymous namespace)::ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary(): Assertion `F.isDeclaration()' failed.
Stack dump:
0.	Program arguments: ../llvm-build/bin/llvm-as test.o.ll 
 #​0 0x00007f6e6aa0ed64 PrintStackTraceSignalHandler(void*) (/usr/local/google/home/sbc/dev/wasm/llvm-build/bin/../lib/libLLVMSupport.so.11git+0x191d64)
 #​1 0x00007f6e6aa0c8ce llvm::sys::RunSignalHandlers() (/usr/local/google/home/sbc/dev/wasm/llvm-build/bin/../lib/libLLVMSupport.so.11git+0x18f8ce)
 #​2 0x00007f6e6aa0f01c SignalHandler(int) (/usr/local/google/home/sbc/dev/wasm/llvm-build/bin/../lib/libLLVMSupport.so.11git+0x19201c)
 #​3 0x00007f6e6a839520 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x13520)
 #​4 0x00007f6e6a366081 raise /build/glibc-G5rUEF/glibc-2.29/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #​5 0x00007f6e6a351535 abort /build/glibc-G5rUEF/glibc-2.29/stdlib/abort.c:81:7
 #​6 0x00007f6e6a35140f _nl_load_domain /build/glibc-G5rUEF/glibc-2.29/intl/loadmsgcat.c:1177:9
 #​7 0x00007f6e6a35eb92 (/lib/x86_64-linux-gnu/libc.so.6+0x32b92)
 #​8 0x00007f6e6aede1d6 (anonymous namespace)::ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() (/usr/local/google/home/sbc/dev/wasm/llvm-build/bin/../lib/libLLVMBitWriter.so.11git+0x1f1d6)
 #​9 0x00007f6e6aece1ee (anonymous namespace)::ModuleBitcodeWriter::write() (/usr/local/google/home/sbc/dev/wasm/llvm-build/bin/../lib/libLLVMBitWriter.so.11git+0xf1ee)
#&#8203;10 0x00007f6e6aec9aff llvm::BitcodeWriter::writeModule(llvm::Module const&, bool, llvm::ModuleSummaryIndex const*, bool, std::array<unsigned int, 5ul>*) (/usr/local/google/home/sbc/dev/wasm/llvm-build/bin/../lib/libLLVMBitWriter.so.11git+0xaaff)
#&#8203;11 0x00007f6e6aed0995 llvm::WriteBitcodeToFile(llvm::Module const&, llvm::raw_ostream&, bool, llvm::ModuleSummaryIndex const*, bool, std::array<unsigned int, 5ul>*) (/usr/local/google/home/sbc/dev/wasm/llvm-build/bin/../lib/libLLVMBitWriter.so.11git+0x11995)
#&#8203;12 0x00000000004048b5 main (../llvm-build/bin/llvm-as+0x4048b5)
#&#8203;13 0x00007f6e6a352bbb __libc_start_main /build/glibc-G5rUEF/glibc-2.29/csu/../csu/libc-start.c:342:3
#&#8203;14 0x000000000040402a _start (../llvm-build/bin/llvm-as+0x40402a)
Aborted

Reproduction steps:

$ cat test.c 
int foo() {
  return 1;
}

int bar() {
  return 1;
}
$ clang -flto=thin -c -O2 test.c 
$ llvm-dis test.o
# Edit test.o.ll removing the final line which is the LTO summary for bar
$ llvm-as test.o.ll

Now, clearly the issue here is that LTO summaries are incomplete but I would expect an error message telling me that rather than an assert.

I'm not sure what the implications having partial thing LTO summaries is but its possible the fix might just be to remove this assertion? My use case is that I want to peform some manual editing on the bitcode text produced by clang with LTO, but I won't want to have to generate summaries for symbols that I add. My current workaround is to remove LTO summaries completely when I perform such additions (its not a huge deal since this is a debug feature anyway).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions