Article View: comp.unix.programmer
Article #3503Re: How to eliminate unnecessary shared libraries from binary?
From: Frank Cusack
Date: Tue, 01 Feb 2005 18:54
Date: Tue, 01 Feb 2005 18:54
36 lines
2896 bytes
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
Technical Details
Message-ID:
<x5yk6psxgab.fsf@mother.corp.google.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!nntp.speakeasy.net!news.speakeasy.net.POSTED!not-for-mailReferences:
<ctkccr$sqg$1@netnews.hinet.net>Show Full Headers
Complete Article Headers
X-Google-Thread: fc89c,64066ebea43813ab X-Google-Thread: 11318c,64066ebea43813ab X-Google-Attributes: gidfc89c,gid11318c,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!nntp.speakeasy.net!news.speakeasy.net.POSTED!not-for-mail NNTP-Posting-Date: Tue, 01 Feb 2005 12:54:08 -0600 Mail-Copies-To: never From: Frank Cusack <fcusack@fcusack.com> Newsgroups: comp.unix.programmer,gnu.gcc.help Subject: Re: How to eliminate unnecessary shared libraries from binary? Date: Tue, 01 Feb 2005 10:54:04 -0800 Message-ID: <x5yk6psxgab.fsf@mother.corp.google.com> User-Agent: Gnus/5.090018 (Oort Gnus v0.18) Emacs/21.2 (gnu/linux) References: <ctkccr$sqg$1@netnews.hinet.net> Cancel-Lock: sha1:LrIil107adzingPTJ1GKLFMi5Pc= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Lines: 36 NNTP-Posting-Host: 216.239.45.4 X-Trace: sv3-zDvIgEI76N0jN3jUzQYM+b0VED2jH7c3H6Q3IOu03r1LheR4Jr1ITd3qZsKWkM1cVgPwCgo30K7iW62!HorKyjTKkbXpX+ve2nI1gr1Th4sycykxPXlSAMEcR+6a94Lki/IRkYHZziDbI5Q+ZF5GnYIS77XU!Z2b1qwvyZEAeKko= X-Complaints-To: abuse@speakeasy.net X-DMCA-Complaints-To: abuse@speakeasy.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.22