public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] Re: How to build a static application binary?
  2010-12-03  4:48 ` Jacob Todd
@ 2010-12-03 15:27   ` Grant Edwards
  2010-12-03 16:53     ` Jacob Todd
  0 siblings, 1 reply; 7+ messages in thread
From: Grant Edwards @ 2010-12-03 15:27 UTC (permalink / raw
  To: gentoo-user

On 2010-12-03, Jacob Todd <jaketodd422@gmail.com> wrote:

> Gotta love gcc!

It's not gcc's fault.

I use gcc on other platforms to create static binaries and don't see
any noticable overhead.

> If you want real static binaries on a unix-ish os, use plan 9.

Except that's not what I want.  I want a static binary on Linux.

-- 
Grant Edwards               grant.b.edwards        Yow! My Aunt MAUREEN was a
                                  at               military advisor to IKE &
                              gmail.com            TINA TURNER!!




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

* Re: [gentoo-user] Re: How to build a static application binary?
  2010-12-03 15:27   ` [gentoo-user] " Grant Edwards
@ 2010-12-03 16:53     ` Jacob Todd
  2010-12-03 22:32       ` Grant Edwards
  0 siblings, 1 reply; 7+ messages in thread
From: Jacob Todd @ 2010-12-03 16:53 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 807 bytes --]

Iirc there a bug in glibc that makes it almost impossible to create static
binaries with it. I can't look the the sources of that info atm, but it be
easily found with google. Do the other platforms you use gcc to build static
binaries with use a different libc?
On Dec 3, 2010 11:14 AM, "Grant Edwards" <grant.b.edwards@gmail.com> wrote:
> On 2010-12-03, Jacob Todd <jaketodd422@gmail.com> wrote:
>
>> Gotta love gcc!
>
> It's not gcc's fault.
>
> I use gcc on other platforms to create static binaries and don't see
> any noticable overhead.
>
>> If you want real static binaries on a unix-ish os, use plan 9.
>
> Except that's not what I want. I want a static binary on Linux.
>
> --
> Grant Edwards grant.b.edwards Yow! My Aunt MAUREEN was a
> at military advisor to IKE &
> gmail.com TINA TURNER!!
>
>

[-- Attachment #2: Type: text/html, Size: 1285 bytes --]

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

* Re: [gentoo-user] How to build a static application binary?
       [not found] <fVtfY-2Jt-7@gated-at.bofh.it>
@ 2010-12-03 17:00 ` David W Noon
  2010-12-03 22:37   ` [gentoo-user] " Grant Edwards
  0 siblings, 1 reply; 7+ messages in thread
From: David W Noon @ 2010-12-03 17:00 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 1498 bytes --]

On Fri, 03 Dec 2010 03:10:02 +0100, Grant Edwards wrote about
[gentoo-user] How to build a static application binary?:

>It seems that "gcc -static" was broken sometime in the last few years.
>
>This used to produce reasonable results:
>
>---------------------------------tiny.c---------------------------------
>#include <unistd.h>
>
>int main(void)
>{
>  write(1,"hi there\n",10);
>  return 0;
>}
>------------------------------------------------------------------------
>
>$ gcc -Wall -static -o tiny tiny.c
>
>$ strip tiny
>
>$ size tiny
>   text    data     bss     dec     hex filename
> 522618    1928    7052  531598   81c8e tiny
> 
>Over _HALF_A_MEGABYTE_ of cruft for a application who's text size is a
>few hundred bytes and makes a single system call.  Leaving out the
>call to write() reduces the file size by 16 bytes.
>
>IOW, an _empty_ main requires 531582 bytes.  Wow.

What you are seeing is a lot of glibc routines being included by the
linkage editor.  These handle all sorts of conditions that will likely
never occur in your program.

Try using a smaller C library, like uclibc or klibc.  They might not
work as well, but they will give you a smaller executable.

Alternatively, try rewriting your code in assembler.
-- 
Regards,

Dave  [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
dwnoon@ntlworld.com (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* [gentoo-user] Re: How to build a static application binary?
  2010-12-03 16:53     ` Jacob Todd
@ 2010-12-03 22:32       ` Grant Edwards
  0 siblings, 0 replies; 7+ messages in thread
From: Grant Edwards @ 2010-12-03 22:32 UTC (permalink / raw
  To: gentoo-user

On 2010-12-03, Jacob Todd <jaketodd422@gmail.com> wrote:

> On Dec 3, 2010 11:14 AM, "Grant Edwards" <grant.b.edwards@gmail.com> wrote:
>> On 2010-12-03, Jacob Todd <jaketodd422@gmail.com> wrote:
>>
>>> Gotta love gcc!
>>
>> It's not gcc's fault.
>
> Iirc there a bug in glibc that makes it almost impossible to create
> static binaries with it.

Yes, that's my understanding as well.  Some design change somewhere
between glibc4 and glibc6 makes it impossible to to static linking in
any meaningful sense of the term.

> I can't look the the sources of that info atm, but it be easily found
> with google. Do the other platforms you use gcc to build static
> binaries with use a different libc?

Yes.  That's how I know it's not gcc's fault: I can build static apps
with gcc/binutils using a different libc.

-- 
Grant Edwards               grant.b.edwards        Yow! A shapely CATHOLIC
                                  at               SCHOOLGIRL is FIDGETING
                              gmail.com            inside my costume..




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

* [gentoo-user] Re: How to build a static application binary?
  2010-12-03 17:00 ` [gentoo-user] How to build a static application binary? David W Noon
@ 2010-12-03 22:37   ` Grant Edwards
  2010-12-03 23:34     ` Alan McKinnon
  0 siblings, 1 reply; 7+ messages in thread
From: Grant Edwards @ 2010-12-03 22:37 UTC (permalink / raw
  To: gentoo-user

On 2010-12-03, David W Noon <dwnoon@ntlworld.com> wrote:

> What you are seeing is a lot of glibc routines being included by the
> linkage editor.  These handle all sorts of conditions that will
> likely never occur in your program.
>
> Try using a smaller C library, like uclibc or klibc.  They might not
> work as well, but they will give you a smaller executable.
>
> Alternatively, try rewriting your code in assembler.

For various reasons (which I doubt anybody cares about), gritting my
teeth and living with the 520K per application looks like a more
practical solution that either using assembler or a different libc.

In practice, I'm sure nobody but me will ever even notice (or care
even if they did notice) the wasted 2MB on a 25MB liveCD.  But it will
still bug me. :/

-- 
Grant Edwards               grant.b.edwards        Yow! SHHHH!!  I hear SIX
                                  at               TATTOOED TRUCK-DRIVERS
                              gmail.com            tossing ENGINE BLOCKS into
                                                   empty OIL DRUMS ...




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

* Re: [gentoo-user] Re: How to build a static application binary?
  2010-12-03 22:37   ` [gentoo-user] " Grant Edwards
@ 2010-12-03 23:34     ` Alan McKinnon
  2010-12-04  5:25       ` Grant Edwards
  0 siblings, 1 reply; 7+ messages in thread
From: Alan McKinnon @ 2010-12-03 23:34 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 1283 bytes --]

Apparently, though unproven, at 00:37 on Saturday 04 December 2010, Grant 
Edwards did opine thusly:

> On 2010-12-03, David W Noon <dwnoon@ntlworld.com> wrote:
> > What you are seeing is a lot of glibc routines being included by the
> > linkage editor.  These handle all sorts of conditions that will
> > likely never occur in your program.
> > 
> > Try using a smaller C library, like uclibc or klibc.  They might not
> > work as well, but they will give you a smaller executable.
> > 
> > Alternatively, try rewriting your code in assembler.
> 
> For various reasons (which I doubt anybody cares about), gritting my
> teeth and living with the 520K per application looks like a more
> practical solution that either using assembler or a different libc.
> 
> In practice, I'm sure nobody but me will ever even notice (or care
> even if they did notice) the wasted 2MB on a 25MB liveCD.  But it will
> still bug me. :/

That's 8% of your space resources. Many more than just you will notice and 
care and whinge loudly. Probably including me.

It might be worth the effort to switch to a libc designed for the sort of task 
you want to accomplish. I assume you already made the effort with busybox or 
similar, it's much the same viewpoint.


-- 
alan dot mckinnon at gmail dot com

[-- Attachment #2: Type: text/html, Size: 5628 bytes --]

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

* [gentoo-user] Re: How to build a static application binary?
  2010-12-03 23:34     ` Alan McKinnon
@ 2010-12-04  5:25       ` Grant Edwards
  0 siblings, 0 replies; 7+ messages in thread
From: Grant Edwards @ 2010-12-04  5:25 UTC (permalink / raw
  To: gentoo-user

On 2010-12-03, Alan McKinnon <alan.mckinnon@gmail.com> wrote:
> Apparently, though unproven, at 00:37 on Saturday 04 December 2010, Grant 
> Edwards did opine thusly:
>
>> On 2010-12-03, David W Noon <dwnoon@ntlworld.com> wrote:
>> > What you are seeing is a lot of glibc routines being included by the
>> > linkage editor.  These handle all sorts of conditions that will
>> > likely never occur in your program.
>> > 
>> > Try using a smaller C library, like uclibc or klibc.  They might not
>> > work as well, but they will give you a smaller executable.
>> > 
>> > Alternatively, try rewriting your code in assembler.
>> 
>> For various reasons (which I doubt anybody cares about), gritting my
>> teeth and living with the 520K per application looks like a more
>> practical solution that either using assembler or a different libc.
>> 
>> In practice, I'm sure nobody but me will ever even notice (or care
>> even if they did notice) the wasted 2MB on a 25MB liveCD.  But it will
>> still bug me. :/
>
> That's 8% of your space resources.

It's closer to 0.5%.  My space resources are 700MB on the CD and
probably at least 512MB of RAM.  Right now I'm using up about 22MB of
the space on the CD, and less than that in RAM.  By the time I'm done,
it will probably be around 25MB.  Anything that boots from a single CD
in under 15 seconds and runs in 512MB of RAM or more will be fine. The
difference between 23MB and 25MB really won't be noticable.

> Many more than just you will notice and care and whinge loudly.
> Probably including me.

Well, I think you'd find it pretty useless no matter how small/fast it
was.  The only thing it's able to do is production test and
diagnostics for a family of PCI boards I support.

> It might be worth the effort to switch to a libc designed for the
> sort of task you want to accomplish. I assume you already made the
> effort with busybox or similar, it's much the same viewpoint.

Sort of.  I'm using busybox, but the "base" of my CD is generated by a
shellscript that strips down a systemrescuecd ISO image to the bare
essesntials (basically just what's required to run a 7MB initrd image
containing busybox). Then I add my three or four static applications
to that.  We used to build our own CD from scratch, but that build
process was fragile and hard to maintain.

The CD doesn't even have network support or drivers for any block
devices except a ramdisk (no SCSI, SATA, ATA, and so on). The only
filesystem it supports is cramfs.  I ripped out USB support also, but
then had to put enough of it back in for the USB keyboards on some of
the machines where it'll be used.

It'll still bug me that those static apps are 90% bloat, but it's just
not worth the effort to switch to uClibc or mess with putting my own
dynamic libraries onto the CD.

-- 
Grant





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

end of thread, other threads:[~2010-12-04  5:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <fVtfY-2Jt-7@gated-at.bofh.it>
2010-12-03 17:00 ` [gentoo-user] How to build a static application binary? David W Noon
2010-12-03 22:37   ` [gentoo-user] " Grant Edwards
2010-12-03 23:34     ` Alan McKinnon
2010-12-04  5:25       ` Grant Edwards
2010-12-03  1:23 [gentoo-user] " Grant Edwards
2010-12-03  4:48 ` Jacob Todd
2010-12-03 15:27   ` [gentoo-user] " Grant Edwards
2010-12-03 16:53     ` Jacob Todd
2010-12-03 22:32       ` Grant Edwards

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox