* RE: ld includes entire archive (.a) when compiling .elf file
@ 2006-03-10 23:08 Josh Keller
2006-03-10 23:43 ` Daniel Jacobowitz
0 siblings, 1 reply; 12+ messages in thread
From: Josh Keller @ 2006-03-10 23:08 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: binutils, Reuben Johnston
How will specifying the start of execution with (-e) remove the uncalled
functions and unused variables? Does the ld linker even have the
capability to automatically remove uncalled functions without having to
specify each used section? I'm sorry if I sound really confused, I'm
pretty new to this. Thanks for your patience.
-Josh
-----Original Message-----
From: Daniel Jacobowitz [mailto:drow@false.org]
Sent: Friday, March 10, 2006 6:02 PM
To: Josh Keller
Cc: binutils@sourceware.org; Reuben Johnston
Subject: Re: ld includes entire archive (.a) when compiling .elf file
On Fri, Mar 10, 2006 at 05:59:32PM -0500, Josh Keller wrote:
> Building with --gc-sections ends up giving me a 0-byte binary. It
> seems to think all my code is garbage (See below) ;) I'm guessing
> that I have to subdivide my code somehow to tell it what to remove,
etc.
>
> I turned on the -f options and got the following error:
> /usr/local/gnu/lib/gcc-lib/arm-elf/3.3/../../../../arm-elf/bin/ld: -f
> may not be used without -shared.
Then obviously you've passed it the wrong options... ah,
-ffunction-sections is not a linker option, it's a compiler option, so
no -Wl.
> Output from my compiler...
>
> arm-elf-gcc Cstartup.o main.o Cstartup_SAM7.o irq.o pio.o
> interrupt_pit.o interrupt_Usart.o --output main.elf -nostartfiles
> -Wl,-Map=main.map,--cref,--gc-sections -Iucos_ii -Lucos_ii -lucos_ii
> -TAT91SAM7S64-ROM.ld
Try using the linker option -e to specify the function at the start of
execution.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: ld includes entire archive (.a) when compiling .elf file
2006-03-10 23:08 ld includes entire archive (.a) when compiling .elf file Josh Keller
@ 2006-03-10 23:43 ` Daniel Jacobowitz
0 siblings, 0 replies; 12+ messages in thread
From: Daniel Jacobowitz @ 2006-03-10 23:43 UTC (permalink / raw)
To: Josh Keller; +Cc: binutils, Reuben Johnston
On Fri, Mar 10, 2006 at 06:08:53PM -0500, Josh Keller wrote:
> How will specifying the start of execution with (-e) remove the uncalled
> functions and unused variables? Does the ld linker even have the
> capability to automatically remove uncalled functions without having to
> specify each used section? I'm sorry if I sound really confused, I'm
> pretty new to this. Thanks for your patience.
No, you need that to prevent the linker from removing everything.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: ld includes entire archive (.a) when compiling .elf file
@ 2006-03-11 1:37 Josh Keller
0 siblings, 0 replies; 12+ messages in thread
From: Josh Keller @ 2006-03-11 1:37 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: binutils, Reuben Johnston
Hehe, yeah, it made an empty binary. I will put in the appropriate switches and post my results.
-Josh
-----Original Message-----
From: Daniel Jacobowitz [mailto:drow@false.org]
Sent: Fri 3/10/2006 6:43 PM
To: Josh Keller
Cc: binutils@sourceware.org; Reuben Johnston
Subject: Re: ld includes entire archive (.a) when compiling .elf file
On Fri, Mar 10, 2006 at 06:08:53PM -0500, Josh Keller wrote:
> How will specifying the start of execution with (-e) remove the uncalled
> functions and unused variables? Does the ld linker even have the
> capability to automatically remove uncalled functions without having to
> specify each used section? I'm sorry if I sound really confused, I'm
> pretty new to this. Thanks for your patience.
No, you need that to prevent the linker from removing everything.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: ld includes entire archive (.a) when compiling .elf file
@ 2006-03-10 23:19 Josh Keller
0 siblings, 0 replies; 12+ messages in thread
From: Josh Keller @ 2006-03-10 23:19 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: binutils, Reuben Johnston
I think this link may help:
http://m68hc11.serveftp.org/faq.php?file=faq/link/gc-1.txt
I will let you know how it works out.
-Josh
Joshua Keller
Key Technologies, Inc.
40 East Cross Street
Baltimore, MD 21230
Phone: 410-385-0200
Fax: 410-385-1114
jkeller@keytechinc.com
www.keytechinc.com
Visit Key Tech at the MD&M East in NYC June 6-8, 2006 - - Booth# 1680
Save $55 on your admission...go to Key Tech at MDM East
-----Original Message-----
From: Daniel Jacobowitz [mailto:drow@false.org]
Sent: Friday, March 10, 2006 6:02 PM
To: Josh Keller
Cc: binutils@sourceware.org; Reuben Johnston
Subject: Re: ld includes entire archive (.a) when compiling .elf file
On Fri, Mar 10, 2006 at 05:59:32PM -0500, Josh Keller wrote:
> Building with --gc-sections ends up giving me a 0-byte binary. It
> seems to think all my code is garbage (See below) ;) I'm guessing
> that I have to subdivide my code somehow to tell it what to remove,
etc.
>
> I turned on the -f options and got the following error:
> /usr/local/gnu/lib/gcc-lib/arm-elf/3.3/../../../../arm-elf/bin/ld: -f
> may not be used without -shared.
Then obviously you've passed it the wrong options... ah,
-ffunction-sections is not a linker option, it's a compiler option, so
no -Wl.
> Output from my compiler...
>
> arm-elf-gcc Cstartup.o main.o Cstartup_SAM7.o irq.o pio.o
> interrupt_pit.o interrupt_Usart.o --output main.elf -nostartfiles
> -Wl,-Map=main.map,--cref,--gc-sections -Iucos_ii -Lucos_ii -lucos_ii
> -TAT91SAM7S64-ROM.ld
Try using the linker option -e to specify the function at the start of
execution.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: ld includes entire archive (.a) when compiling .elf file
@ 2006-03-10 22:59 Josh Keller
2006-03-10 23:02 ` Daniel Jacobowitz
0 siblings, 1 reply; 12+ messages in thread
From: Josh Keller @ 2006-03-10 22:59 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: binutils, Reuben Johnston
Building with --gc-sections ends up giving me a 0-byte binary. It seems
to think all my code is garbage (See below) ;) I'm guessing that I have
to subdivide my code somehow to tell it what to remove, etc.
I turned on the -f options and got the following error:
/usr/local/gnu/lib/gcc-lib/arm-elf/3.3/../../../../arm-elf/bin/ld: -f
may not be used without -shared.
Output from my compiler...
arm-elf-gcc Cstartup.o main.o Cstartup_SAM7.o irq.o pio.o
interrupt_pit.o interrupt_Usart.o --output main.elf -nostartfiles
-Wl,-Map=main.map,--cref,--gc-sections -Iucos_ii -Lucos_ii -lucos_ii
-TAT91SAM7S64-ROM.ld
Size after:
main.elf :
section size addr
.text 0 0
.data 0 2097152
.bss 0 0
.stab 4884 0
.stabstr 33758 0
.debug_aranges 96 0
.debug_pubnames 29 0
.debug_info 2524 0
.debug_abbrev 406 0
.debug_line 467 0
.debug_frame 32 0
.debug_str 1102 0
Total 43298
Joshua Keller
Key Technologies, Inc.
40 East Cross Street
Baltimore, MD 21230
Phone: 410-385-0200
Fax: 410-385-1114
jkeller@keytechinc.com
www.keytechinc.com
Visit Key Tech at the MD&M East in NYC June 6-8, 2006 - - Booth# 1680
Save $55 on your admission...go to Key Tech at MDM East
-----Original Message-----
From: Daniel Jacobowitz [mailto:drow@false.org]
Sent: Friday, March 10, 2006 5:51 PM
To: Josh Keller
Cc: binutils@sourceware.org; Reuben Johnston
Subject: Re: ld includes entire archive (.a) when compiling .elf file
On Fri, Mar 10, 2006 at 05:46:07PM -0500, Josh Keller wrote:
> The map file says the archive member is included. However, I only
> make one call to an empty function (I'm testing to see what's
> included) in my
> main() called OSInitHookEnd (first line listed below). I'm not sure
> why it's pulling in the rest of the libucos_ii.a archive.
> -Josh
>
> The top of the map file is as follows:
Here's what is happening:
> $ more main.map
> Archive member included because of file (symbol)
>
> ucos_ii/libucos_ii.a(os_cpu_c.o)
> main.o (OSInitHookEnd)
main.o includes os_cpu_c.o to define OSInitHookEnd.
> ucos_ii/libucos_ii.a(os_core.o)
> ucos_ii/libucos_ii.a(os_cpu_c.o)
> (OSIntCtxSwFlag)
os_cpu_c.o includes os_core.o to define OSIntCtxSwFlag.
> ucos_ii/libucos_ii.a(os_mem.o)
> ucos_ii/libucos_ii.a(os_core.o)
> (OS_MemInit)
Which includes os_mem.o to define OS_MemInit.
Et cetera.
Have you verified that the linker is receiving --gc-sections, as I
suggested? Also, did you build with -ffunction-sections and
-fdata-sections? If you want --gc-sections to be useful, you'll have to
put functions and variables into their own discardable sections.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: ld includes entire archive (.a) when compiling .elf file
2006-03-10 22:59 Josh Keller
@ 2006-03-10 23:02 ` Daniel Jacobowitz
0 siblings, 0 replies; 12+ messages in thread
From: Daniel Jacobowitz @ 2006-03-10 23:02 UTC (permalink / raw)
To: Josh Keller; +Cc: binutils, Reuben Johnston
On Fri, Mar 10, 2006 at 05:59:32PM -0500, Josh Keller wrote:
> Building with --gc-sections ends up giving me a 0-byte binary. It seems
> to think all my code is garbage (See below) ;) I'm guessing that I have
> to subdivide my code somehow to tell it what to remove, etc.
>
> I turned on the -f options and got the following error:
> /usr/local/gnu/lib/gcc-lib/arm-elf/3.3/../../../../arm-elf/bin/ld: -f
> may not be used without -shared.
Then obviously you've passed it the wrong options... ah,
-ffunction-sections is not a linker option, it's a compiler option, so
no -Wl.
> Output from my compiler...
>
> arm-elf-gcc Cstartup.o main.o Cstartup_SAM7.o irq.o pio.o
> interrupt_pit.o interrupt_Usart.o --output main.elf -nostartfiles
> -Wl,-Map=main.map,--cref,--gc-sections -Iucos_ii -Lucos_ii -lucos_ii
> -TAT91SAM7S64-ROM.ld
Try using the linker option -e to specify the function at the start of
execution.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: ld includes entire archive (.a) when compiling .elf file
@ 2006-03-10 22:46 Josh Keller
2006-03-10 22:51 ` Daniel Jacobowitz
0 siblings, 1 reply; 12+ messages in thread
From: Josh Keller @ 2006-03-10 22:46 UTC (permalink / raw)
To: binutils, Reuben Johnston
The map file says the archive member is included. However, I only make
one call to an empty function (I'm testing to see what's included) in my
main() called OSInitHookEnd (first line listed below). I'm not sure why
it's pulling in the rest of the libucos_ii.a archive.
-Josh
The top of the map file is as follows:
$ more main.map
Archive member included because of file (symbol)
ucos_ii/libucos_ii.a(os_cpu_c.o)
main.o (OSInitHookEnd)
ucos_ii/libucos_ii.a(os_core.o)
ucos_ii/libucos_ii.a(os_cpu_c.o)
(OSIntCtxSwFlag)
ucos_ii/libucos_ii.a(os_mem.o)
ucos_ii/libucos_ii.a(os_core.o)
(OS_MemInit)
ucos_ii/libucos_ii.a(os_q.o) ucos_ii/libucos_ii.a(os_core.o) (OS_QInit)
ucos_ii/libucos_ii.a(os_task.o)
ucos_ii/libucos_ii.a(os_core.o)
(OSTaskCreateExt)
ucos_ii/libucos_ii.a(os_cpu_a.o)
ucos_ii/libucos_ii.a(os_core.o)
(OSStartHighRdy)
ucos_ii/libucos_ii.a(os_time.o)
ucos_ii/libucos_ii.a(os_core.o)
(OSTimeDly)
/usr/local/gnu/lib/gcc-lib/arm-elf/3.3/libgcc.a(_udivsi3.o)
main.o (__udivsi3)
/usr/local/gnu/lib/gcc-lib/arm-elf/3.3/libgcc.a(_dvmd_tls.o)
/usr/local/gnu/lib/gcc-lib/arm-elf/3.3/libgcc.a(_udivsi3.o) (__div0)
/usr/local/gnu/lib/gcc-lib/arm-elf/3.3/../../../../arm-elf/lib/libc.a(st
rlen.o)
interrupt_Usart.o (strlen)
BTW, the end application is a small microcontroller (with 64kb of FLASH
w/16kb of RAM) so code space is an issue for me. I plan on switching
the processor into THUMB mode later once I have these kinks worked out.
Thanks!
-Josh
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: ld includes entire archive (.a) when compiling .elf file
2006-03-10 22:46 Josh Keller
@ 2006-03-10 22:51 ` Daniel Jacobowitz
0 siblings, 0 replies; 12+ messages in thread
From: Daniel Jacobowitz @ 2006-03-10 22:51 UTC (permalink / raw)
To: Josh Keller; +Cc: binutils, Reuben Johnston
On Fri, Mar 10, 2006 at 05:46:07PM -0500, Josh Keller wrote:
> The map file says the archive member is included. However, I only make
> one call to an empty function (I'm testing to see what's included) in my
> main() called OSInitHookEnd (first line listed below). I'm not sure why
> it's pulling in the rest of the libucos_ii.a archive.
> -Josh
>
> The top of the map file is as follows:
Here's what is happening:
> $ more main.map
> Archive member included because of file (symbol)
>
> ucos_ii/libucos_ii.a(os_cpu_c.o)
> main.o (OSInitHookEnd)
main.o includes os_cpu_c.o to define OSInitHookEnd.
> ucos_ii/libucos_ii.a(os_core.o)
> ucos_ii/libucos_ii.a(os_cpu_c.o)
> (OSIntCtxSwFlag)
os_cpu_c.o includes os_core.o to define OSIntCtxSwFlag.
> ucos_ii/libucos_ii.a(os_mem.o)
> ucos_ii/libucos_ii.a(os_core.o)
> (OS_MemInit)
Which includes os_mem.o to define OS_MemInit.
Et cetera.
Have you verified that the linker is receiving --gc-sections, as
I suggested? Also, did you build with -ffunction-sections and
-fdata-sections? If you want --gc-sections to be useful, you'll
have to put functions and variables into their own discardable
sections.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 12+ messages in thread
* ld includes entire archive (.a) when compiling .elf file
@ 2006-03-10 21:57 Josh Keller
2006-03-10 22:29 ` Daniel Jacobowitz
0 siblings, 1 reply; 12+ messages in thread
From: Josh Keller @ 2006-03-10 21:57 UTC (permalink / raw)
To: binutils; +Cc: Reuben Johnston
I'm trying to compile a .elf file with the following command line:
Linking: main.elf
arm-elf-gcc Cstartup.o main.o Cstartup_SAM7.o irq.o pio.o
interrupt_pit.o interrupt_Usart.o
--output main.elf -nostartfiles -Wl,-Map=main.map,--cref
--no-whole-archive --gc-sections -Iucos_ii
-Lucos_ii -lucos_ii -TAT91SAM7S64-ROM.ld
And I get an executable that runs, however, my binary is much larger
than it is supposed to be because the linker is including all the .o
files in my archive (.a).
I can't figure out what to do. I have tried the --gc-sections option
and the --no-whole-archive option but I still get a really large
executable. I created my archive from .o files using
arm-elf-ar -rcv libucos_ii.a $(OBJS).
I can't seem to figure out a good solution. Any ideas? I'd rather not
create an archive file for each .o file (which sort of defeats the
purpose of having a .a file) Thanks for the help!
I'm using GNU ld version 2.14 20030612
Here is a listing of the files in my archive:
$ arm-elf-size libucos_ii.a
text data bss dec hex filename
4156 0 0 4156 103c os_core.o (ex libucos_ii.a)
208 0 0 208 d0 os_cpu_c.o (ex libucos_ii.a)
0 0 0 0 0 os_flag.o (ex libucos_ii.a)
1168 0 0 1168 490 os_mem.o (ex libucos_ii.a)
2472 0 0 2472 9a8 os_q.o (ex libucos_ii.a)
3360 0 0 3360 d20 os_task.o (ex libucos_ii.a)
368 40 0 408 198 os_cpu_a.o (ex libucos_ii.a)
2 0 0 2 2 os_dbg_r.o (ex libucos_ii.a)
1564 0 0 1564 61c os_mbox.o (ex libucos_ii.a)
2256 0 0 2256 8d0 os_mutex.o (ex libucos_ii.a)
1252 0 0 1252 4e4 os_sem.o (ex libucos_ii.a)
764 0 0 764 2fc os_time.o (ex libucos_ii.a)
-Josh
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: ld includes entire archive (.a) when compiling .elf file
2006-03-10 21:57 Josh Keller
@ 2006-03-10 22:29 ` Daniel Jacobowitz
2006-03-10 22:34 ` Daniel Jacobowitz
0 siblings, 1 reply; 12+ messages in thread
From: Daniel Jacobowitz @ 2006-03-10 22:29 UTC (permalink / raw)
To: Josh Keller; +Cc: binutils, Reuben Johnston
On Fri, Mar 10, 2006 at 04:57:26PM -0500, Josh Keller wrote:
> I can't figure out what to do. I have tried the --gc-sections option
> and the --no-whole-archive option but I still get a really large
> executable. I created my archive from .o files using
> arm-elf-ar -rcv libucos_ii.a $(OBJS).
>
> I can't seem to figure out a good solution. Any ideas? I'd rather not
> create an archive file for each .o file (which sort of defeats the
> purpose of having a .a file) Thanks for the help!
Please try using the -Map option to ld (-Wl,-Map,filename if you're
using GCC). That will tell you why each file is pulled in.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: ld includes entire archive (.a) when compiling .elf file
2006-03-10 22:29 ` Daniel Jacobowitz
@ 2006-03-10 22:34 ` Daniel Jacobowitz
2006-03-10 22:43 ` Daniel Jacobowitz
0 siblings, 1 reply; 12+ messages in thread
From: Daniel Jacobowitz @ 2006-03-10 22:34 UTC (permalink / raw)
To: Josh Keller, binutils, Reuben Johnston
On Fri, Mar 10, 2006 at 05:29:25PM -0500, Daniel Jacobowitz wrote:
> On Fri, Mar 10, 2006 at 04:57:26PM -0500, Josh Keller wrote:
> > I can't figure out what to do. I have tried the --gc-sections option
> > and the --no-whole-archive option but I still get a really large
> > executable. I created my archive from .o files using
> > arm-elf-ar -rcv libucos_ii.a $(OBJS).
> >
> > I can't seem to figure out a good solution. Any ideas? I'd rather not
> > create an archive file for each .o file (which sort of defeats the
> > purpose of having a .a file) Thanks for the help!
>
> Please try using the -Map option to ld (-Wl,-Map,filename if you're
> using GCC). That will tell you why each file is pulled in.
BTW, I see that you were using GCC; --no-whole-archive probably doesn't
get to LD, nor --gc-sections. You have to use -Wl for those options.
But --whole-archive should be the default anyway.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: ld includes entire archive (.a) when compiling .elf file
2006-03-10 22:34 ` Daniel Jacobowitz
@ 2006-03-10 22:43 ` Daniel Jacobowitz
0 siblings, 0 replies; 12+ messages in thread
From: Daniel Jacobowitz @ 2006-03-10 22:43 UTC (permalink / raw)
To: Josh Keller, binutils, Reuben Johnston
On Fri, Mar 10, 2006 at 05:34:45PM -0500, Daniel Jacobowitz wrote:
> BTW, I see that you were using GCC; --no-whole-archive probably doesn't
> get to LD, nor --gc-sections. You have to use -Wl for those options.
> But --whole-archive should be the default anyway.
Sigh, --no-whole-archive should be the default. Sorry about that.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2006-03-11 1:37 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-10 23:08 ld includes entire archive (.a) when compiling .elf file Josh Keller
2006-03-10 23:43 ` Daniel Jacobowitz
-- strict thread matches above, loose matches on Subject: below --
2006-03-11 1:37 Josh Keller
2006-03-10 23:19 Josh Keller
2006-03-10 22:59 Josh Keller
2006-03-10 23:02 ` Daniel Jacobowitz
2006-03-10 22:46 Josh Keller
2006-03-10 22:51 ` Daniel Jacobowitz
2006-03-10 21:57 Josh Keller
2006-03-10 22:29 ` Daniel Jacobowitz
2006-03-10 22:34 ` Daniel Jacobowitz
2006-03-10 22:43 ` Daniel Jacobowitz
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).