Question about LDC and --gc-sections

Jonathan Marler johnnymarler at gmail.com
Thu Oct 25 18:09:35 UTC 2018


On Thursday, 25 October 2018 at 17:19:05 UTC, H. S. Teoh wrote:
> 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

I don't know the answer to this question, but one thing you might 
try.  As an experiment, you could write a dummy main function 
that calls all the entry points you need to expose and then link 
it as an executable with --gc-sections and see how many symbols 
you are left with.  I'm very curious about this one so hopefully 
someone knows the answer to this.


More information about the Digitalmars-d mailing list