* [OT] Prevent linker from unnecessary symbol resolution
@ 2004-05-10 13:59 Srikanth Madani
2004-05-10 17:17 ` Ian Lance Taylor
0 siblings, 1 reply; 3+ messages in thread
From: Srikanth Madani @ 2004-05-10 13:59 UTC (permalink / raw)
To: gcc-help mailing list
Hi,
Suppose I have a C file fun1.c containing two functions:
__________
void func1() {
printf("\nIn function func1()\n");
}
void func2() {
func3();
}
___________
and another called hello.c containing:
___________
void main() {
func1();
}
___________
Is it possible to create a staticly linked binary using just these two
source files? Or do I have to provide a function definition for func3(),
even though it is not called.
Cheers,
Srikanth Madani
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [OT] Prevent linker from unnecessary symbol resolution
2004-05-10 13:59 [OT] Prevent linker from unnecessary symbol resolution Srikanth Madani
@ 2004-05-10 17:17 ` Ian Lance Taylor
2004-05-11 19:41 ` Srikanth Madani
0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2004-05-10 17:17 UTC (permalink / raw)
To: Srikanth Madani; +Cc: gcc-help mailing list
Srikanth Madani <srikanth.madani@vodafone.com> writes:
> Suppose I have a C file fun1.c containing two functions:
>
> __________
> void func1() {
> printf("\nIn function func1()\n");
> }
> void func2() {
> func3();
> }
> ___________
>
> and another called hello.c containing:
>
> ___________
> void main() {
> func1();
> }
> ___________
>
> Is it possible to create a staticly linked binary using just these two
> source files? Or do I have to provide a function definition for func3(),
> even though it is not called.
You have to define func3. You could do it on the linker command line
using something along the lines of '-Wl,--defsym,func3=0'.
If you compile with -ffunction-sections and link with --gc-sections,
you might get away with not defining func3. I haven't tried it,
though, and it would be inherently system dependent.
Ian
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [OT] Prevent linker from unnecessary symbol resolution
2004-05-10 17:17 ` Ian Lance Taylor
@ 2004-05-11 19:41 ` Srikanth Madani
0 siblings, 0 replies; 3+ messages in thread
From: Srikanth Madani @ 2004-05-11 19:41 UTC (permalink / raw)
To: Ian Lance Taylor; +Cc: gcc-help mailing list
Thanks for the response Ian.
So, the conclusion is that my binary is stuck with unnecessary relocatable
code (of a function func3() which main() doesn't call).
Of course, I don't call func2() either, but I can accept that - as it is
defined within an object file which I use (fun1.o)
My interest in all this is to remove unused functions, and thus reduce the
size of my final binary.
I did find another thread on this list which dealt with removing dead code.
Here's the Google cache :
http://66.102.11.104/search?q=cache:5y73E-67cZAJ:gcc.gnu.org/ml/gcc-help/200
3-08/msg00128.html++site:gcc.gnu.org+removing+dead+code&hl=en
I'm not sure I can do this under Solaris though - I will post an update if I
manage it.
Best regards,
Srikanth Madani
ps: Here's the entire scenario - if someone wishes to recreate it.
[181]> \ls *.c
fun1.c fun2.c hello.c
[182]> cat fun1.c
void func1() {
printf("\nIn function func1()\n");
}
void func2() {
func3();
}
[183]> cat fun2.c
void func3() {
printf("\nIn function func3()\n");
}
[184]> cat hello.c
void main() {
func1();
}
[185]> cc hello.c fun1.c
hello.c:
fun1.c:
Undefined first referenced
symbol in file
func3 fun1.o
ld: fatal: Symbol referencing errors. No output written to a.out
And if I use fun2.c as well - then all goes well.
[186]> cc hello.c fun1.c fun2.c
hello.c:
fun1.c:
fun2.c:
[187]> \ls a.out
a.out
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-05-11 19:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-10 13:59 [OT] Prevent linker from unnecessary symbol resolution Srikanth Madani
2004-05-10 17:17 ` Ian Lance Taylor
2004-05-11 19:41 ` Srikanth Madani
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).