Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aarch64 support #34

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion examples/cpp/pyperf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,19 @@ add_executable(PyPerf
PyOffsets.cc
PyPerfNativeStackTrace.cc
)
target_link_libraries(PyPerf pthread libunwind-ptrace.a libunwind-x86_64.a libunwind.a lzma)
target_link_libraries(PyPerf pthread libunwind-ptrace.a)

execute_process(COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE)

if(${ARCHITECTURE} STREQUAL "x86_64")
target_link_libraries(PyPerf libunwind-x86_64.a)
elseif(${ARCHITECTURE} STREQUAL "aarch64")
target_link_libraries(PyPerf libunwind-aarch64.a)
endif()
target_link_libraries(PyPerf libunwind.a) # this one is needed after the x86_64/aarch64 link

target_link_libraries(PyPerf lzma)

if(NOT CMAKE_USE_LIBBPF_PACKAGE)
target_link_libraries(PyPerf bcc-static)
else()
Expand Down
209 changes: 208 additions & 1 deletion examples/cpp/pyperf/PyOffsets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ There are a couple of exceptions:
3. PyThreadState.thread - this field's name is "thread_id" in some Python versions.
*/

#if defined(__x86_64__)
extern const struct struct_offsets kPy27OffsetConfig = {
.PyObject = {
.ob_type = 8
Expand Down Expand Up @@ -229,13 +230,219 @@ extern const struct struct_offsets kPy310OffsetConfig = {
},
};

#elif defined(__aarch64__)

extern const struct struct_offsets kPy27OffsetConfig = {
.PyObject = {
.ob_type = 8
},
.String = {
.data = 36, // offsetof(PyStringObject, ob_sval)
.size = 16, // offsetof(PyVarObject, ob_size)
},
.PyTypeObject = {
.tp_name = 24
},
.PyThreadState = {
.next = 0,
.interp = 8,
.frame = 16,
.thread = 144,
},
.PyInterpreterState = {
.tstate_head = 8,
},
.PyRuntimeState = {
.interp_main = -1, // N/A
},
.PyFrameObject = {
.f_back = 24,
.f_code = 32,
.f_lineno = 124,
.f_localsplus = 376,
},
.PyCodeObject = {
.co_filename = 80,
.co_name = 88,
.co_varnames = 56,
.co_firstlineno = 96,
},
.PyTupleObject = {
.ob_item = 24
},
};

extern const struct struct_offsets kPy36OffsetConfig = {
.PyObject = {
.ob_type = 8
},
.String = {
.data = 48, // offsetof(PyStringObject, ob_sval)
.size = 16, // offsetof(PyVarObject, ob_size)
},
.PyTypeObject = {
.tp_name = 24
},
.PyThreadState = {
.next = 8,
.interp = 16,
.frame = 24,
.thread = 152,
},
.PyInterpreterState = {
.tstate_head = 8,
},
.PyRuntimeState = {
.interp_main = 32,
},
.PyFrameObject = {
.f_back = 24,
.f_code = 32,
.f_lineno = 124,
.f_localsplus = 376,
},
.PyCodeObject = {
.co_filename = 96,
.co_name = 104,
.co_varnames = 64,
.co_firstlineno = 36,
},
.PyTupleObject = {
.ob_item = 24
},
};

extern const struct struct_offsets kPy37OffsetConfig = {
.PyObject = {
.ob_type = 8
},
.String = {
.data = 48, // offsetof(PyStringObject, ob_sval)
.size = 16, // offsetof(PyVarObject, ob_size)
},
.PyTypeObject = {
.tp_name = 24
},
.PyThreadState = {
.next = 8,
.interp = 16,
.frame = 24,
.thread = 176,
},
.PyInterpreterState = {
.tstate_head = 8,
},
.PyRuntimeState = {
.interp_main = 32,
},
.PyFrameObject = {
.f_back = 24,
.f_code = 32,
.f_lineno = 108,
.f_localsplus = 360,
},
.PyCodeObject = {
.co_filename = 96,
.co_name = 104,
.co_varnames = 64,
.co_firstlineno = 36,
},
.PyTupleObject = {
.ob_item = 24
},
};

extern const struct struct_offsets kPy38OffsetConfig = {
.PyObject = {
.ob_type = 8
},
.String = {
.data = 48, // offsetof(PyStringObject, ob_sval)
.size = 16, // offsetof(PyVarObject, ob_size)
},
.PyTypeObject = {
.tp_name = 24
},
.PyThreadState = {
.next = 8,
.interp = 16,
.frame = 24,
.thread = 176,
},
.PyInterpreterState = {
.tstate_head = 8,
},
.PyRuntimeState = {
.interp_main = 40, // N/A
},
.PyFrameObject = {
.f_back = 24,
.f_code = 32,
.f_lineno = 108,
.f_localsplus = 360,
},
.PyCodeObject = {
.co_filename = 104,
.co_name = 112,
.co_varnames = 72,
.co_firstlineno = 40,
},
.PyTupleObject = {
.ob_item = 24
},
};

extern const struct struct_offsets kPy310OffsetConfig = {
.PyObject = {
.ob_type = 8
},
.String = {
.data = 48, // offsetof(PyStringObject, ob_sval)
.size = 16, // offsetof(PyVarObject, ob_size)
},
.PyTypeObject = {
.tp_name = 24
},
.PyThreadState = {
.next = 8,
.interp = 16,
.frame = 24,
.thread = 176,
},
.PyInterpreterState = {
.tstate_head = 8,
},
.PyRuntimeState = {
.interp_main = 40,
},
.PyFrameObject = {
.f_back = 24,
.f_code = 32,
.f_lineno = 100,
.f_localsplus = 352,
},
.PyCodeObject = {
.co_filename = 104,
.co_name = 112,
.co_varnames = 72,
.co_firstlineno = 40,
},
.PyTupleObject = {
.ob_item = 24
},
};

#else
#error unknown arch
#endif

// List of mappings from Python 3 minor versions to offsets. `get_offsets` depends on this list
// being sorted in ascending order when it searches through it.
const std::vector<std::pair<version, struct_offsets>> python3Versions = {
{{3,6,0}, kPy36OffsetConfig},
{{3,7,0}, kPy37OffsetConfig},
{{3,8,0}, kPy38OffsetConfig},
// 3.9 is same as 3.8
// 3.9 is same as 3.8 (on both x86_64 and Aarch64)
{{3,10,0}, kPy310OffsetConfig},
};

Expand Down
Loading