We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Sorry i just make a mistake to close the issue #2648. The change about this issue is in bellow. Also pull request has been made #2665
diff --git a/src/cc/bcc_elf.c b/src/cc/bcc_elf.c index 584257199d05beb165378dae3151254514a17318..a2aeea7cebba5522952ebad95df5aac25ec1c1f1 100644 --- a/src/cc/bcc_elf.c +++ b/src/cc/bcc_elf.c @@ -738,6 +738,24 @@ int bcc_elf_get_type(const char *path) { return hdr.e_type; } +uint64_t bcc_elf_get_base_address(const char *path) { + Elf *e; + GElf_Phdr phdr; + GElf_Addr base_address; + int fd; + + if (openelf(path, &e, &fd) < 0) + return -1; + + gelf_getphdr(e, 0, &phdr); + + base_address = phdr.p_vaddr-phdr.p_offset; + + elf_end(e); + close(fd); + return base_address; +} + int bcc_elf_is_exe(const char *path) { return (bcc_elf_get_type(path) != -1) && (access(path, X_OK) == 0); } diff --git a/src/cc/bcc_elf.h b/src/cc/bcc_elf.h index b6f5c4313c85cbfc37db3b577e8efa80a09680db..62d5ef7351431883666126e461a7941731f0d238 100644 --- a/src/cc/bcc_elf.h +++ b/src/cc/bcc_elf.h @@ -73,6 +73,7 @@ int bcc_elf_get_text_scn_info(const char *path, uint64_t *addr, uint64_t *offset); int bcc_elf_get_type(const char *path); +uint64_t bcc_elf_get_base_address(const char *path); int bcc_elf_is_shared_obj(const char *path); int bcc_elf_is_exe(const char *path); int bcc_elf_is_vdso(const char *name); diff --git a/src/cc/bcc_syms.cc b/src/cc/bcc_syms.cc index 45d3f2c537a51fbf72467bfe43c37bc56d7ae4da..4970f39d8538cd9a3f0f0ebea96832df556b0977 100644 --- a/src/cc/bcc_syms.cc +++ b/src/cc/bcc_syms.cc @@ -683,7 +683,7 @@ static int _find_sym(const char *symname, uint64_t addr, uint64_t, void *payload) { struct bcc_symbol *sym = (struct bcc_symbol *)payload; if (!strcmp(sym->name, symname)) { - sym->offset = addr; + sym->offset = addr - sym->base_address; return -1; } return 0; @@ -738,6 +738,10 @@ int bcc_resolve_symname(const char *module, const char *symname, sym->name = symname; sym->offset = addr; + + if ((sym->base_address = bcc_elf_get_base_address(sym->module)) < 0) + goto invalid_module; + if (option == NULL) option = &default_option; diff --git a/src/cc/bcc_syms.h b/src/cc/bcc_syms.h index 352d385bdccb270a429f648385993d002955d8a3..0f6bd7cfe88b280d1b547a1758f93a163281999e 100644 --- a/src/cc/bcc_syms.h +++ b/src/cc/bcc_syms.h @@ -29,6 +29,7 @@ struct bcc_symbol { const char *demangle_name; const char *module; uint64_t offset; + uint64_t base_address; }; typedef int (*SYM_CB)(const char *symname, uint64_t addr);
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Sorry i just make a mistake to close the issue #2648.
The change about this issue is in bellow. Also pull request has been made #2665
The text was updated successfully, but these errors were encountered: