Article View: comp.unix.programmer
Article #3544Re: g++: Shared library, mapfiles, execution speed
From: Greg Menke
Date: Fri, 14 Mar 2003 02:14
Date: Fri, 14 Mar 2003 02:14
50 lines
3576 bytes
3576 bytes
Fred Ma <fma@doe.carleton.ca> writes:
> My question is: is execution speed or optimizability
> (gcc -O) affected by -shared? I'm not too sure how to
> compare shared vs. nonshared. My experience in the
> past has been just to compile without shared. In that
> case, calling the program is straightforward. Just type
> the name of the executable. With matlab, however, I
> compile it using their compiler (which does alot of other
> things beside just invoking gcc). In particular, they add
> extra switches:
>
> -shared
> -Wl,-M,${MATLAB}/extern/lib/sol2/mexFunction.map
I've not heard of a case where there is any significant difference
between position independent and non-position independent. I suspect
most code ends up compiled independent in any case. Perhaps it could
change something in how registers are allocated, but that would be
something highly architecture specific.
static vs shared is used to create either a dynamically or statically
linked library. A static library ends up being an archive of .o files
that are included in a executable when its linked, whereas a
dynamically linked library can be attached to an executable at
runtime. Optimization is not affected because shared/static is more
of a linker issue than a compiler issue. Once the code is in memory
and the fixups applied to all the symbols, there isn't any difference.
When you compile an executable, you're not creating a library, so
shared/static are not applicable.
>
> The -shared is obvious, and the -Wl is for the linker.
> I never used the linker explicitly before, relying on gcc to
> pull it all together. Now, I'm looking at "man ld", which
> is the sunOS5.8 man page, and I'm not sure if it is the same
> one that gcc uses. Is there any reason to think otherwise?
A map file is simply a textual representation of some of addresses &
symbols in the output executable. Perhaps Matlab is reading the map
file to get symbol information or some such. If you're curious about
looking at compiled code, use objdump -dt against your .o file.
Here, ld is not being invoked separately, the -Wl tells gcc to pass
along the following parameter when it invokes ld. You definately
don't want to be playing around with ld until you know you need to.
Gregm
Technical Details
Message-ID:
<m3u1e6g0e1.fsf@europa.pienet>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.uchicago.edu!newsswitch.lcs.mit.edu!newsfeed.mathworks.com!nntp.abs.net!news.abs.net!not-for-mailReferences:
<3E70F170.B4EE8B07@doe.carleton.ca>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,e2dd6c17ce56ca38 X-Google-Attributes: gid11318c,public X-Google-Thread: 106e3f,e2dd6c17ce56ca38 X-Google-Attributes: gid106e3f,public X-Google-Thread: fc89c,e2dd6c17ce56ca38 X-Google-Attributes: gidfc89c,public X-Google-Thread: 11035d,e2dd6c17ce56ca38 X-Google-Attributes: gid11035d,public X-Google-ArrivalTime: 2003-03-13 18:14:32 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.uchicago.edu!newsswitch.lcs.mit.edu!newsfeed.mathworks.com!nntp.abs.net!news.abs.net!not-for-mail Sender: gregm@europa.pienet Newsgroups: comp.unix.programmer,gnu.gcc.help,comp.soft-sys.matlab,comp.unix.solaris Subject: Re: g++: Shared library, mapfiles, execution speed References: <3E70F170.B4EE8B07@doe.carleton.ca> From: Greg Menke <gregm-news@toadmail.com> Message-ID: <m3u1e6g0e1.fsf@europa.pienet> Lines: 50 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: 13 Mar 2003 21:14:30 -0500 NNTP-Posting-Host: 162.33.158.68 X-Complaints-To: abuse@toad.net X-Trace: news.abs.net 1047608071 162.33.158.68 (Thu, 13 Mar 2003 21:14:31 EST) NNTP-Posting-Date: Thu, 13 Mar 2003 21:14:31 EST