Add base address calculation

This commit is contained in:
Patrick Lipka 2025-08-18 14:13:01 +02:00
parent a0b3af9c40
commit 659a872024
1 changed files with 28 additions and 0 deletions

28
src/rvprof_symbols.c Normal file
View File

@ -0,0 +1,28 @@
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <elf.h>
#include <ctype.h>
#include "rvprof_internal.h"
// thread-local storage for function names
__thread char g_tmp_func_name[128];
// base offset for PIE
static uintptr_t g_base_address_offset = 0;
static int g_base_address_calculated = 0;
// base address calculatiion
static void calculate_base_address(void* known_runtime_addr, uintptr_t known_elf_addr){
if (g_base_address_calculated) return;
uintptr_t runtime_addr = (uintptr_t)known_runtime_addr;
if (runtime_addr > known_elf_addr){
g_base_address_offset = runtime_addr - known_elf_addr;
}
g_base_address_calculated = 1;
}
// compare function for symbol table quicksort
// TODO