Open
Description
After #136121 is merged, thin LTO with assembly output with cache crashes lld. A test case is basic:
int main() { return 0; }
clang -c main.c -O2 -flto=thin -o main.o
ld.lld --thinlto-cache-dir=. --lto-emit-asm -e main main.o
The cache directory should not have cached output files.
The output stream in LTOBackend: codegen()
is of type CacheStream
, defined in Caching.cpp. The commit function of this class deletes the underlying raw_pwrite_stream
(OS). With LTO and assembly output, MCAsmStreamer is created as an output streamer and it also holds a raw pointer to raw_pwrite_stream
indirectly through a formatted_raw_output
wrapper. In the MCAsmStreamer
destructor, formatted_raw_ostream
calls flush()
on a deleted object.
A simple fix would be to delete the LTO pipeline before the stream commit function is called in LTOBackend.cpp: codegen().