🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.unix.programmer
3 messages
3 total messages Started by Dennis Mon, 31 Jan 2005 04:32
How to eliminate unnecessary shared libraries from binary?
#3501
Author: Dennis
Date: Mon, 31 Jan 2005 04:32
17 lines
1579 bytes
Hello all,

    I have several utilities sharing one makefile with common linking flags. 
For example,

            LFLAGS= -lpthread -lm -ljpeg

           (BINPATH)%: %.c
                           $(CC) $(CFLAGS) $(INCLUDE) -o $@ $< -L$(LIBPATH) 
$(LFLAGS)

    The executable is always linked with the 3 shared libraries even if they 
are not necessary which produces the runtime loading error. Is it possible 
for ld smart enough to check the real dependency and linked with them only?

Dennis
 
Re: How to eliminate unnecessary shared libraries from binary?
#3502
Author: Paul Pluzhnikov
Date: Mon, 31 Jan 2005 04:50
39 lines
2293 bytes
"Dennis" <rwlin@avamax.com> writes:

>             LFLAGS= -lpthread -lm -ljpeg
...
>     The executable is always linked with the 3 shared libraries 

This is "as designed".

> even if they are not necessary 

The linker can't know that. Maybe they appear to be unnecessary now,
but are required by something else that the executable will load
later.

> which produces the runtime loading error.

Huh? If at least one of your exes requires all 3 libraries, and if
that exe runs, then all the other exes should run just as well.

> Is it possible for ld smart enough to check the real dependency
> and linked with them only?

Such a linker would be "thinking for you" and doing what it thinks
is right, not what you told it to do.

There is no worse frustration then fighting tools that think they
are smarter then you.

If you don't want extra dependencies, write a correct Makefile.

GNU make (and Sun make, IIRC) has 'target-specific variable values':

   This feature allows you to define different values for the same
   variable, based on the target that `make' is currently building.

Cheers,
-- 
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Re: How to eliminate unnecessary shared libraries from binary?
#3503
Author: Frank Cusack
Date: Tue, 01 Feb 2005 18:54
36 lines
2896 bytes
On Mon, 31 Jan 2005 12:32:25 +0800 "Dennis" <rwlin@avamax.com> wrote:
> Hello all,
>
>     I have several utilities sharing one makefile with common linking flags. 
> For example,
>
>             LFLAGS= -lpthread -lm -ljpeg
>
>            (BINPATH)%: %.c
>                            $(CC) $(CFLAGS) $(INCLUDE) -o $@ $< -L$(LIBPATH) 
> $(LFLAGS)
>
>     The executable is always linked with the 3 shared libraries even if they 
> are not necessary which produces the runtime loading error. Is it possible 
> for ld smart enough to check the real dependency and linked with them only?

As Paul said, your best bet is to write a correct Makefile.

Failing that, Solaris' ld supports '-z ignore' and '-z record'.

     -z ignore | record
           Ignores, or records, dynamic dependencies that are not
           referenced  as  part  of  the  link-edit.  Ignores, or
           records, unreferenced ELF sections from  the  relocat-
           able  objects  input  as  part  of  the  link-edit. By
           default, -z record is in effect.

           An ELF section will be ignored, and hence  eliminated,
           from the output file being generated if it contributes
           to an allocatable segment, if it  provides  no  global
           symbols,  and if no other section from any object that
           contributes to the link-edit makes reference to it.

GNU ld does not have this feature.  I don't know about other ld's.

/fc
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads