Thread overview
Stripping D symbols?
Oct 16, 2010
Heywood Floyd
Oct 16, 2010
Heywood Floyd
Oct 16, 2010
Heywood Floyd
Oct 16, 2010
Denis Koroskin
October 16, 2010
Hello!

I've been trying to strip an executable created with DMD from symbols. Has anyone any experience with this?

I can't seem to rid my execs of more or less containing the entire class-tree. Example:

// sym.d - - - -
import std.stdio;
class Bunny{
	int x;
	int getX()
	{
		return x;
	}
}
void main()
{
	auto b = new Bunny();
	writefln("Hello %d", b.getX() );
}

// - - - - - (OSX 10.6)

# dmd -release sym
# strip sym
# nm sym | grep Bunny
000028c8 T _D3sym5Bunny4getXMFZi
# _

// - - - - -

This was of course a simplified example. I tried putting "private" in front of the class, but that didn't change anything.

Any ideas? I'm just lost. Is it the same on Linux?

Or maybe this is one of those "features" that allows D to call functions by name or something? I see "T" is a text entry, by reading the man-pages..

(I suppose it really doesn't matter, but if possible I'd like to not expose function and class names in my binaries, for (I think) obvious reasons.)


Kind regards
/HF




October 16, 2010

..ok, I got bored and installed Ubuntu I tried it, and there it worked fine!

# strip sym
# nm sym | grep Bunny
nm: sym: no symbols
# _


Great! The program runs fine too.
(And the binary went from a size of 399Kb to 191Kb! Woah! That's more than half gone!)

Hm, but how to I go about his now? Seems the OSX-strip is acting funny? Or could it have something to do with DMD still? Maybe I should ask in some darwin-forum about strip...

BR
/HF






Heywood Floyd Wrote:

> Hello!
> 
> I've been trying to strip an executable created with DMD from symbols. Has anyone any experience with this?
> 
> I can't seem to rid my execs of more or less containing the entire class-tree. Example:
> 
> // sym.d - - - -
> import std.stdio;
> class Bunny{
> 	int x;
> 	int getX()
> 	{
> 		return x;
> 	}
> }
> void main()
> {
> 	auto b = new Bunny();
> 	writefln("Hello %d", b.getX() );
> }
> 
> // - - - - - (OSX 10.6)
> 
> # dmd -release sym
> # strip sym
> # nm sym | grep Bunny
> 000028c8 T _D3sym5Bunny4getXMFZi
> # _
> 
> // - - - - -
> 
> This was of course a simplified example. I tried putting "private" in front of the class, but that didn't change anything.
> 
> Any ideas? I'm just lost. Is it the same on Linux?
> 
> Or maybe this is one of those "features" that allows D to call functions by name or something? I see "T" is a text entry, by reading the man-pages..
> 
> (I suppose it really doesn't matter, but if possible I'd like to not expose function and class names in my binaries, for (I think) obvious reasons.)
> 
> 
> Kind regards
> /HF
> 
> 
> 
> 

October 16, 2010

..got it solved at last.. \o/
Just writing it down here for future reference (since I found nothing when googling etc..)




Strip can not manage this by itself. The linker, ld (el-dee) needs to be run with the "-exported_symbols_list"-option and given an empty file. Then the symbols created by dmd are treated as local, or whatever it is, and then strip can successfully strip them out. If CLI is used then a stripped binary can be created like this: (#-lines are treated as comments in the exported symbols file.)

   # echo "#empty symbols list for d-code stripping" > symlist
   # dmd -L-exported_symbols_list -Lsymlist myprog
   # strip myprog

If XCode is used (with the D for Xcode plugin) an empty file can be put in the project root and then the "Exported Symbols File"-build property (for Release) can be set to the name of this file. Then, lastly a new Build Phase: Run Script can be added with the code

   strip build/Release/MyApp.app/Contents/MacOS/MyApp

If the target is an OSX-app named MyApp. Hope it helps someone at some point... :)


Toodiloo!
BR
/HF





Heywood Floyd Wrote:

> 
> 
> ..ok, I got bored and installed Ubuntu I tried it, and there it worked fine!
> 
> # strip sym
> # nm sym | grep Bunny
> nm: sym: no symbols
> # _
> 
> 
> Great! The program runs fine too.
> (And the binary went from a size of 399Kb to 191Kb! Woah! That's more than half gone!)
> 
> Hm, but how to I go about his now? Seems the OSX-strip is acting funny? Or could it have something to do with DMD still? Maybe I should ask in some darwin-forum about strip...
> 
> BR
> /HF
> 
> 
> 
> 
> 
> 
> Heywood Floyd Wrote:
> 
> > Hello!
> > 
> > I've been trying to strip an executable created with DMD from symbols. Has anyone any experience with this?
> > 
> > I can't seem to rid my execs of more or less containing the entire class-tree. Example:
> > 
> > // sym.d - - - -
> > import std.stdio;
> > class Bunny{
> > 	int x;
> > 	int getX()
> > 	{
> > 		return x;
> > 	}
> > }
> > void main()
> > {
> > 	auto b = new Bunny();
> > 	writefln("Hello %d", b.getX() );
> > }
> > 
> > // - - - - - (OSX 10.6)
> > 
> > # dmd -release sym
> > # strip sym
> > # nm sym | grep Bunny
> > 000028c8 T _D3sym5Bunny4getXMFZi
> > # _
> > 
> > // - - - - -
> > 
> > This was of course a simplified example. I tried putting "private" in front of the class, but that didn't change anything.
> > 
> > Any ideas? I'm just lost. Is it the same on Linux?
> > 
> > Or maybe this is one of those "features" that allows D to call functions by name or something? I see "T" is a text entry, by reading the man-pages..
> > 
> > (I suppose it really doesn't matter, but if possible I'd like to not expose function and class names in my binaries, for (I think) obvious reasons.)
> > 
> > 
> > Kind regards
> > /HF
> > 
> > 
> > 
> > 
> 

October 16, 2010
On Sat, 16 Oct 2010 23:14:44 +0400, Heywood Floyd <soul8o8@gmail.com> wrote:

>
>
> ..got it solved at last.. \o/
> Just writing it down here for future reference (since I found nothing when googling etc..)
>
>
>
>
> Strip can not manage this by itself. The linker, ld (el-dee) needs to be run with the "-exported_symbols_list"-option and given an empty file. Then the symbols created by dmd are treated as local, or whatever it is, and then strip can successfully strip them out. If CLI is used then a stripped binary can be created like this: (#-lines are treated as comments in the exported symbols file.)
>
>    # echo "#empty symbols list for d-code stripping" > symlist
>    # dmd -L-exported_symbols_list -Lsymlist myprog
>    # strip myprog
>
> If XCode is used (with the D for Xcode plugin) an empty file can be put in the project root and then the "Exported Symbols File"-build property (for Release) can be set to the name of this file. Then, lastly a new Build Phase: Run Script can be added with the code
>
>    strip build/Release/MyApp.app/Contents/MacOS/MyApp
>
> If the target is an OSX-app named MyApp.
> Hope it helps someone at some point... :)
>
>
> Toodiloo!
> BR
> /HF
>
>

Good to know and glad you solved that one. Many people are looking for a way to strip symbols from the executable and reduce file size in general, they should find your information useful.