Skip to content
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
4 changes: 2 additions & 2 deletions cmake/Findelfutils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ find_package(zstd)
set(CMAKE_FIND_LIBRARY_SUFFIXES ${ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})

set(SHA256_ELF
"616099beae24aba11f9b63d86ca6cc8d566d968b802391334c91df54eab416b4"
"09e2ff033d39baa8b388a2d7fbc5390bfde99ae3b7c67c7daaf7433fbcf0f01e"
CACHE STRING "SHA256 of the elfutils tar")
set(VER_ELF
"0.192"
"0.194"
CACHE STRING "elfutils version")
set(ELFUTILS_PATH ${VENDOR_PATH}/elfutils-${VER_ELF})

Expand Down
43 changes: 43 additions & 0 deletions include/dso_hdr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <array>
#include <cassert>
#include <filesystem>
#include <map>
#include <string>
#include <unordered_map>
Expand Down Expand Up @@ -68,6 +69,32 @@ class DsoStats {
uint64_t _backpopulate_count{0};
};

/**************
* vDSO file *
**************/

class VdsoSnapshot {
public:
VdsoSnapshot();
~VdsoSnapshot();

VdsoSnapshot(const VdsoSnapshot &other) = delete;
VdsoSnapshot &operator=(const VdsoSnapshot &other) = delete;
VdsoSnapshot(VdsoSnapshot &&other) noexcept;
VdsoSnapshot &operator=(VdsoSnapshot &&other) noexcept;

void set(FileInfo info);

[[nodiscard]] bool ready() const;
[[nodiscard]] const FileInfo &info() const;

private:
void reset();

FileInfo _info;
bool _ready{false};
};

/**************
* DSO Header *
**************/
Expand Down Expand Up @@ -112,6 +139,12 @@ class DsoHdr {

/******* MAIN APIS **********/
explicit DsoHdr(std::string_view path_to_proc = "", int dd_profiling_fd = -1);
~DsoHdr() = default;

DsoHdr(const DsoHdr &other) = delete;
DsoHdr &operator=(const DsoHdr &other) = delete;
DsoHdr(DsoHdr &&other) noexcept = default;
DsoHdr &operator=(DsoHdr &&other) noexcept = default;

// Add the element check for overlap and remove them
DsoFindRes insert_erase_overlap(Dso &&dso);
Expand Down Expand Up @@ -214,8 +247,14 @@ class DsoHdr {
FileInfoId_t update_id_from_dso(const Dso &dso);

FileInfoId_t update_id_dd_profiling(const Dso &dso);
FileInfoId_t update_id_vdso(const Dso &dso);

FileInfoId_t update_id_from_path(const Dso &dso);
FileInfo find_vdso_file_info();
bool ensure_vdso_snapshot();
std::optional<std::string>
remap_host_workspace_path(std::string_view original) const;
void init_workspace_remap();

// Unordered map (by pid) of sorted DSOs
DsoPidMap _pid_map;
Expand All @@ -224,10 +263,14 @@ class DsoHdr {
FileInfoVector _file_info_vector;
std::string _path_to_proc; // /proc files can be mounted at various places
// (whole host profiling)
std::string _workspace_host_prefix;
std::string _workspace_container_root;
int _dd_profiling_fd;
// Assumption is that we have a single version of the dd_profiling library
// across all PIDs.
FileInfoId_t _dd_profiling_file_info = k_file_info_undef;
VdsoSnapshot _vdso_snapshot;
FileInfoId_t _vdso_file_info = k_file_info_undef;
};

} // namespace ddprof
18 changes: 18 additions & 0 deletions include/unwind_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,22 @@ void add_virtual_base_frame(UnwindState *us);
void add_error_frame(const Dso *dso, UnwindState *us, ProcessAddress_t pc,
SymbolErrors error_case = SymbolErrors::unknown_mapping);

#if defined(__aarch64__)
inline uint64_t canonicalize_user_address(uint64_t addr) {
// Drop the top byte that may hold a pointer tag (TBI/MTE) before sign
// extension so we can match proc-maps entries.
constexpr unsigned k_top_byte_shift = 56;
constexpr uint64_t top_byte_mask = (uint64_t{1} << k_top_byte_shift) - 1;
addr &= top_byte_mask;

constexpr unsigned canonical_bits = 48;
if (canonical_bits < k_top_byte_shift) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the logic of this function:
this condition is always true, therefore the previous masking operation is unnecessary

addr &= (uint64_t{1} << canonical_bits) - 1;
}
return addr;
}
#else
inline uint64_t canonicalize_user_address(uint64_t addr) { return addr; }
#endif

} // namespace ddprof
Loading