3

I have the latest version of Intel Pin 3.0 version 76887.

I have an MPX-enabled toy example:

#include <stdio.h>
int g[10];
int main(int argc, char **argv) {
  int x = g[11];
  printf("%d\n", x);
  return 0;
}

When compiled with gcc + MPX, I see MPX instructions in the disassembly via objdump, and the example correctly writes me a bounds violation:

Saw a #BR! status 0 at 0x401798

Now I'd like to count the total number of specific MPX instructions using Intel Pin, e.g., BNDLDX and BNDMK.

My first attempt was using the shipped tool source/tools/SimpleExamples/trace.cpp. This tool showed me NOPs at places of MPX instructions.

In my second attempt, I wrote my own tool with the following snippet:

xed_iclass_enum_t iclass = (xed_iclass_enum_t)INS_Opcode(ins);
if (iclass == XED_ICLASS_BNDMK)
    INS_InsertPredicatedCall(ins, IPOINT_BEFORE, (AFUNPTR)countBndmk, IARG_END);

This doesn't work, countBndmk is never called. I double-checked my code with other instruction iclasses, and they worked. So clearly there is a problem of Pin (or XED?) not recognizing MPX instructions.


Browsing the docs, I noticed an interesting knob

KNOB<BOOL> knob_mpx_mode(KNOB_MODE_WRITEONCE,"supported:xed","xed_mpx_mode","0","Enable Intel(R) MPX instruction decoding")

This knob seems to enable MPX decoding and is 0 by default, and I don't know how to enable it per command-line or in my tool. I found no other references to this problem in code or internet.


I know I could use Intel SDE to dump the debug trace including MPX instructions. I wonder if there is a way to enable MPX in Intel Pin. Or the only solution is to decode opcodes myself?

  • Tried to print the instructions - it gives me nops every time (my architecture doesn't support pin). May be architecture is the problem here? Did you check if your architecture supports it? (just a guess) – R4444 Feb 19 '19 at 15:54

1 Answers1

0

Maybe a little bit late to answer, but it seems that you have just to pass the option to PIN.

A little bit of background:

On the Intel manual there's this line (nothing to do with MPX, but it gives a clue):

Add the knob support_jit_api to the Pin command line as Pin tool option:
    <Pin executable> <pin options> -t <Pin tool> -support_jit_api <Other Pin tool options> -- <Test application> <Test application options>

It happens there's an existing KNOB for this option:

KNOB<BOOL> LEVEL_PINCLIENT::KnobJitApi  (   KNOB_MODE_WRITEONCE     ,
"pintool:sym"   ,
"support_jit_api"   ,
"0"     ,
"Enables the Jitted Functions Support"  
)

As the MPX knob is defined as:

KNOB<BOOL> knob_mpx_mode(KNOB_MODE_WRITEONCE,"supported:xed","xed_mpx_mode","0","Enable Intel(R) MPX instruction decoding")

I guess you just have to pass the option to PIN:

<Pin executable> <pin options> -t <Pin tool> -xed_mpx_mode <Other Pin tool options> -- <Test application> <Test application options>

It seems that those KNOBs are hardcoded onto PIN / PinTools.

Neitsa
  • 7,693
  • 1
  • 28
  • 45
  • Thanks for this research, ufortunately, adding these options to command-line does not help (Pin always complains about unknown options). – Dmitrii Kuvaiskii Dec 05 '16 at 09:22