public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* LD: function-level linking
@ 2006-07-10  6:50 Tzu-Chien Chiu
  2006-07-10  8:15 ` Thiemo Seufer
  0 siblings, 1 reply; 7+ messages in thread
From: Tzu-Chien Chiu @ 2006-07-10  6:50 UTC (permalink / raw)
  To: binutils

Hello all.

I'm looking for a similar feature available in Visual C++.
Function-level linking.

In Visual C++, there is an option "/Gy" which enables "function-level
linking". That is, each function is packaged separately as a COMDAT,
and later the linker option "/OPT:REF" eliminates the COMDATs which
are never referenced.

FYI: http://msdn2.microsoft.com/en-us/library/bxwfs976.aspx

In this way, the entire object file won't have to be linked as a whole
when only one of the functions in it is referenced. It's preferred
linking for embedded system software. Not all libraries are design ed
as glibc, which has a separate file for each file, and it's sometimes
not easy or feasible to modify the source code of the libraries.

I can not find similar compiler and linker options in the GNU tool
chain. What I missed?

-- 
Tzu-Chien Chiu - SMedia Technology Corp.
URL: http://www.csie.nctu.edu.tw/~jwchiu/

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

* Re: LD: function-level linking
  2006-07-10  6:50 LD: function-level linking Tzu-Chien Chiu
@ 2006-07-10  8:15 ` Thiemo Seufer
  2006-07-10 14:37   ` Tzu-Chien Chiu
  0 siblings, 1 reply; 7+ messages in thread
From: Thiemo Seufer @ 2006-07-10  8:15 UTC (permalink / raw)
  To: Tzu-Chien Chiu; +Cc: binutils

Tzu-Chien Chiu wrote:
> Hello all.
> 
> I'm looking for a similar feature available in Visual C++.
> Function-level linking.
> 
> In Visual C++, there is an option "/Gy" which enables "function-level
> linking". That is, each function is packaged separately as a COMDAT,
> and later the linker option "/OPT:REF" eliminates the COMDATs which
> are never referenced.
> 
> FYI: http://msdn2.microsoft.com/en-us/library/bxwfs976.aspx
> 
> In this way, the entire object file won't have to be linked as a whole
> when only one of the functions in it is referenced. It's preferred
> linking for embedded system software. Not all libraries are design ed
> as glibc, which has a separate file for each file, and it's sometimes
> not easy or feasible to modify the source code of the libraries.
> 
> I can not find similar compiler and linker options in the GNU tool
> chain. What I missed?

There's gcc's -ffunction-sections, and ld's -Wl,--gc-sections.


Thiemo

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

* Re: LD: function-level linking
  2006-07-10  8:15 ` Thiemo Seufer
@ 2006-07-10 14:37   ` Tzu-Chien Chiu
  2006-07-10 14:44     ` Thiemo Seufer
  2006-07-10 16:49     ` Ian Lance Taylor
  0 siblings, 2 replies; 7+ messages in thread
From: Tzu-Chien Chiu @ 2006-07-10 14:37 UTC (permalink / raw)
  To: Thiemo Seufer; +Cc: binutils

I got a warning from ld: "gc-sections option ignored."

The compilation command:
[quote]
or32-elf-gcc -o a.o -c -ffunction-sections -fdata-sections a.c
[/quote]

The link command is:
[quote]
or32-elf-gcc -o program a.o b.o c.o -lfoo -Wl,-gc-sections, -Wl,-static
[/quote]

I've check the object files by objdump, and each function was in its
own section (.text.function name), so I'm probably sure that the
compiler did the correct job.

According to LD manual (2.16.x):

[quote]
--no-gc-sections
--gc-sections
    Enable garbage collection of unused input sections. It is ignored
on targets that do not support this option.
[/quote]

I'm using a cross gnu-tool-chain, it may not be very well ported. What
should I check if the target (or the toolchain) support this option.

Thank you.



2006/7/10, Thiemo Seufer <ths@networkno.de>:
> Tzu-Chien Chiu wrote:
> > Hello all.
> >
> > I'm looking for a similar feature available in Visual C++.
> > Function-level linking.
> >
> > In Visual C++, there is an option "/Gy" which enables "function-level
> > linking". That is, each function is packaged separately as a COMDAT,
> > and later the linker option "/OPT:REF" eliminates the COMDATs which
> > are never referenced.
> >
> > FYI: http://msdn2.microsoft.com/en-us/library/bxwfs976.aspx
> >
> > In this way, the entire object file won't have to be linked as a whole
> > when only one of the functions in it is referenced. It's preferred
> > linking for embedded system software. Not all libraries are design ed
> > as glibc, which has a separate file for each file, and it's sometimes
> > not easy or feasible to modify the source code of the libraries.
> >
> > I can not find similar compiler and linker options in the GNU tool
> > chain. What I missed?
>
> There's gcc's -ffunction-sections, and ld's -Wl,--gc-sections.
>
>
> Thiemo
>


-- 
Tzu-Chien Chiu - SMedia Technology Corp.
URL: http://www.csie.nctu.edu.tw/~jwchiu/

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

* Re: LD: function-level linking
  2006-07-10 14:37   ` Tzu-Chien Chiu
@ 2006-07-10 14:44     ` Thiemo Seufer
  2006-07-10 14:49       ` Tzu-Chien Chiu
  2006-07-10 16:49     ` Ian Lance Taylor
  1 sibling, 1 reply; 7+ messages in thread
From: Thiemo Seufer @ 2006-07-10 14:44 UTC (permalink / raw)
  To: Tzu-Chien Chiu; +Cc: binutils

Tzu-Chien Chiu wrote:
> I got a warning from ld: "gc-sections option ignored."
> 
> The compilation command:
> [quote]
> or32-elf-gcc -o a.o -c -ffunction-sections -fdata-sections a.c
> [/quote]
> 
> The link command is:
> [quote]
> or32-elf-gcc -o program a.o b.o c.o -lfoo -Wl,-gc-sections, -Wl,-static
> [/quote]

You missed the second dash in front of --gc-sections.


Thiemo

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

* Re: LD: function-level linking
  2006-07-10 14:44     ` Thiemo Seufer
@ 2006-07-10 14:49       ` Tzu-Chien Chiu
  2006-07-10 14:53         ` Tzu-Chien Chiu
  0 siblings, 1 reply; 7+ messages in thread
From: Tzu-Chien Chiu @ 2006-07-10 14:49 UTC (permalink / raw)
  To: Thiemo Seufer; +Cc: binutils

According to the manual at:

http://sourceware.org/binutils/docs-2.16/ld/Options.html#Options

[quote]
For options whose names are multiple letters, either one dash or two
can precede the option name; ...
[/quote]

By the way, I tested both (one and two dashes), ld complained both anway.


2006/7/10, Thiemo Seufer <ths@networkno.de>:
> Tzu-Chien Chiu wrote:
> > I got a warning from ld: "gc-sections option ignored."
> >
> > The compilation command:
> > [quote]
> > or32-elf-gcc -o a.o -c -ffunction-sections -fdata-sections a.c
> > [/quote]
> >
> > The link command is:
> > [quote]
> > or32-elf-gcc -o program a.o b.o c.o -lfoo -Wl,-gc-sections, -Wl,-static
> > [/quote]
>
> You missed the second dash in front of --gc-sections.
>
>
> Thiemo
>


-- 
Tzu-Chien Chiu - SMedia Technology Corp.
URL: http://www.csie.nctu.edu.tw/~jwchiu/

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

* Re: LD: function-level linking
  2006-07-10 14:49       ` Tzu-Chien Chiu
@ 2006-07-10 14:53         ` Tzu-Chien Chiu
  0 siblings, 0 replies; 7+ messages in thread
From: Tzu-Chien Chiu @ 2006-07-10 14:53 UTC (permalink / raw)
  To: Thiemo Seufer; +Cc: binutils

I didn't port that binutils, and I'm neither a bintuil port expert,
but probably I should check some files in binutils to see if this port
_support_ GC sections?

The obj format is ELF.


FYI:
I'm using OpenRISC tool-chain, an open source RISC CPU.
http://www.opencores.org/pnews.cgi/list/or1k?no_loop=yes


2006/7/10, Tzu-Chien Chiu <tzuchien.chiu@gmail.com>:
> According to the manual at:
>
> http://sourceware.org/binutils/docs-2.16/ld/Options.html#Options
>
> [quote]
> For options whose names are multiple letters, either one dash or two
> can precede the option name; ...
> [/quote]
>
> By the way, I tested both (one and two dashes), ld complained both anway.
>
>
> 2006/7/10, Thiemo Seufer <ths@networkno.de>:
> > Tzu-Chien Chiu wrote:
> > > I got a warning from ld: "gc-sections option ignored."
> > >
> > > The compilation command:
> > > [quote]
> > > or32-elf-gcc -o a.o -c -ffunction-sections -fdata-sections a.c
> > > [/quote]
> > >
> > > The link command is:
> > > [quote]
> > > or32-elf-gcc -o program a.o b.o c.o -lfoo -Wl,-gc-sections, -Wl,-static
> > > [/quote]
> >
> > You missed the second dash in front of --gc-sections.
> >
> >
> > Thiemo
> >
>
>
> --
> Tzu-Chien Chiu - SMedia Technology Corp.
> URL: http://www.csie.nctu.edu.tw/~jwchiu/
>


-- 
Tzu-Chien Chiu - SMedia Technology Corp.
URL: http://www.csie.nctu.edu.tw/~jwchiu/

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

* Re: LD: function-level linking
  2006-07-10 14:37   ` Tzu-Chien Chiu
  2006-07-10 14:44     ` Thiemo Seufer
@ 2006-07-10 16:49     ` Ian Lance Taylor
  1 sibling, 0 replies; 7+ messages in thread
From: Ian Lance Taylor @ 2006-07-10 16:49 UTC (permalink / raw)
  To: Tzu-Chien Chiu; +Cc: binutils

"Tzu-Chien Chiu" <tzuchien.chiu@gmail.com> writes:

> I got a warning from ld: "gc-sections option ignored."

That means that your specific backend does not have support for
gc-sections.

> or32-elf-gcc -o a.o -c -ffunction-sections -fdata-sections a.c

You need to add gc_mark_hook and gc_sweep_hook functions to
bfd/elf32-or32.c.

Ian

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

end of thread, other threads:[~2006-07-10 16:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-10  6:50 LD: function-level linking Tzu-Chien Chiu
2006-07-10  8:15 ` Thiemo Seufer
2006-07-10 14:37   ` Tzu-Chien Chiu
2006-07-10 14:44     ` Thiemo Seufer
2006-07-10 14:49       ` Tzu-Chien Chiu
2006-07-10 14:53         ` Tzu-Chien Chiu
2006-07-10 16:49     ` 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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).