SystemZ target: OOB read on "llvm-mc -show-inst-operands"
| 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.
ping!
Anyone seen this before?
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?
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)
void SystemZOperand::print(raw_ostream &OS) const is also no longer unimplemented.