c - symbol lookup error: ./libobjdata.so: undefined symbol: bfd_map_over_sections -
when compiled getsections_dl.c file, output error, mean have not linked library?
my compile command is:
gcc getsections_dl.c -l. -ldl -lbfd -o getsections_dl
my getsections_dl.c:
#include <stdlib.h> #include <string.h> #include <bfd.h> #include <unistd.h> #include <dlfcn.h> extern void dump_sections(bfd *abfd); #define rdtsc(x) __asm__ __volatile__("rdtsc \n\t" : "=a" (*(x))) // following function tweaked version of itoa functions // can found in either objsym.c or objsect.c char* lltoa(long long int val, int base) { if (val == 0x0) { static char zero[] = "0"; return &zero[0]; } static char buf[64] = {0}; int = 60; for(; val && ; --i, val /= base) buf[i] = "0123456789abcdef"[val % base]; return &buf[i+1]; } int main(int argc, char *argv[]) { bfd *obj; void *handle; unsigned long long start, finish; void (*func)(bfd *); bfd_init(); obj = bfd_openr(argv[1], "elf32-i386"); if (!obj) { bfd_perror("open failure\n"); return 0; } rdtsc(&start); if (!strcmp(argv[2], "rtld_lazy")) handle = dlopen("./libobjdata.so", rtld_lazy); else handle = dlopen("./libobjdata.so", rtld_now); rdtsc(&finish); bfd_check_format(obj, bfd_object); //compute cycles write(1, "time: ", strlen("time: ")); int t = (finish-start)/2793; write(1, lltoa(t, 10), strlen(lltoa(t, 10))); write(1, " cycles/mhz\n\n", strlen(" cycles/mhz\n\n")); func = dlsym(handle, "dump_sections"); // bfd_map_over_sections(obj, func2, null); dump_sections(obj); dlclose(handle); return 0; }
and library c file objsect.c (which objdump() dose):
#include <bfd.h> #include <stdio.h> #include <unistd.h> #include <string.h> void dump_section(bfd *abfd, asection *section, void *obj) { // number of octets per target byte //unsigned int opb = bfd_octets_per_byte(abfd); char* itoa(int val, int base) { if (val == 0x0) { static char zero[] = "0"; return &zero[0]; } static char buf[32] = {0}; int = 30; for(; val && ; --i, val /= base) buf[i] = "0123456789abcdef"[val % base]; return &buf[i+1]; } //write(1, "section:", strlen("section:")); write(1, section->name, strlen(section->name)); write(1, " \t", strlen(" \t")); write(1, itoa(section->vma, 16), strlen(itoa(section->vma, 16))); write(1, " \t", strlen(" \t")); write(1, itoa(section->rawsize, 16), strlen(itoa(section->rawsize, 10))); write(1, " \t", strlen(" \t")); write(1, itoa(section->size, 16), strlen(itoa(section->size, 10))); write(1, " \t", strlen(" \t")); write(1, itoa(section->filepos, 16), strlen(itoa(section->filepos, 16))); write(1, " \n", strlen(" \n")); } void dump_sections(bfd *abfd) { write(1, "name\t", strlen("name\t")); write(1, "size\t", strlen("size\t")); write(1, "vma\tt", strlen("vma\t")); write(1, "lma\t", strlen("lma\t")); write(1, "file off\t", strlen("file off\t")); write(1, "algn\n", strlen("algn\n")); // each section in abfd, call dump_section_headers() bfd_map_over_sections(abfd, dump_section, null); }
Comments
Post a Comment