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
Changes from 18 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
11 changes: 10 additions & 1 deletion examples/cpp/pyperf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -19,7 +19,16 @@ 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 libunwind.a lzma)

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()

if(NOT CMAKE_USE_LIBBPF_PACKAGE)
target_link_libraries(PyPerf bcc-static)
else()
206 changes: 206 additions & 0 deletions examples/cpp/pyperf/PyOffsets.cc
Original file line number Diff line number Diff line change
@@ -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
@@ -229,12 +230,217 @@ 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,
.size = 16,
},
.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,
.size = -1,
},
.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,
.size = -1,
},
.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 kPy310OffsetConfig = {
.PyObject = {
.ob_type = 8
},
.String = {
.data = 48,
.size = -1,
},
.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
},
};

#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},
// TODO check on aarch64
// 3.9 is same as 3.8
{{3,10,0}, kPy310OffsetConfig},
};
Loading