473,385 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

linker: does it skip unused functions?

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
9 2712
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Sam Smith | last post by:
Hi, I'm thinking about whether or not to build a general library on its own and later link that lib with the main executable, or to build the main executable with a subset of the relevant source...
35
by: Geronimo W. Christ Esq | last post by:
Are there any scripts or tools out there that could look recursively through a group of C/C++ source files, and allow unreferenced function calls or values to be easily identified ? LXR is handy...
12
by: Baloff | last post by:
Hello I have this linker error which makes me think that the definition file is not being seen by the linker, this code is taken from "Thinking in C++, 2nd Edition, Volume 1, Annotated Solutions...
11
by: Michael B Allen | last post by:
Is there a standard method for supressing warnings regarding unused parameters? I have a function that might be called hundreds of thousands of times that looks like this: const void *...
4
by: Roland Zerek | last post by:
Hi, Is there any way to avoid the compiler/linker to optimize one (and only this) class member? Below is the code: <code> class MyFactory { /* . . . */ public static void Register(...
3
by: Steve Baer | last post by:
I recently read your whitepaper under the "extremely long link times" post and have a question that I was hoping you could answer. My question is based on the following paragraph: Directives...
2
by: Oneironaut | last post by:
Hello friends, I have an issue with a linker warning. It is the warning LNK4089. I am working in MSVC6.0 I investigated and this warning tells that the import of the library to which it makes...
10
by: Joris Dolderer | last post by:
Hello, I want to compile and link a program statically against the dietlibc. Of course, the dietlibc includes functions my program never needs. Is there any way to throw them out of the final...
2
by: NvrBst | last post by:
I have C99 code (which I changed extensions to .cpp to compile as C+ +98). Which is does fine. I create a Static Library Project (.lib) and Build, and it builds the .obj files (9 of them) and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.