On Saturday, 11 April 2015 at 15:35:47 UTC, w0rp wrote:
I've been looking into compiling smaller executables, and the
trick I learned from watching sessions from the last DConf is
to use the KEEP symbol in a linker script with something like
gc-sections. So at the compilation stage, symbols are put in
different sections, a linker script marks some symbols to be
kept if they are not referenced, and then unreferenced symbols
are removed, resulting in sometimes very small executables.
The problem is that if you don't KEEP some symbols for
druntime, or in your own program, you can run into errors
because symbols which weren't apparently referenced now get
used and your program breaks. I was just thinking, "There must
be a GCC extension for doing this without a linker script," I
*think* there might be.
From what I just read, __attribute__((used)) in GCC should do
the job, and I think it should be usable from GDC with its
attribute pragmas. I believe there's also an attribute for
putting symbols in particular sections. I'm wondering,
supposing I'm not completely wrong and this actually works,
would it behoove us to add some version() blocks for GDC (Also
LDC?) in druntime and flag all of the symbols like this
appropriately, so that creating executables with gc-sections
will Just Work in some cases without a linker script?
What do people think? Am I on to something, or I am just making
fanciful ideas which won't work?
I tried to elicit some direction on this in the past, but I
wasn't able to get very far. The following forum threads may
interest you:
"Dead code removal"
http://forum.dlang.org/post/[email protected]
"--gc-section and GDC]
http://forum.dlang.org/post/[email protected]
"Difference in perpective between LDC and GDC"
http://forum.dlang.org/post/[email protected]
I get the impression from those discussions that the binutils
implementation for D is incomplete but it's still not clear to me
whether dead code removal, or retainining "used" code, is a job
for the compiler or the linker. It may require some
orchestration between the two.
I proposed an idea to move declarations for certain runtime hooks
out of the compiler and into druntime as *.di files. That would
allow for features of the runtime to be decorated in the
platform's port with "used", "weak", "section", etc., but
although I proposed it, I'm not convinced it's the way forward.
You can see the thread here:
http://forum.dlang.org/post/[email protected]
Mike