Question about LDC and --gc-sections

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Oct 25 17:19:05 UTC 2018


I'm currently working on an Android project that has a significant D
component, and using LDC to cross-compile to ARM. (Much thanks to
Joakim, BTW, who wrote detailed instructions on the wiki on how to set
this up.)  Since Android requires a .so file, I have to statically link
everything into a single .so.  However, I'm finding that the resulting
.so has tons of unused symbols that bloat the size to about 5MB (~1.6MB
after the Android SDK tools compress everything, of which only about
100KB is my actual D code).

Since LDC's libdruntime.a and libphobos2.a already have every function
in its own section, technically the linker *ought* to be able to strip
out most of the unreferenced sections.  However, running the linker with
--gc-sections doesn't seem to reduce the file size significantly, and
many unused sections are still present.  Stripping the file with `strip`
afterwards still leaves over 10,000 symbols, far too many given the
current size of my D code, and clearly an indication of a ton of stuff
in druntime/phobos that I don't actually use. I suspect it may be
because the target is an .so rather than an executable, so the linker
may be leaving in all public symbols as a precaution.

How do I tell the linker (clang) to drop everything except the small
handful of entry points required by the Android API?


T

-- 
Public parking: euphemism for paid parking. -- Flora


More information about the Digitalmars-d mailing list