Tool: mp_objdump2mpt
Overview
Objdump to MicroprobeTest (mpt) tool provides a command-line interface (CLI) to interpret objdump outputs and generate the corresponding MPT file (Microprobe test (mpt) format). From the MPT format the user can use existing tools (Command line tools) to produce test cases for different environments and formats.
Note
The microbenchmark generation policy implemented in this tool reproduces exactly the code provided. It resolves any symbolic references (references to data, or branch targets), and only if specified by the user, it initializes some registers to not break the target Application Binary Interface.
Basic usage
> mp_objdump2mpt -T TARGET -i OBJDUMP_FILE -O MPT_OUTPUT_FILE
where:
Flag/Argument |
Description |
---|---|
|
Target definition string. Check: Command line target definition scheme |
|
Objdump file generated with Objdump (see details in the following section) |
|
Output file name |
How to obtain an objdump file?
objdump (part of the GNU Binutils) is a program for displaying various information about object files. An object file is a file containing object code, meaning relocatable format machine code that is usually not directly executable. There are various formats for object files, and the same object code can be packaged in different object files. In addition to the object code itself, object files may contain metadata used for linking or debugging, including: information to resolve symbolic cross-references between different modules, relocation information, stack unwinding information, comments, program symbols, debugging or profiling information. Consequently, objdump can be used as a disassembler to view an executable in assembly form. More details on the wikipedia webpage.
The command to get an dump of a binary using objdump is the following:
> objdump -D -z your_binary_file > mydump.dump
the -D
flag forces the tool to dump also the data sections (not
only the executable ones) and the -z
flag instructs the tool to dump
everything (long regions of zero values are typically excluded).
Note
Only dumps from GNU Binutils objdump are currently supported.
Ensuring the Application Binary Interface
The ABI (Application Binary Interface) for a given environment (defined in here ) specifies the semantics of registers and the calling conventions. For instance, usually a register is reserved to point to the stack. So, the code being extracted from the objdump output requires that these registers contain appropriate values. It is up to the user to initialize them correctly, although the tool provides some support for that.
Currently, this tool supports the automatic definition of the stack, the automatic initialization of the stack pointer and the definition of the start symbol which will be called after initializing the environment. The user can use the following flags to change the different options:
Flag/Argument |
Description |
---|---|
|
Ensure ELF Application Binary Interface (e.g. define stack, stack pointer, etc.) |
|
Stack size in bytes (default: 4096) |
|
Stack name (Default: microprobe_stack) |
|
Stack address (Default: allocated in the data area) |
|
Symbol to call after initializing the stack. If not specified, no call is performed |
|
End the code with a branch to itself instruction |
Note
The necessary instructions required for initializing the stack pointer will be added at the beginning of the code (on lower addresses) and the start code address will be modified accordingly.
Note
If the start symbol is specified, function linkage instructions are used to call that symbol after initializing the environment. It is up to the user to define the behavior when the called function returns. That is, no specific instructions are added after the call (return address for the called function) and therefore the behavior is not specified.
Full usage
mp_objdump2mpt.py: INFO: Processing input arguments...
usage: mp_objdump2mpt.py [-h] [-P SEARCH_PATH [SEARCH_PATH ...]] [-V] [-v]
[-d] [-c CONFIG_FILE [CONFIG_FILE ...]]
[-C FORCE_CONFIG_FILE]
[--dump-configuration-file OUTPUT_CONFIG_FILE]
[--dump-full-configuration-file OUTPUT_CONFIG_FILE]
[-A ARCHITECTURE_PATHS] [-M MICROARCHITECTURE_PATHS]
[-E ENVIRONMENT_PATHS] -T TARGET
[--list-architectures] [--list-microarchitectures]
[--list-environments] [--traceback]
[--profile PROFILE_OUTPUT] [-i INPUT_OBJDUMP_FILE] -O
OUTPUT_MPT_FILE [-S] [-s SECTIONS [SECTIONS ...]]
[-f FROM_ADDRESS] [-t TO_ADDRESS]
[-X DEFAULT_CODE_ADDRESS] [-D DEFAULT_DATA_ADDRESS]
[--elf-abi] [--stack-size STACK_SIZE]
[--stack-name STACK_NAME]
[--stack-address STACK_ADDRESS]
[--start-symbol START_SYMBOL]
[--end-branch-to-itself]
Microprobe Objdump to MPT tool
optional arguments:
-h, --help show this help message and exit
-P SEARCH_PATH [SEARCH_PATH ...], --default_paths SEARCH_PATH [SEARCH_PATH ...]
Default search paths for microprobe target definitions
-V, --version Show Microprobe version and exit
-v, --verbosity Verbosity level (Values: [0,1,2,3,4]). Each time this
argument is specified the verbosity level is
increased. By default, no logging messages are shown.
These are the four levels available:
-v (1): critical messages
-v -v (2): critical and error messages
-v -v -v (3): critical, error and warning messages
-v -v -v -v (4): critical, error, warning and info messages
Specifying more than four verbosity flags, will
default to the maximum of four. If you need extra
information, enable the debug mode (--debug or -d
flags).
-d, --debug Enable debug mode in Microprobe framework. Lots of
output messages will be generated
Configuration arguments:
Command arguments related to configuration file handling
-c CONFIG_FILE [CONFIG_FILE ...], --configuration CONFIG_FILE [CONFIG_FILE ...]
Configuration file. The configuration files will be
readed in order of appearance. Values are reset by the
last configuration file in case of non-list values.
List values will be appended (not reset)
-C FORCE_CONFIG_FILE, --force-configuration FORCE_CONFIG_FILE
Force configuration file. Use this configuration file
as the default start configuration. This disables any
system-wide, or user-provided configuration.
--dump-configuration-file OUTPUT_CONFIG_FILE
Dump a configuration file with the actual
configuration used
--dump-full-configuration-file OUTPUT_CONFIG_FILE
Dump a configuration file with the actual
configuration used plus all the configuration options
not set
Target path arguments:
Command arguments related to target paths
-A ARCHITECTURE_PATHS, --architecture-paths ARCHITECTURE_PATHS
Search path for architecture definitions. Microprobe
will search in these paths for architecture
definitions
-M MICROARCHITECTURE_PATHS, --microarchitecture-paths MICROARCHITECTURE_PATHS
Search path for microarchitecture definitions.
Microprobe will search in these paths for
microarchitecture definitions
-E ENVIRONMENT_PATHS, --environment-paths ENVIRONMENT_PATHS
Search path for environment definitions. Microprobe
will search in these paths for environment definitions
Target arguments:
Command arguments related to target specification and queries
-T TARGET, --target TARGET
Target tuple. Microprobe follows a GCC-like target
definition scheme, where a target is defined by a
tuple as following:
<arch-name>-<uarch-name>-<env-name>
where:
<arch-name>: is the name of the architecture
<uarch-name>: is the name of the microarchitecture
<env-name>: is the name of the environment
One can use --list-* options to get the list of
definitions available in the default search paths or
the paths specified by the different --*-paths options
--list-architectures Generate a list of architectures available in the
defined search paths and exit
--list-microarchitectures
Generate a list of microarchitectures available in the
defined search paths and exit
--list-environments Generate a list of environments available in the
defined search paths and exit
Debug arguments:
Command arguments related to debugging facilities
--traceback show a traceback and starts a python debugger (pdb)
when an error occurs. 'pdb' is an interactive python
shell that facilitates the debugging of errors
--profile PROFILE_OUTPUT
dump profiling information into given file (see
'pstats' module)
Objdump to MPT arguments:
Command arguments related to Objdump to MPT tool
-i INPUT_OBJDUMP_FILE, --input-objdump-file INPUT_OBJDUMP_FILE
Objdump file to process, if not provided, the input is
read from standard input
-O OUTPUT_MPT_FILE, --output-mpt-file OUTPUT_MPT_FILE
Output file name
-S, --strict Be strict when parsing objdump input, if not set,
silently skip unparsed elements
-s SECTIONS [SECTIONS ...], --sections SECTIONS [SECTIONS ...]
Space separated CODE section names to interpret.
(default: '.text' section)
-f FROM_ADDRESS, --from-address FROM_ADDRESS
If set, start interpreting from this address
-t TO_ADDRESS, --to-address TO_ADDRESS
If set, end interpreting at this address
-X DEFAULT_CODE_ADDRESS, --default-code-address DEFAULT_CODE_ADDRESS
Default code address
-D DEFAULT_DATA_ADDRESS, --default-data-address DEFAULT_DATA_ADDRESS
Default data address
--elf-abi Ensure ELF Application Binary Interface (e.g. define
stack, stack pointer, etc.)
--stack-size STACK_SIZE
Stack size in bytes (Default: 4096)
--stack-name STACK_NAME
Stack name (Default: microprobe_stack)
--stack-address STACK_ADDRESS
Stack address (Default: allocated in the data area)
--start-symbol START_SYMBOL
Symbol to call after initializing the stack. If not
specified, no call is performed
--end-branch-to-itself
A branch to itself instruction will be added at the
end of the test
Environment variables:
MICROPROBETEMPLATES Default path for microprobe templates
MICROPROBEDEBUG If set, enable debug
MICROPROBEDEBUGPASSES If set, enable debug during passes
MICROPROBEASMHEXFMT Assembly hexadecimal format. Options:
'all' -> All immediates in hex format
'address' -> Address immediates in hex format (default)
'none' -> All immediate in integer format
Example outputs
Example 1:
Command:
> mp_objdump2mpt.py -T riscv_v22-riscv_generic-riscv64_linux_gcc -O output.mpt -i input.objdump -s microprobe.text --elf-abi
Input file input.objdump
:
1
2c2mpt_test003.target.bin: file format elf64-littleriscv
3
4
5Disassembly of section microprobe.text:
6
70000000010030000 <c2mpt_function>:
8 10030000: 10040637 lui a2,0x10040
9 10030004: 00060613 mv a2,a2
10 10030008: 00863783 ld a5,8(a2) # 10040008 <linkedlist+0x8>
11 1003000c: 05063703 ld a4,80(a2)
12 10030010: 00078a63 beqz a5,10030024 <c2mpt_function+0x24>
13 10030014: 0007b683 ld a3,0(a5)
14 10030018: 0087b783 ld a5,8(a5)
15 1003001c: 00d70733 add a4,a4,a3
16 10030020: fe079ae3 bnez a5,10030014 <c2mpt_function+0x14>
17 10030024: 00171713 slli a4,a4,0x1
18 10030028: 04e63823 sd a4,80(a2)
19 1003002c: 00008067 ret
20
210000000010030030 <my_subroutine>:
22 10030030: 00151513 slli a0,a0,0x1
23 10030034: 100407b7 lui a5,0x10040
24 10030038: 04a7b823 sd a0,80(a5) # 10040050 <count>
25 1003003c: 00008067 ret
26
27Disassembly of section microprobe.data:
28
290000000010040000 <linkedlist>:
30 10040000: 0000 unimp
31 10040002: 0000 unimp
32 10040004: 0000 unimp
33 10040006: 0000 unimp
34 10040008: 0000 unimp
35 1004000a: 0000 unimp
36 1004000c: 0000 unimp
37 1004000e: 0000 unimp
38 10040010: 0000 unimp
39 10040012: 0000 unimp
40 10040014: 0000 unimp
41 10040016: 0000 unimp
42 10040018: 0000 unimp
43 1004001a: 0000 unimp
44 1004001c: 0000 unimp
45 1004001e: 0000 unimp
46 10040020: 0000 unimp
47 10040022: 0000 unimp
48 10040024: 0000 unimp
49 10040026: 0000 unimp
50 10040028: 0000 unimp
51 1004002a: 0000 unimp
52 1004002c: 0000 unimp
53 1004002e: 0000 unimp
54 10040030: 0000 unimp
55 10040032: 0000 unimp
56 10040034: 0000 unimp
57 10040036: 0000 unimp
58 10040038: 0000 unimp
59 1004003a: 0000 unimp
60 1004003c: 0000 unimp
61 1004003e: 0000 unimp
62 10040040: 0000 unimp
63 10040042: 0000 unimp
64 10040044: 0000 unimp
65 10040046: 0000 unimp
66 10040048: 0000 unimp
67 1004004a: 0000 unimp
68 1004004c: 0000 unimp
69 1004004e: 0000 unimp
70
710000000010040050 <count>:
72 10040050: cafe sw t6,84(sp)
73 10040052: cafe sw t6,84(sp)
74 10040054: 0000 unimp
75 10040056: 0000 unimp
Output file output.mpt
:
1; Microprobe Test Definition File
2[MPT]
3mpt_version = 0.5 ; Format version of this MPT file.
4
5[REGISTERS] ; Section to specify the initial register values
6
7; Format: register = value. E.g.:
8
9; Set GR0, GR1 and GR2 register to 0, 1, 2 values respectively
10;GR0 = 0x0
11
12
13[DATA] ; Section to specify the variables
14
15; Data section default address. Variables will be placed from this address
16; if their address is not specified
17
18default_address = 0x0000000000000000
19
20; Variable Declaration
21; Format: var_name = [ "type", nelems, address, alignment, init_values ]
22; where:
23; - "type": is a string specifying the type of elements in the variable
24; - nelems: is the number of elements in the variable
25; - address : is the address of the variable, if set the address will be
26; fixed, otherwise, it will be computer by microprobe
27; - alignment : alignment requirements of the variable. It should not
28; conflict with address if specified. It can be set to None
29; - init_values : if it is a single value, all the elements will be
30; initialized to that value, if it is an array, elements
31; will be initialized to the values specified in a round-
32; robin fashion. Two special keywords can be specified:
33; RNDFP and RNDINT to initialize the elements to random FP
34; and random INT values
35;
36; Note that variable names ARE NOT case sensitive. I.e. VAR = Var = var
37
38linkedlist = ["char", 00000040, 0x0000000010040000, None, None]
39count = ["char", 00000004, 0x0000000010040050, None, [51966, 51966, 0, 0]]
40microprobe stack = ["uint8_t", 00004096, None, 0x0010, None]
41
42[CODE] ; Section to specify the code
43
44; Code section default address. Code will be placed from this address
45; if the instruction address is not specified
46
47default_address = 0x000000001002fff8
48
49; The code specified after 'instructions' entry (below) is the code that will be
50; processed by microprobe. The instruction format is similar to GNU assembler
51; format, it also allows the specification of labels (NOT case sensitive) and
52; references to the declared variables. It is also possible to specify instruction
53; addresses and to do code expansion by referencing other user
54; defined entries. Check the example below to see examples of these features.
55;
56; *****************************************************************************
57; ****** Although Microprobe performs some sanity checks, it is the ********
58; ****** responsibility of the user to define correct code. ********
59; ****** ********
60; *****************************************************************************
61
62instructions =
63 <ELF_ABI_START>:
64 AUIPC x2, %pcrel_hi(microprobe stack)
65 ADDI x2, x2, %pcrel_lo(microprobe stack_pcrel_1)
66 0x0000000010030000 <C2MPT_FUNCTION>:
67 LUI x12, 65600
68 ADDI x12, x12, 0x0
69 LD x15, 0x8(x12)
70 LD x14, 0x50(x12)
71 BEQ x15, x0, C2MPT_FUNCTION+0X24
72 LD x13, 0x0(x15)
73 LD x15, 0x8(x15)
74 ADD x14, x14, x13
75 BNE x15, x0, C2MPT_FUNCTION+0X14
76 SLLI x14, x14, 1
77 SD x14, 0x50(x12)
78 JALR x0, 0x0(x1)
79 0x0000000010030030 <MY_SUBROUTINE>:
80 SLLI x10, x10, 1
81 LUI x15, 65600
82 SD x10, 0x50(x15)
83 JALR x0, 0x0(x1)
84 <ELF_ABI_EXIT>:
85 ADDI x0, x0, 0x0