This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: Compile app using the BFD library?
Why does the following give me a seg fault?
It seg faults on bfd_get_symtab_upper_bound(abfd)
print_symbol_table() is modeled after the example in section 2.7 of
the BFDlib manual.
a.out is a simple program compiled with gcc
> gcc hello.c
#include <stdio.h>
#include <stdlib.h>
#include "/home/bblietz/work/binutils-2.14/bfd/bfd.h"
#define FILENAME "/home/bblietz/work/testCode/a.out"
#define TARGET "i686-pc-linux-gnu"
void print_symbol_table(bfd *abfd)
{
long storage_needed;
asymbol **symbol_table;
long number_of_symbols;
long i;
storage_needed = bfd_get_symtab_upper_bound(abfd);
symbol_table = (asymbol **)xmalloc(storage_needed);
number_of_symbols = bfd_canonicalize_symtab(abfd, symbol_table);
for(i = 0; i < number_of_symbols; i++)
{
printf("%s\n", symbol_table[i]->name);
}
}
int main(int argc, char *argv[])
{
bfd *abfd;
bfd_init();
bfd_set_default_target (TARGET);
abfd = bfd_openr(FILENAME, NULL);
printf("abfd: 0x%x\n", abfd);
print_symbol_table(abfd);
}
Daniel Jacobowitz wrote:
On Fri, Feb 06, 2004 at 06:12:44PM -0600, Brian Blietz wrote:
I currently have an app that uses the BFD library.
I am having troubles building the application.
I am using Redhat Fedora, gcc 3.2.3, binutils 2.14
Here is my compile line and the errors that follow
gcc bfd-test.c -lbfd
Also use -liberty.
--
Brian Blietz
bblietz@iastate.edu
"There are 10 types of people in the world...
Those who understand binary, and those who don't."