By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,289 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,289 IT Pros & Developers. It's quick & easy.

linker: does it skip unused functions?

P: n/a
Hi,

if I link my code to other o-files: Does the linker include the whole
o-file or does it use the needed functions from that only?

Felix
Nov 14 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Felix Kater <f.******@gmx.net> scribbled the following:
Hi, if I link my code to other o-files: Does the linker include the whole
o-file or does it use the needed functions from that only?


This is completely dependent on the linker implementation and not
specified by the ISO C standard.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"It's not survival of the fattest, it's survival of the fittest."
- Ludvig von Drake
Nov 14 '05 #2

P: n/a
Felix Kater wrote:
Hi,

if I link my code to other o-files: Does the linker include the whole
o-file or does it use the needed functions from that only?

Felix


Is that a trick question? Is there a _c_ in there somewhere? Oh, there are tree
of them, but none of them is ISO C. All in all, Felix, you're not in the right
NG. I'm going to be exceptionally nice (for this NG's standard) and direct you
to what I believe might be the right NG for this kind of problem: gnu.gcc.help.
Good luck!
Nov 14 '05 #3

P: n/a
Eltee <el***@hotmail.com> scribbled the following:
Felix Kater wrote:
Hi,

if I link my code to other o-files: Does the linker include the whole
o-file or does it use the needed functions from that only?

Felix
Is that a trick question? Is there a _c_ in there somewhere? Oh, there are tree
of them, but none of them is ISO C. All in all, Felix, you're not in the right
NG. I'm going to be exceptionally nice (for this NG's standard) and direct you
to what I believe might be the right NG for this kind of problem: gnu.gcc.help.
Good luck!


What makes you so sure Felix is using GNU GCC?

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"C++ looks like line noise."
- Fred L. Baube III
Nov 14 '05 #4

P: n/a
Joona I Palaste wrote:
Eltee <el***@hotmail.com> scribbled the following:
Felix Kater wrote:
Hi,

if I link my code to other o-files: Does the linker include the whole
o-file or does it use the needed functions from that only?

Felix


Is that a trick question? Is there a _c_ in there somewhere? Oh, there are tree
of them, but none of them is ISO C. All in all, Felix, you're not in the right
NG. I'm going to be exceptionally nice (for this NG's standard) and direct you
to what I believe might be the right NG for this kind of problem: gnu.gcc.help.
Good luck!

What makes you so sure Felix is using GNU GCC?


Call it a hunch. Moreover, had he been using some <alert type="OT"
level="severe" allusion="Gatesware">visual</alert> tool, he wouldn't have run
into such a problem 'cause the IDE does that behind the scenes.

Besides, I said "what I believe" and "might be".
Nov 14 '05 #5

P: n/a
Felix Kater wrote:
Hi,

if I link my code to other o-files: Does the linker include the whole
o-file or does it use the needed functions from that only?


Your request is not topical in c.l.c; moreover, linkers are
rather complicated pieces of software, so the answer may depend
on the used linker.
You should ask in a newsgroup dedicated to your linker.

<OT>
AFAIK, for most linkers it is an all or nothing decision: If
no symbol from the object file is needed, the linker _may_ be
able to decide to "postpone" the file to the end of the linking.
If still no symbol is needed, it _may_ skip the object file.

The same holds for libraries consisting of multiple object
files: The linker _may_ be able to decide to use only the
necessary object files.

I somehow doubt that most linkers can do more than that.
If your linker can do at least that, you could consider
splitting your modules into as many (or less) files as you
have functions with external linkage and tell the linker
to use only the object files needed.
</OT>

Cheers
Michael
--
E-Mail: Mine is a gmx dot de address.

Nov 14 '05 #6

P: n/a
Michael Mair wrote:
Felix Kater wrote:
Hi,

if I link my code to other o-files: Does the linker include the whole
o-file or does it use the needed functions from that only?

Your request is not topical in c.l.c; moreover, linkers are
rather complicated pieces of software, so the answer may depend
on the used linker.
You should ask in a newsgroup dedicated to your linker.

<OT>
AFAIK, for most linkers it is an all or nothing decision: If
no symbol from the object file is needed, the linker _may_ be
able to decide to "postpone" the file to the end of the linking.
If still no symbol is needed, it _may_ skip the object file.

The same holds for libraries consisting of multiple object
files: The linker _may_ be able to decide to use only the
necessary object files.

I somehow doubt that most linkers can do more than that.
If your linker can do at least that, you could consider
splitting your modules into as many (or less) files as you
have functions with external linkage and tell the linker
to use only the object files needed.
</OT>


Uf! I'm impressed. Might have to re-gauge my clc-meter, too. Seems like it's
possible to get OT explanations in this NG after all. Hm.
Nov 14 '05 #7

P: n/a
Felix Kater wrote:
if I link my code to other o-files:
I'll assume that you mean *.o (object) files which are outputs
from the compilation of individual translation units.
Does the linker include the whole object file?
The typical link editor will load [include]
the entire object file into the executable image
whether or not it resolves any links.
Or does it use the needed functions from that only?


No. The typical link editor loads the entire object file.
Remember that the object file may include global or static
variable or constant definitions which the functions access.

If you want to load functions individually,
you should place them into separate source files
and compile them individually into separate object files
then create a library archive of these object files.
The typical link editor will load only the object files
that it needs to resolve links from this library archive.

The link editor is usually called by your compiler
to create an executable program.
Please tell us which compiler and operating system you are using
so that we can help you locate the appropriate forum
to answer your platform specific questions.
Nov 14 '05 #8

P: n/a
Eltee wrote:
Michael Mair wrote:
Felix Kater wrote:
If I link my code to other o-files:
Does the linker include the whole o-file?
Or does it use the needed functions from that only?


Your request is not topical in c.l.c;
moreover, linkers are rather complicated pieces of software,
so the answer may depend on the used linker.
You should ask in a newsgroup dedicated to your linker.

<OT>
AFAIK, for most linkers it is an all or nothing decision:
If no symbol from the object file is needed,
the linker _may_ be able to decide
to "postpone" the file to the end of the linking.
If still no symbol is needed, it _may_ skip the object file.

The same holds for libraries
consisting of multiple object files:
The linker _may_ be able to decide
to use only the necessary object files.

I somehow doubt that most linkers can do more than that.
If your linker can do at least that, you could consider
splitting your modules into as many (or less) files
as you have functions with external linkage
and tell the linker to use only the object files needed.
</OT>


I'm impressed. Might have to re-gauge my clc-meter, too.
Seems like it's possible to get OT explanations in this NG after all.


Michael Mair's response was appropriate.
These are the rules:

1. Don't respond to off-topic questions.
2. If you feel that you *must* respond,
be polite and try to be helpful.
3. Don't admonish the original poster.
It is sufficient to merely mention that
the question is off-topic in order to prevent
most other subscribers from responding to it.

Off-topic questions should never be used as an excuse
to abuse new subscribers, vent personal frustration
or express hostility. It will not elevate your esteem
among other subscribers.
Nov 14 '05 #9

P: n/a
E. Robert Tisdale wrote:
Off-topic questions should never be used as an excuse
to abuse new subscribers, vent personal frustration
or express hostility. It will not elevate your esteem
among other subscribers.


My esteem. Do you think that's what I'm after?
Nov 14 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.