* BFD question
@ 2004-05-17 19:50 Bloch, Jack
2004-05-17 20:01 ` Ian Lance Taylor
2004-05-17 20:54 ` Bloch, Jack
0 siblings, 2 replies; 4+ messages in thread
From: Bloch, Jack @ 2004-05-17 19:50 UTC (permalink / raw)
To: 'gdb@sources.redhat.com'
Can anyone help. I am writing an application that needs to read symbols from
an executable file.
I am running a stock SuSE 2.4.19 Kernel. I have libbfd version 2.12.90.0.15.
My code reads as follows :
bfd *l_bfd = NULL;
char *l_target = "elf32-i386";
const char *l_err = NULL;
long l_storage = 0;
long l_symnum = 0;
long l_ndx = 0;
int l_dyn = 0;
int l_flags = 0;
int l_access = (EXEC_P | HAS_SYMS);
asymbol **l_symbol = NULL;
if (!p_file)
{ /* invalid file name */
printf("INVALID FILE NAME FOR EXTRACT SYMBOLS !!!\n");
return(-1); /* set error indicator */
}
printf("EXTRACTING SYMBOLS FOR FILE %s\n",p_file);
/*****************/
/* open the file */
/*****************/
if ((l_bfd = bfd_openr(p_file,l_target)) == NULL)
{ /* unable to open file */
l_err = bfd_errmsg(bfd_get_error ()); /* read BFD error */
printf("ERROR %s OPENing FILE %s FOR SYMBOL EXTRACTION
!!!\n",l_err,p_file);
return(-1); /* set error indicator */
}
/***********************************/
/* check the file format to ensure */
/* an executable file. */
/***********************************/
if (!bfd_check_format(l_bfd,bfd_object))
{ /* not an executable file */
l_err = bfd_errmsg(bfd_get_error ()); /* read BFD error */
printf("BFD ERROR %s VALIDATING EXECUTABLE SYMBOL FORMAT ON
%s\n",l_err,p_file);
bfd_close(l_bfd); /* close file */
return(-1); /* set error indicator */
}
/*****************************************************/
/* ensure that the given file has symbols associated */
/* with it. */
/*****************************************************/
l_flags = bfd_get_file_flags(l_bfd);
if ((l_flags & l_access) == 0)
{ /* no symbols associated with this file */
printf("NO SYMBOLIC INFORMATION FOUND FOR %s !!!\n",p_file);
return(-1); /* set error indicator */
}
/******************************************************/
/* determine the amount of memory needed to store the */
/* program symbols. this can be static or dynamic */
/* storage. */
/******************************************************/
l_storage = bfd_get_symtab_upper_bound(l_bfd);
if (l_storage == 0);
{ /* static failed so try dynamic */
printf("RETRIEVING STATIC STORAGE FAILED, TRYING DYNAMIC !!!\n");
l_storage = bfd_get_dynamic_symtab_upper_bound(l_bfd);
if (l_storage == 0);
{ /* cannot retrieve dynamic storage size */
printf("FAILED TO RETRIEVE DYNAMIC STORAGE SIZE !!!\n");
return(-1); /* set eror indicator */
}
}
return(0); /* set success indicator */
The call to bfd_get_file_flags returns a 0. The file is indeed an elf32-i386
target.
Please respond to jack.bloch@icn.siemens.com
Thanks in advance.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: BFD question
2004-05-17 19:50 BFD question Bloch, Jack
@ 2004-05-17 20:01 ` Ian Lance Taylor
2004-05-17 20:54 ` Bloch, Jack
1 sibling, 0 replies; 4+ messages in thread
From: Ian Lance Taylor @ 2004-05-17 20:01 UTC (permalink / raw)
To: Bloch, Jack; +Cc: 'gdb@sources.redhat.com'
"Bloch, Jack" <Jack.Bloch@icn.siemens.com> writes:
> The call to bfd_get_file_flags returns a 0. The file is indeed an elf32-i386
> target.
What does objdump -f return on the file?
Has the file perhaps been stripped?
Ian
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: BFD question
2004-05-17 19:50 BFD question Bloch, Jack
2004-05-17 20:01 ` Ian Lance Taylor
@ 2004-05-17 20:54 ` Bloch, Jack
2004-05-17 21:07 ` Ian Lance Taylor
1 sibling, 1 reply; 4+ messages in thread
From: Bloch, Jack @ 2004-05-17 20:54 UTC (permalink / raw)
To: 'Ian Lance Taylor '; +Cc: ''gdb@sources.redhat.com' '
Here is the output
objdump -f Coregen
Coregen: file format elf32-i386
architecture: i386, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x08048400
This looks good to me.
By the way, I forgot to show in my code listing that p_file is a char *
passed in as a parameter ans is set to "/usr/coretest/Coregen"
-----Original Message-----
From: Ian Lance Taylor
To: Bloch, Jack
Cc: 'gdb@sources.redhat.com'
Sent: 5/17/2004 4:01 PM
Subject: Re: BFD question
"Bloch, Jack" <Jack.Bloch@icn.siemens.com> writes:
> The call to bfd_get_file_flags returns a 0. The file is indeed an
elf32-i386
> target.
What does objdump -f return on the file?
Has the file perhaps been stripped?
Ian
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: BFD question
2004-05-17 20:54 ` Bloch, Jack
@ 2004-05-17 21:07 ` Ian Lance Taylor
0 siblings, 0 replies; 4+ messages in thread
From: Ian Lance Taylor @ 2004-05-17 21:07 UTC (permalink / raw)
To: Bloch, Jack; +Cc: ''gdb@sources.redhat.com' '
"Bloch, Jack" <Jack.Bloch@icn.siemens.com> writes:
> objdump -f Coregen
>
> Coregen: file format elf32-i386
> architecture: i386, flags 0x00000112:
> EXEC_P, HAS_SYMS, D_PAGED
> start address 0x08048400
>
>
> This looks good to me.
>
> By the way, I forgot to show in my code listing that p_file is a char *
> passed in as a parameter ans is set to "/usr/coretest/Coregen"
Well, objdump thinks the value of bfd_get_file_flags is 0x112.
Your code looks OK at a cursory glance. I don't know what the problem
is. Sorry.
Ian
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-05-17 21:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-17 19:50 BFD question Bloch, Jack
2004-05-17 20:01 ` Ian Lance Taylor
2004-05-17 20:54 ` Bloch, Jack
2004-05-17 21:07 ` Ian Lance Taylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox