Update the rocprof-sys-rt library (#786)

Derived from Dyninst_RT 13.0.0
This commit is contained in:
David Galiffi
2025-09-03 09:19:43 -04:00
committed by GitHub
parent 2da209da7f
commit a57fd50865
31 changed files with 464 additions and 2574 deletions
@@ -33,9 +33,12 @@
* RTlinux.c: mutatee-side library function specific to Linux
************************************************************************/
#define _GNU_SOURCE
#include "h/dyninstAPI_RT.h"
#include "src/RTcommon.h"
#include "src/RTthread.h"
#include "unaligned_memory_access.h"
#include <assert.h>
#include <errno.h>
#include <stdio.h>
@@ -46,11 +49,8 @@
#endif
#include <errno.h>
#include <gnu/libc-version.h>
#include <link.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/syscall.h>
@@ -114,7 +114,7 @@ t_kill(int pid, int sig)
}
void
DYNINSTbreakPoint()
DYNINSTbreakPoint(void)
{
if(DYNINSTstaticMode) return;
// Call into a funtion that contains a
@@ -131,7 +131,7 @@ uncaught_breakpoint(int sig)
}
void
DYNINSTsafeBreakPoint()
DYNINSTsafeBreakPoint(void)
{
if(DYNINSTstaticMode) return;
@@ -141,7 +141,7 @@ DYNINSTsafeBreakPoint()
}
void
mark_heaps_exec()
mark_heaps_exec(void)
{
/* Grab the page size, to align the heap pointer. */
long int pageSize = sysconf(_SC_PAGESIZE);
@@ -215,7 +215,7 @@ typedef struct dlopen_args
void* (*DYNINST_do_dlopen)(dlopen_args_t*) = NULL;
static int
get_dlopen_error()
get_dlopen_error(void)
{
char* err_str;
err_str = dlerror();
@@ -278,7 +278,7 @@ DYNINSTloadLibrary(char* libname)
#endif
// Define this value so that we can compile on a system that doesn't have
// gettid and still run on one that does.
// gettid and still run on one that does.
#if !defined(SYS_gettid)
# if defined(arch_x86)
@@ -290,7 +290,7 @@ DYNINSTloadLibrary(char* libname)
#endif
int
dyn_lwp_self()
dyn_lwp_self(void)
{
static int gettid_not_valid = 0;
int result;
@@ -307,7 +307,7 @@ dyn_lwp_self()
}
int
dyn_pid_self()
dyn_pid_self(void)
{
return getpid();
}
@@ -315,7 +315,7 @@ dyn_pid_self()
dyntid_t (*DYNINST_pthread_self)(void);
dyntid_t
dyn_pthread_self()
dyn_pthread_self(void)
{
dyntid_t me;
if(DYNINSTstaticMode)
@@ -373,12 +373,10 @@ DYNINST_am_initial_thread(dyntid_t tid)
# elif defined(arch_power)
# if defined(arch_64bit)
# define UC_PC(x) x->uc_mcontext.regs->nip
# else // 32-bit
# define UC_PC(x) x->uc_mcontext.uc_regs->gregs[32]
# endif // power
# elif defined(arch_aarch64)
// #warning "UC_PC: in aarch64, pc is not directly accessable."
// aarch64 pc is not one of 31 GPRs, but an independent reg
// aarch64 pc is not one of 31 GPRs, but an independent reg
# define UC_PC(x) x->uc_mcontext.pc
# endif // UC_PC
@@ -430,8 +428,9 @@ dyninstTrapHandler(int sig, siginfo_t* sg, ucontext_t* context)
struct trap_mapping_header* hdr = getStaticTrapMap((unsigned long) orig_ip);
assert(hdr);
volatile trapMapping_t* mapping = &(hdr->traps[0]);
trap_to = dyninstTrapTranslate(orig_ip, (unsigned long*) &hdr->num_entries, &zero,
&mapping, &one);
trap_to = dyninstTrapTranslate(
orig_ip, CAST_WITHOUT_ALIGNMENT_WARNING(unsigned long*, &hdr->num_entries),
&zero, &mapping, &one);
}
else
{
@@ -445,33 +444,12 @@ dyninstTrapHandler(int sig, siginfo_t* sg, ucontext_t* context)
# if defined(cap_binary_rewriter)
extern struct r_debug _r_debug;
// Remove because of an issue with glibc-2.35+ switching to namespaces.
// Previously there was a dynamic relocation against _r_debug in the loader which
// picked up the interposed definition, but glibc now uses a direct internal hidden
// symbol reference and thus no longer updates the interposed object.
//
// DLLEXPORT struct r_debug _r_debug __attribute__((weak));
/* Verify that the r_debug variable is visible */
void
r_debugCheck()
r_debugCheck(void)
{
# define LIBC_VERSION_BUFFER_LENGTH 1024
char _version_s[LIBC_VERSION_BUFFER_LENGTH];
snprintf(_version_s, LIBC_VERSION_BUFFER_LENGTH, "%s", gnu_get_libc_version());
unsigned long _version[2];
unsigned long idx = 0;
char* token = strtok(_version_s, ".");
while(token != NULL && idx < 2)
{
_version[idx++] = atol(token);
token = strtok(NULL, ".");
}
if(_version[0] < 2 || (_version[0] == 2 && _version[1] < 35))
{
assert(_r_debug.r_map);
}
# undef LIBC_VERSION_BUFFER_LENGTH
assert(_r_debug.r_map);
}
# define NUM_LIBRARIES 512 // Important, max number of rewritten libraries
@@ -494,11 +472,11 @@ static unsigned all_headers_current[NUM_LIBRARIES_BITMASK_SIZE];
static unsigned all_headers_last[NUM_LIBRARIES_BITMASK_SIZE];
static int
parse_libs();
parse_libs(void);
static int
parse_link_map(struct link_map* l);
static void
clear_unloaded_libs();
clear_unloaded_libs(void);
static void
set_bit(unsigned* bit_mask, int bit, char value);
@@ -554,7 +532,7 @@ done:
# if !defined(arch_aarch64)
static int
parse_libs()
parse_libs(void)
{
struct link_map* l_current;
@@ -639,7 +617,7 @@ parse_link_map(struct link_map* l)
}
static void
clear_unloaded_libs()
clear_unloaded_libs(void)
{
unsigned i;
for(i = 0; i < NUM_LIBRARIES_BITMASK_SIZE; i++)
@@ -757,13 +735,13 @@ get_next_set_bitmask(unsigned* bit_mask, int last_pos)
* function runDYNINSTBaseInit(). See DYNINSTglobal_ctors_handler.
*/
extern void
r_debugCheck();
r_debugCheck(void);
extern void
DYNINSTBaseInit();
DYNINSTBaseInit(void);
void
runDYNINSTBaseInit() __attribute__((constructor));
runDYNINSTBaseInit(void) __attribute__((constructor));
void
runDYNINSTBaseInit()
runDYNINSTBaseInit(void)
{
r_debugCheck();
DYNINSTBaseInit();