From 9b02dc631d71ded18bf62ea332b68bd873cc23b6 Mon Sep 17 00:00:00 2001 From: Amir Ayupov Date: Fri, 8 Apr 2022 21:07:27 -0700 Subject: [BOLT] Check MCContext errors Abort on emission errors to prevent a malformed binary being written. Example: ``` :0: error: Undefined temporary symbol .Ltmp26310 :0: error: Undefined temporary symbol .Ltmp26311 :0: error: Undefined temporary symbol .Ltmp26312 :0: error: Undefined temporary symbol .Ltmp26313 :0: error: Undefined temporary symbol .Ltmp26314 :0: error: Undefined temporary symbol .Ltmp26315 BOLT-ERROR: Emission failed. ``` Reviewed By: yota9 Differential Revision: https://reviews.llvm.org/D123263 --- bolt/lib/Rewrite/RewriteInstance.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'bolt') diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp index 1db7bd92a4a0..2cac9d74b83e 100644 --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -3108,6 +3108,10 @@ void RewriteInstance::emitAndLink() { emitBinaryContext(*Streamer, *BC, getOrgSecPrefix()); Streamer->Finish(); + if (Streamer->getContext().hadError()) { + errs() << "BOLT-ERROR: Emission failed.\n"; + exit(1); + } ////////////////////////////////////////////////////////////////////////////// // Assign addresses to new sections. @@ -3137,7 +3141,7 @@ void RewriteInstance::emitAndLink() { RTDyld->finalizeWithMemoryManagerLocking(); if (RTDyld->hasError()) { - outs() << "BOLT-ERROR: RTDyld failed: " << RTDyld->getErrorString() << "\n"; + errs() << "BOLT-ERROR: RTDyld failed: " << RTDyld->getErrorString() << "\n"; exit(1); } -- cgit v1.2.3