llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

SystemZ target: OOB read on "llvm-mc -show-inst-operands"

Open llvmbot opened this issue 11 years ago • 4 comments

Bugzilla Link 25647
Version trunk
OS Linux
Attachments Command line and ASan output
Reporter LLVM Bugzilla Contributor
CC @JonPsson,@uweigand

Extended Description

Compiling LLVM with AddressSanitizer shows that "llvm-mc -show-inst-operands -arch systemz <<< asdf" reads out-of-bounds. See the attached log for more information.

Tested on a19bd39c4e4/r254120 (current git HEAD), but months older versions are affected, too.

llvmbot avatar Nov 26 '15 05:11 llvmbot

ping!

Anyone seen this before?

JonPsson avatar Feb 15 '16 19:02 JonPsson

I ran the test case with valgrind and gdb, and found that the printing of operands is in SystemZ unimplemented:

void SystemZOperand::print(raw_ostream &OS) const { llvm_unreachable("Not implemented"); }

At this point the MCTargetAsmParser destructor is invoked, and there seems to be a problem with a std::string destructor, which causes 3 valgrind errors.

If I add a simple destructor in SystemZAsmParser like

  • ~SystemZAsmParser() {
  • dbgs() << "destructor.\n";
  • }

, then behavour changes! The program now figures out that there are no operands to print, and llvm_unreachable() is not called. Program exits without any memory errors.

SystemZAsmParser inherits from MCTargetAsmParser, which also inherits from a superclass with a virtual destructor. Those destructors are empty. Adding an empty destructor in SystemZAsmParser does not help.

Does this ring a bell for anyone?

JonPsson avatar Dec 04 '15 11:12 JonPsson

I don't think this is a problem any longer:

$ bin/llvm-mc -show-inst-operands -arch systemz <<< asdf
<stdin>:1:1: note: parsed instruction: [Token:asdf]
asdf
^
<stdin>:1:1: error: invalid instruction, did you mean: ad, sd?
asdf
^

(with current main)

dominik-steenken avatar Apr 10 '25 08:04 dominik-steenken

void SystemZOperand::print(raw_ostream &OS) const is also no longer unimplemented.

dominik-steenken avatar Apr 10 '25 08:04 dominik-steenken