Skip to content

Instantly share code, notes, and snippets.

@sklam
Created July 13, 2021 22:55
Show Gist options
  • Save sklam/5d000b89df4abee3fac5141895e06c0e to your computer and use it in GitHub Desktop.
Save sklam/5d000b89df4abee3fac5141895e06c0e to your computer and use it in GitHub Desktop.
Notes on using radare2 with Numba

Numba + Radare2

Information on seeing source info of Numba jit code in radare2.

Getting object file from numba

@njit(debug=True)
def foo():
    ...

# Trigger compilation
foo()

# Get CodeLibrary
ov = foo.overloads[foo.signatures[0]]
lib = ov.library
# Write out the compiled object file
with open("out.o", 'wb') as fout:
    fout.write(lib._get_compiled_object())

Using Radare2

The following instructions work on radare2 5.3. It's easiest to a recent radare2 prebuilt binary from a recent centos docker image and just yum install radare2.

For some unknown reason, radare2 cannot read the object file directly. We need to make a shared object first:

$ gcc -g -O0 -shared -o out.so  out.o

Then, we can invoke radare2 on the out.so:

$ radare2 -e io.cache=true -e asm.dwarf=true out.so

Radare2 commands needed:

  • aaaaa - enables some analysis
  • v - visual mode
    • V - graph mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment