diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp --- a/llvm/lib/MC/WinCOFFObjectWriter.cpp +++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp @@ -169,6 +169,7 @@ Strings.clear(); SectionMap.clear(); SymbolMap.clear(); + WeakDefaults.clear(); MCObjectWriter::reset(); } diff --git a/llvm/test/MC/COFF/weak-uaf.ll b/llvm/test/MC/COFF/weak-uaf.ll new file mode 100644 --- /dev/null +++ b/llvm/test/MC/COFF/weak-uaf.ll @@ -0,0 +1,12 @@ +; RUN: llc --compile-twice -mtriple=x86_64-pc-win32 -filetype=obj < %s + +; UAF when re-using the MCObjectWriter. does not leak into the output, +; but should be detectable with --compile-twice under ASAN or so. + +define weak void @foo() nounwind { + ret void +} + +define weak void @bar() nounwind { + ret void +}