* "Create a symbol table"
@ 2001-06-08 19:16 Xinan Tang
2001-06-08 19:58 ` Alan Modra
0 siblings, 1 reply; 7+ messages in thread
From: Xinan Tang @ 2001-06-08 19:16 UTC (permalink / raw)
To: binutils
Hi
I was trying to create a symbol table at the linking time. Here
is what I did:
___________________________________________________________________
#define MY_OBJ "foo_obj.o"
#define MY_SEC "foo_sec"
#define SectionFlags (SEC_HAS_CONTENTS|SEC_ALLOC|SEC_LOAD|SEC_KEEP)
#define SectionSize 4
static bfd *create_dummy_bfd()
{
bfd *abfd;
asection *sec;
{ // Create a bfd
abfd = bfd_openw(MY_OBJ, "elf32-osp192");
bfd_set_format(abfd, bfd_object);
}
{ // Create a section
char *sec_mem;
sec = bfd_make_section_old_way(abfd, MY_SEC);
if (!bfd_set_section_flags(abfd, sec, SectionFlags))
abort();
if (!bfd_set_section_size(abfd, sec, SectionSize))
abort();
if (!bfd_set_section_alignment (abfd, sec, 2))
abort();
sec_mem = (char *) xmalloc(SectionSize);
*((int *) sec_mem) = 0x1234;
if (!bfd_set_section_contents(abfd, sec, sec_mem, 0, SectionSize))
abort();
}
{ //* Create a symbol
asymbol **symtab, *new;
symtab = (asymbol **) xmalloc(2*sizeof(asymbol *));
new = bfd_make_empty_symbol(abfd);
new->name = "foo_symbol";
new->flags = BSF_GLOBAL | BSF_DEBUGGING;
new->value = 0xFFFF;
new->section = sec;
symtab[0] = new;
symtab[1] = NULL;
if (!bfd_set_symtab(abfd, symtab, 1))
abort();
}
if (!bfd_close(abfd))
abort();
__________________________________________________________________
Basically the symbol table has only one symbol, "foo_symbol".
However, once using `objdump' to dump the symbol table, it says
no symbols.
__________________________________________
>./objdump -t foo_obj.o
foo_obj.o: file format elf32-little
./objdump: foo_obj.o: no symbols
_______________________________________
What did go wrong?
Thanks
--
Dr. Xinan Tang Member of Technical Staff
EMail: xinant@cognigine.com Cognigine Corp.
Voice: 510.743.4930 6120 Stevenson Boulevard
Fax: 510.743.4910 Fremont, CA 94538
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: "Create a symbol table"
2001-06-08 19:16 "Create a symbol table" Xinan Tang
@ 2001-06-08 19:58 ` Alan Modra
2001-06-08 20:14 ` Xinan Tang
0 siblings, 1 reply; 7+ messages in thread
From: Alan Modra @ 2001-06-08 19:58 UTC (permalink / raw)
To: Xinan Tang; +Cc: binutils
On Fri, Jun 08, 2001 at 07:16:06PM -0700, Xinan Tang wrote:
>
> Basically the symbol table has only one symbol, "foo_symbol".
> However, once using `objdump' to dump the symbol table, it says
> no symbols.
>
> __________________________________________
> >./objdump -t foo_obj.o
>
> foo_obj.o: file format elf32-little
>
> ./objdump: foo_obj.o: no symbols
> _______________________________________
>
> What did go wrong?
The first entry of a symbol table is reserved.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: "Create a symbol table"
2001-06-08 19:58 ` Alan Modra
@ 2001-06-08 20:14 ` Xinan Tang
2001-06-08 20:38 ` Alan Modra
0 siblings, 1 reply; 7+ messages in thread
From: Xinan Tang @ 2001-06-08 20:14 UTC (permalink / raw)
To: Alan Modra; +Cc: binutils
Hi Alan,
Alan Modra wrote:
> On Fri, Jun 08, 2001 at 07:16:06PM -0700, Xinan Tang wrote:
>
>> Basically the symbol table has only one symbol, "foo_symbol".
>> However, once using `objdump' to dump the symbol table, it says
>> no symbols.
>>
>> __________________________________________
>>
>>> ./objdump -t foo_obj.o
>>
>> foo_obj.o: file format elf32-little
>>
>> ./objdump: foo_obj.o: no symbols
>> _______________________________________
>>
>> What did go wrong?
>
>
> The first entry of a symbol table is reserved.
The problem is NO symbol at all in the dumped .o file.
If you trace objdump' execution, you will find out that
the 'bfd->flags' is 0x0 is the problem.
Therefore, using bfd_set_symtab() alone to set the symbol table
is not enough. What else do we need to do?
Thanks
--
Dr. Xinan Tang Member of Technical Staff
EMail: xinant@cognigine.com Cognigine Corp.
Voice: 510.743.4930 6120 Stevenson Boulevard
Fax: 510.743.4910 Fremont, CA 94538
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: "Create a symbol table"
2001-06-08 20:14 ` Xinan Tang
@ 2001-06-08 20:38 ` Alan Modra
2001-06-08 20:42 ` DJ Delorie
2001-06-09 9:49 ` Xinan Tang
0 siblings, 2 replies; 7+ messages in thread
From: Alan Modra @ 2001-06-08 20:38 UTC (permalink / raw)
To: Xinan Tang; +Cc: binutils
On Fri, Jun 08, 2001 at 08:14:08PM -0700, Xinan Tang wrote:
>
> Therefore, using bfd_set_symtab() alone to set the symbol table
> is not enough. What else do we need to do?
I don't think I had enough coffee this morning. The comment about
the first entry of a symbol table has nothing to do with the
problem. :-( I think your problem is calling bfd_set_section_contents
too early. That function should only be called after you have finished
making changes to the bfd, as it fixes section offsets in the file, and
writes out the symbol table.
Alan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: "Create a symbol table"
2001-06-08 20:38 ` Alan Modra
@ 2001-06-08 20:42 ` DJ Delorie
2001-06-09 12:14 ` Xinan Tang
2001-06-09 9:49 ` Xinan Tang
1 sibling, 1 reply; 7+ messages in thread
From: DJ Delorie @ 2001-06-08 20:42 UTC (permalink / raw)
To: amodra; +Cc: xinant, binutils
> I don't think I had enough coffee this morning. The comment about
> the first entry of a symbol table has nothing to do with the
> problem. :-( I think your problem is calling bfd_set_section_contents
> too early. That function should only be called after you have finished
> making changes to the bfd, as it fixes section offsets in the file, and
> writes out the symbol table.
It's complicated by the use of bfd_make_writable(), which switches the
bfd from file-based to memory-based. The only thing you really should
do with such a bfd is later call bfd_make_readable and hand it back to
the program as if it were reading a file off disk.
PE uses this technique to create archives corresponding to DLLs you
attempt to "link" against.
/*
FUNCTION
bfd_make_writable
SYNOPSIS
boolean bfd_make_writable(bfd *abfd);
DESCRIPTION
Takes a BFD as created by <<bfd_create>> and converts it
into one like as returned by <<bfd_openw>>. It does this
by converting the BFD to BFD_IN_MEMORY. It's assumed that
you will call <<bfd_make_readable>> on this bfd later.
RETURNS
<<true>> is returned if all is ok, otherwise <<false>>.
*/
/*
FUNCTION
bfd_make_readable
SYNOPSIS
boolean bfd_make_readable(bfd *abfd);
DESCRIPTION
Takes a BFD as created by <<bfd_create>> and
<<bfd_make_writable>> and converts it into one like as
returned by <<bfd_openr>>. It does this by writing the
contents out to the memory buffer, then reversing the
direction.
RETURNS
<<true>> is returned if all is ok, otherwise <<false>>. */
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: "Create a symbol table"
2001-06-08 20:38 ` Alan Modra
2001-06-08 20:42 ` DJ Delorie
@ 2001-06-09 9:49 ` Xinan Tang
1 sibling, 0 replies; 7+ messages in thread
From: Xinan Tang @ 2001-06-09 9:49 UTC (permalink / raw)
To: Alan Modra; +Cc: binutils
Hi Alan,
Alan Modra wrote:
> I don't think I had enough coffee this morning. The comment about
> the first entry of a symbol table has nothing to do with the
> problem. :-( I think your problem is calling bfd_set_section_contents
> too early. That function should only be called after you have finished
> making changes to the bfd, as it fixes section offsets in the file, and
> writes out the symbol table.
>
> Alan
I see. I will try this order then.
bfd_set_symtab() ;
bfd_set_section_contents();
Thanks
--
Dr. Xinan Tang Member of Technical Staff
EMail: xinant@cognigine.com Cognigine Corp.
Voice: 510.743.4930 6120 Stevenson Boulevard
Fax: 510.743.4910 Fremont, CA 94538
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: "Create a symbol table"
2001-06-08 20:42 ` DJ Delorie
@ 2001-06-09 12:14 ` Xinan Tang
0 siblings, 0 replies; 7+ messages in thread
From: Xinan Tang @ 2001-06-09 12:14 UTC (permalink / raw)
To: DJ Delorie; +Cc: amodra, binutils
Hi DJ,
DJ Delorie wrote:
>
>
> It's complicated by the use of bfd_make_writable(), which switches the
> bfd from file-based to memory-based. The only thing you really should
> do with such a bfd is later call bfd_make_readable and hand it back to
> the program as if it were reading a file off disk.
>
> PE uses this technique to create archives corresponding to DLLs you
> attempt to "link" against.
>
I found out that the correct order to create a bfd is as follows:
1: abfd = bfd_openw();
2: bfd_set_symtab();
3: bfd_set_section_contents();
However, I cannot make bfd_make_writable() work. If I replace
bfd_openw() with
1_1: abfd = bfd_create();
1_2: bfd_make_writable(abfd);
2: bfd_set_symtab();
3: bfd_set_section_contents();
The last call will generate the segmentation fault error.
I tried to emulate what make_one() in pe-dll.c does. But not successfull.
One question, what is difference between using
bfd_set_section_contents() and using a series of bfd_put_XX()?
I noticed that in pe-dll.c, both are used.
Thanks
--
Dr. Xinan Tang Member of Technical Staff
EMail: xinant@cognigine.com Cognigine Corp.
Voice: 510.743.4930 6120 Stevenson Boulevard
Fax: 510.743.4910 Fremont, CA 94538
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2001-06-09 12:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-08 19:16 "Create a symbol table" Xinan Tang
2001-06-08 19:58 ` Alan Modra
2001-06-08 20:14 ` Xinan Tang
2001-06-08 20:38 ` Alan Modra
2001-06-08 20:42 ` DJ Delorie
2001-06-09 12:14 ` Xinan Tang
2001-06-09 9:49 ` Xinan Tang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).