From 12ee7a6ad787771ab6848758afd0e41099a2e63c Mon Sep 17 00:00:00 2001 From: Patrick Lipka Date: Mon, 18 Aug 2025 15:41:50 +0200 Subject: [PATCH] adding of interesting symbols only --- src/rvprof_symbols.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/rvprof_symbols.c b/src/rvprof_symbols.c index a597c35..57e0dc6 100644 --- a/src/rvprof_symbols.c +++ b/src/rvprof_symbols.c @@ -25,4 +25,44 @@ static void calculate_base_address(void* known_runtime_addr, uintptr_t known_elf } // compare function for symbol table quicksort -// TODO \ No newline at end of file +static int compare_symbol(const void* a, const void* b){ + const symbol_entry_t* sym_a = (const symbol_entry_t*)a; + const symbol_entry_t* sym_b = (const symbol_entry_t*)b; + + if (sym_a->addr < sym_b->addr) return -1; + if (sym_a->addr > sym_b->addr) return 1; + return 0; +} + +// add symbol to symbol table +static int add_symbol(uintptr_t addr, const char* name, size_t size){ + if (!name || strlen(name) == 0) return 0; + + // skip most internal symbols + if (name[0] == '_' && name[1] == '_'){ + if (strncmp(name, "__cyg_profile", 13) == 0) return 0; + if (strncmp(name, "__libc_", 7) == 0) return 0; + if (strncmp(name, "__gmon_", 7) == 0) return 0; + if (strstr(name, "_start") == NULL && strstr(name, "_init") == NULL && strstr(name, "_fini") == NULL && strstr(name, "main") == NULL) { + return 0; + } + } + + // skip section symbols + if (strstr(name, ".") != NULL) return 0; + // skip versioned symbols + if (strstr(name, "@") != NULL) return 0; + + // add interesting symbols + size_t name_len = strlen(name); + char* tmp_name = rvprof_malloc(name_len+1); + if (!tmp_name) return -1; + strcpy(tmp_name, name); + + g_rvprof.symbols.data[g_rvprof.symbols.size].addr = addr; + g_rvprof.symbols.data[g_rvprof.symbols.size].name = tmp_name; + g_rvprof.symbols.data[g_rvprof.symbols.size].size = size; + g_rvprof.symbols.size++; + + return 0; +} \ No newline at end of file