www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Stripping D symbols?

reply Heywood Floyd <soul8o8 gmail.com> writes:
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)




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
Oct 16 2010
parent reply Heywood Floyd <soul8o8 gmail.com> writes:
..ok, I got bored and installed Ubuntu I tried it, and there it worked fine!



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)
 



 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
 
 
 
 
Oct 16 2010
parent reply Heywood Floyd <soul8o8 gmail.com> writes:
..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

file.)





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!
 


 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)
 



 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
 
 
 
 
Oct 16 2010
parent "Denis Koroskin" <2korden gmail.com> writes:
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  

 comments in the exported symbols file.)





 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.
Oct 16 2010