[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C++ religious war (was: llua Higher-level C API for Lua)
- From: David Given <dg@...>
- Date: Sun, 23 Mar 2014 12:09:03 +0000
On 23/03/14 02:35, Sean Conner wrote:
[...]
> To ensure that the exectable only includes those functions used out of
> a library, you have to basically put each public routine in its own object
> file, which could explain the "lots of small files" you might see in C or
> C++.
Traditionally, yes, which is why C libraries tend to have every function
in their own source file:
http://sourceforge.net/p/tack/tack/ci/default/tree/lang/cem/libcc.ansi/ctype/toupper.c
However, the details are a bit more subtle. Linkers actually work on the
section level, not on the object file level; historically object files
could only contain a single section (I'm simplifying a bit here), so
they were equivalent.
Modern object files, however, can contain multiple sections. And modern
compilers have options to emit every function into its own section. Now
the linker is capable of discarding unused code at function granularity,
not object file granularity. Check out gcc's -ffunction-sections and
-fdata-sections options, which enable this (you may also need to pass
-Wl,--gc-sections to the linker). If you use a lot of static libraries
enabling them will probably shrink your executable considerably.
I will add that this sort of nonsense is precisely the kind of
implementation-specific detail that sane programmers[*] should never
need to care about. The fact that we *do* need to care about it is very sad.
[*] Although no-one has ever accused me of being a sane programmer.
--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "There does not now, nor will there ever, exist a programming
│ language in which it is the least bit hard to write bad programs." ---
│ Flon's Axiom
Attachment:
signature.asc
Description: OpenPGP digital signature
- References:
- Re: C++ religious war (was: llua Higher-level C API for Lua), steve donovan
- Re: C++ religious war (was: llua Higher-level C API for Lua), Roberto Ierusalimschy
- Re: C++ religious war (was: llua Higher-level C API for Lua), Hisham
- Re: C++ religious war (was: llua Higher-level C API for Lua), steve donovan
- Re: C++ religious war (was: llua Higher-level C API for Lua), Roberto Ierusalimschy
- Re: C++ religious war (was: llua Higher-level C API for Lua), Jeremy Ong
- Re: C++ religious war (was: llua Higher-level C API for Lua), Hisham
- Re: C++ religious war (was: llua Higher-level C API for Lua), Coroutines
- Re: C++ religious war (was: llua Higher-level C API for Lua), steve donovan
- Re: C++ religious war (was: llua Higher-level C API for Lua), William Ahern
- Re: C++ religious war (was: llua Higher-level C API for Lua), Sean Conner