public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* How to determine if a global symbol is defined in .so and hence  needs to be output to the binary as undefined
@ 2007-09-06 10:42 Mayank Kumar
  2007-09-06 17:05 ` Ian Lance Taylor
  0 siblings, 1 reply; 4+ messages in thread
From: Mayank Kumar @ 2007-09-06 10:42 UTC (permalink / raw)
  To: binutils

Since i didn't get any response I am reframing the question


While porting binutils 2.17  to interix I am facing the following problem.

While creating a binary usinf ld, I want to determine if a symbol is completely defined in another .so and hence needs to be output to a binary as undefined.
What is the best way to achieve this or how is this handled in elf format.


Thanks
Mayank


-----Original Message-----
From: binutils-owner@sourceware.org [mailto:binutils-owner@sourceware.org] On Behalf Of Mayank Kumar
Sent: Wednesday, September 05, 2007 1:05 PM
To: binutils@sources.redhat.com
Subject: Dynamic Linking issue in coff file format

Resending due to no response.

Thanks
Mayank

-----Original Message-----
From: Mayank Kumar
Sent: Friday, August 31, 2007 11:48 AM
To: binutils@sources.redhat.com
Subject: Dynamic Linking issue in coff file format

Hi All
While porting binutils 2.17 to interix, I am facing an issue when linking to libc.so. It is described as follows:-

1: I link a binary with libc.so and that binary accesses a variable from libc.so.

2: Suppose that variable is ___sF, in this case nm output shows me

$ nm binary | grep sF
00046f50 D ___sF

3: This is wrong because the sF is declared in libc.so and hence here it should come as " U ___sF"

4: After debugging inside ld, I see the following:-

        A:coff_link_add_symbols called twice, once for the binary where it reads ___sF as undefined and once for libc.so where it reads ___sF as defined        and adds it to a some symbol table.
        B: _bfd_coff_write_global_sym is called when doing the final linking to write the global symbols. In coff this is handled as , if the output section for a symbol is NULL, then it means that symbol is coming from a .so or is defined there, hence output that symbol as an undefined symbol into the binary.


But in my case, this symbol and infact all symbols(I think data symbols) coming from libc.so get output to the binary as defined since they have an associated output section which is .data.


So my questions are:-
1: How is this case handled in elf and where is the code ?
2: how/where in elf or coff, does the output section for a symbol gets populated and what prevents a global symbol defined in .so to have an output_section.
3: any other thing that you all think I should know to debug and fix this.

Any help/pointers will be appreciated as I am not very familiar with the overall architecture.


Thanks in advance
Mayank

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to determine if a global symbol is defined in .so and hence  needs to be output to the binary as undefined
  2007-09-06 10:42 How to determine if a global symbol is defined in .so and hence needs to be output to the binary as undefined Mayank Kumar
@ 2007-09-06 17:05 ` Ian Lance Taylor
  2007-09-07  4:36   ` Mayank Kumar
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Lance Taylor @ 2007-09-06 17:05 UTC (permalink / raw)
  To: Mayank Kumar; +Cc: binutils

Mayank Kumar <mayank@microsoft.com> writes:

> While creating a binary usinf ld, I want to determine if a symbol is
> completely defined in another .so and hence needs to be output to a
> binary as undefined.  What is the best way to achieve this or how is
> this handled in elf format.

In ELF this is handled in elf_link_output_extsym, in the case for
bfd_link_hash_defined where input_sec->output_section == NULL.

But COFF/PE uses completely different code.  You can't just blindly
copy the ELF code.  You have to understand how the COFF/PE code is
supposed to work.  The approximately equivalent COFF code is
_bfd_coff_write_global_sym.

Ian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: How to determine if a global symbol is defined in .so and hence   needs to be output to the binary as undefined
  2007-09-06 17:05 ` Ian Lance Taylor
@ 2007-09-07  4:36   ` Mayank Kumar
  2007-09-07  5:05     ` Alan Modra
  0 siblings, 1 reply; 4+ messages in thread
From: Mayank Kumar @ 2007-09-07  4:36 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: binutils

Hi Ian
Thanks for the reply. I am not looking forward to copy the code but since I had no clue how this thing work, I was trying to get some help here.
The way you pointed for elf works, its exactly the same way for coff as well. If the output_section is NULL , the symbol is output as undefined into the binary. Now the problem is that in my porting effort, this output_section doesn't come out to be NULL for all defined symbols in the .so and hence it gets output to the binary as defined which is wrong.
        Now I wanted to understand where this output_section gets populated so that I can debug through why this section is not coming to be NULL.
Can you give me some clues ?


Thanks
Mayank


-----Original Message-----
From: Ian Lance Taylor [mailto:iant@google.com]
Sent: Thursday, September 06, 2007 10:35 PM
To: Mayank Kumar
Cc: binutils@sources.redhat.com
Subject: Re: How to determine if a global symbol is defined in .so and hence needs to be output to the binary as undefined

Mayank Kumar <mayank@microsoft.com> writes:

> While creating a binary usinf ld, I want to determine if a symbol is
> completely defined in another .so and hence needs to be output to a
> binary as undefined.  What is the best way to achieve this or how is
> this handled in elf format.

In ELF this is handled in elf_link_output_extsym, in the case for
bfd_link_hash_defined where input_sec->output_section == NULL.

But COFF/PE uses completely different code.  You can't just blindly
copy the ELF code.  You have to understand how the COFF/PE code is
supposed to work.  The approximately equivalent COFF code is
_bfd_coff_write_global_sym.

Ian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to determine if a global symbol is defined in .so and hence   needs to be output to the binary as undefined
  2007-09-07  4:36   ` Mayank Kumar
@ 2007-09-07  5:05     ` Alan Modra
  0 siblings, 0 replies; 4+ messages in thread
From: Alan Modra @ 2007-09-07  5:05 UTC (permalink / raw)
  To: Mayank Kumar; +Cc: binutils

On Fri, Sep 07, 2007 at 12:36:04PM +0800, Mayank Kumar wrote:
>         Now I wanted to understand where this output_section gets populated so that I can debug through why this section is not coming to be NULL.

The ELF linker simply removes all the dynamic sections.  Search for
bfd_section_list_clear in elflink.c

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-09-07  5:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-06 10:42 How to determine if a global symbol is defined in .so and hence needs to be output to the binary as undefined Mayank Kumar
2007-09-06 17:05 ` Ian Lance Taylor
2007-09-07  4:36   ` Mayank Kumar
2007-09-07  5:05     ` Alan Modra

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).