public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: ld warning (was Optimization, remove unused code from  Image)
@ 2005-01-11 13:59 Eljay Love-Jensen
  0 siblings, 0 replies; 3+ messages in thread
From: Eljay Love-Jensen @ 2005-01-11 13:59 UTC (permalink / raw)
  To: Madani, Srikanth, VF-DE, gcc-help

Hi Srikanth,

 > ld --gc-sections *.o

Don't do that.

Try this instead:
gcc -Wl,--gc-sections *.o

Also note:  --gc-sections doesn't work in some environments.  (Hmmm, I was 
under the vague impression that the gc facility was disabled entirely.  But 
don't quote me on that.)

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: ld warning (was Optimization, remove unused code from  Image)
@ 2005-01-11 15:14 Madani, Srikanth, VF-DE
  0 siblings, 0 replies; 3+ messages in thread
From: Madani, Srikanth, VF-DE @ 2005-01-11 15:14 UTC (permalink / raw)
  To: Eljay Love-Jensen, gcc-help

Eljay Love-Jensen wrote:

> Try this instead:
>gcc -Wl,--gc-sections *.o

>Also note:  --gc-sections doesn't work in some environments.  (Hmmm, I
was 
>under the vague impression that the gc facility was disabled entirely.
But 
>don't quote me on that.)


Thanks, the warning was suppressed. (I also had to link crt* objects)

But my a.out (which runs fine) still has a definition for func3() - the
function which is not referenced by main().

Too bad that the ld man page doesn't specify the hosts on which garbage
collection (--gc-sections) does not work.

Will retry on a Linux machine where everything is GNU, and see if I have
better results there.

Cheers,  
Srikanth Madani

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: ld warning (was Optimization, remove unused code from Image)
@ 2005-01-11 13:48 Madani, Srikanth, VF-DE
  0 siblings, 0 replies; 3+ messages in thread
From: Madani, Srikanth, VF-DE @ 2005-01-11 13:48 UTC (permalink / raw)
  To: Graham Stott, Sriharsha, gcc-help, Labermeier Norbert

Graham Stott wrote:

>It is possible to eliminated unused functions on many but not all
targets
>supported by GCC. 

>Use -ffunction-sections when compling and and --gc-sections when
linking.


I apologise then. I tried to simulate this on SunOS 5.8.
Wonder if someone can help me with an ld warning I encountered which
seems to be the reason for my corrupted executable.


Three C source files:
 
$> cat hello.c
int main(void) {
        printf("\nHello world!\n");
        func1();
        exit(0);
}
$>


$> cat fun1.c
void func1(void) {
        printf("\nIn function func1()\n");
}
void func2(void) {
        func3();
}
$>


$> cat fun2.c
void func3(void) {
        printf("\nIn function func3()\n");
}
$>
 
Compiled with gcc <gcc version 3.3>

$>
$>gcc -ffunction-sections -pedantic-errors -c *.c
$>
 
Linked with ld <GNU ld version 2.11.2 (with BFD 2.11.2)>
 
$> ld --gc-sections *.o
/bin/ld: warning: cannot find entry symbol _start; not setting start
address
$>

 
And my a.out is corrupted:
 
$> file a.out
can't read ELF header
a.out:
$>
 
And dumps core:
 
$> ./a.out
Segmentation fault (core dumped)
$>



Why/how do I have to speficiy the start address?
I did see
http://www.gnu.org/software/binutils/manual/ld-2.9.1/html_node/ld_24.htm
l#SEC24 - am none the wiser.
 
Help!
 
Cheers,
Srikanth Madani

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-01-11 15:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-11 13:59 ld warning (was Optimization, remove unused code from Image) Eljay Love-Jensen
  -- strict thread matches above, loose matches on Subject: below --
2005-01-11 15:14 Madani, Srikanth, VF-DE
2005-01-11 13:48 Madani, Srikanth, VF-DE

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).