Skip to content

Commit 4c5e0eb

Browse files
committed
Reduce amount of error messages when failing to initialize LLVM
1 parent a551e24 commit 4c5e0eb

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/utils/hsdis/hsdis.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -600,19 +600,34 @@ class hsdis_backend : public hsdis_backend_base {
600600
if (_arch_name[0] == '\0')
601601
_arch_name = native_target_triple();
602602

603+
static bool complained = false;
604+
603605
if (LLVMInitializeNativeTarget() != 0) {
604-
fprintf(stderr, "failed to initialize LLVM native target\n");
606+
if (!complained)
607+
(*_printf_callback)(_printf_stream, "failed to initialize LLVM native target\n");
608+
complained = true;
609+
/* must bail out */
610+
_losing = true;
611+
return;
605612
}
606613
if (LLVMInitializeNativeAsmPrinter() != 0) {
607-
fprintf(stderr, "failed to initialize LLVM native asm printer\n");
614+
if (!complained)
615+
(*_printf_callback)(_printf_stream, "failed to initialize LLVM native asm printer\n");
616+
complained = true;
617+
/* must bail out */
618+
_losing = true;
619+
return;
608620
}
609621
if (LLVMInitializeNativeDisassembler() != 0) {
610-
fprintf(stderr, "failed to initialize LLVM native disassembler\n");
622+
if (!complained)
623+
(*_printf_callback)(_printf_stream, "failed to initialize LLVM native disassembler\n");
624+
complained = true;
625+
/* must bail out */
626+
_losing = true;
627+
return;
611628
}
612-
613629
if ((_dcontext = LLVMCreateDisasm(_arch_name, NULL, 0, NULL, NULL)) == NULL) {
614630
const char* bad = _arch_name;
615-
static bool complained;
616631
if (bad == &_target_triple[0])
617632
print_help("bad target_triple=%s", bad);
618633
else if (!complained)

0 commit comments

Comments
 (0)