Symbol stripping on OSX. Any luck?

Discuss issues relating to audio plugins

Symbol stripping on OSX. Any luck?

Postby Mikey » Tue May 08, 2012 2:13 pm

I've been trying to learn how to strip symbols from plugins. It was pointed out to me that the linker-based flags in XCode don't really have much effect. I started out with Jules' suggestion ("strip -x -S YourPlugin.vst/Contents/MacOS/YourPlugin") and have been digging through man pages. No matter what I do, nm still shows hundreds of internal symbols. The majority of these have no dependencies outside of the plugin, so I don't see why they'd be of any interest to the host executable. They would be of some interest to those whose intents aren't purely musical.

Perhaps there's also something I need to do in the linker, but I must admit to being stumped. I wonder if there's anyone who might point me toward the proper path.
Mikey
JUCE UberWeenie
 
Posts: 227
Joined: Fri Feb 20, 2009 7:36 pm
Location: The Rockies

Re: Symbol stripping on OSX. Any luck?

Postby jpo » Tue May 08, 2012 2:47 pm

are you building with -fvisibility=hidden , and possibly also -fvisibility-inlines-hidden ? that's what I'm using, stripping with 'strip -x' and no unwanted symbol is visible in the plugin with nm
jpo
JUCE UberWeenie
 
Posts: 336
Joined: Thu Mar 20, 2008 2:45 pm

Re: Symbol stripping on OSX. Any luck?

Postby Mikey » Tue May 08, 2012 3:58 pm

jpo wrote:are you building with -fvisibility=hidden , and possibly also -fvisibility-inlines-hidden ? that's what I'm using, stripping with 'strip -x' and no unwanted symbol is visible in the plugin with nm

Ah. Didn't even think of going at the compiler flags. That's a huge help. Thanks!
Mikey
JUCE UberWeenie
 
Posts: 227
Joined: Fri Feb 20, 2009 7:36 pm
Location: The Rockies

Re: Symbol stripping on OSX. Any luck?

Postby Franky47 » Wed May 16, 2012 3:59 pm

I use the following method:

Export only the needed symbols by describing them in a .exp file, and passing "-exported_symbols_list path/to/file.exp" to the linker.

The file would contain, for example:
Code: Select all
# -----------------------------------------------------------------------
# VST

_VSTPluginMain


# -----------------------------------------------------------------------
# AudioUnit
# These two symbols must match the following syntax:
#
# Main entry: _$(JucePlugin_AUExportPrefix)Entry
# View entry: _$(JucePlugin_AUExportPrefix)ViewEntry
#
# JucePlugin_AUExportPrefix is defined in JucePluginCharacteristics.h

_MyPluginEntry
_MyPluginViewEntry


# -----------------------------------------------------------------------
# RTAS

_CDSPDoHostCommand
_CDSPGetLoLong
_CDSPSendLoLong
_CProcessGroupGetBundleRef
_CProcessGroupRestoreResourceFile
_CProcessGroupUseResourceFile
_CloseMachOPlugIn
_Dispatcher
_NewMachOPlugIn
__PI_GetRoutineDescriptor
_main_macho


Note that you need to specify different files for i386 and x86_64 symbols, as RTAS and AudioUnit's view are exported only in i386.

Then I'm using the following perl script, found on a Apple mailing list thread (link is dead now), to strip down the rest:

Code: Select all
# /usr/bin/perl -w
# http://lists.apple.com/archives/xcode-users/2006/mar/msg00552.html
#
# Last updated: 21MAR06, Andy O'Meara and Rob Barris
#
# This is an Xcode post-build phase script for devs who sleep better at night knowing
#    that their deployment binaries are as stripped as possible.  This makes life more difficult
#    for a hacker/cracker to locate sensitive code to trace, study, and/or extract.
#
# This script will execute only if the Xcode "Deployment Postprocessing" setting
#    is set (aka DEPLOYMENT_POSTPROCESSING).
#
# The downside to shipping a stripped binary is that your user's crash reports
#    will be useless unless you have a link map to convert code offsets (from a stack trace)
#    into proc names.  To address this, this script moves your pre-stripped executable
#    to the build dir, appending "_full" to the filename, allowing you to retain it for
#    the day you need it in order to decipher a stack trace.  You do this by using 'atos'
#    with the original generated binary (type 'man atos' for info).
#
# Recommended Xcode build settings:
#    Dead Code Stripping                  YES
#    Only Link In Essential Symbols       NO
#    Deployment Postprocessing            YES (this activates this script)
#    Strip Linked Product                 NO
#    Use Separate Strip                   NO
#    Strip Style                          All Symbols
#    Strip Debug Symbols During Copy      NO
#    Preserve Private External Symbols    NO
#    Separate PCH Symbols                 YES
#    Symbols Hidden By Default            YES (Critical!)
#    Inline Functions Hidden              YES
#
# Note that if you're building a dynamic library, you'll need to explicitly
#    declare any symbols that you want to be exported.  See the following:
#    file:///Developer/ADC%20Reference%20Library/documentation/DeveloperTools/Conceptual/CppRuntimeEnv/Articles/SymbolVisibility.html
#

use strict;

die "$0: Must be run from Xcode" unless $ENV{"BUILT_PRODUCTS_DIR"};

# This script is activated via an Xcode env flag.
if ( $ENV{DEPLOYMENT_POSTPROCESSING} ne "YES" ) {
   exit 0;
}

# Strip output only for Protect configuration
if ( $ENV{CONFIGURATION} ne "Protect" ) {
   exit 0;
}


print "\n\n==================== Commencing external stripping phase...\n";
       
my $BINARY       = "$ENV{BUILT_PRODUCTS_DIR}/$ENV{WRAPPER_NAME}/Contents/MacOS/$ENV{EXECUTABLE_NAME}";
my $BINARY_FULL  = "$ENV{BUILT_PRODUCTS_DIR}/$ENV{EXECUTABLE_NAME}_full";
my $BINARY_i386  = "${BINARY}_i386";
my $BINARY_x86_64   = "${BINARY}_x86_64";

       
# Extract each arch into a "thin" binary for stripping
`lipo "$BINARY" -thin x86_64 -output "$BINARY_x86_64" `;
`lipo "$BINARY" -thin i386   -output "$BINARY_i386"`;

# Retain the orignal binary for QA and use with the util 'atos'
`mv -f "$BINARY" "$BINARY_FULL"`;

# Perform desired stripping on each thin binary. 
`strip -S -x -o "${BINARY_i386}_tmp"   -r "$BINARY_i386"`;
`strip -S -x -o "${BINARY_x86_64}_tmp" -r "$BINARY_x86_64" `;

# We're now done with the original thin binaries, so chuck them.
`rm -f "$BINARY_i386"`;
`rm -f "$BINARY_x86_64" `;

# Make the new universal binary from our stripped thin pieces.
`lipo -arch i386 "${BINARY_i386}_tmp" -arch x86_64 "${BINARY_x86_64}_tmp" -create -output "$BINARY"`;

# We're now done with the temp thin binaries, so chuck them.
`rm -f "${BINARY_i386}_tmp"`;
`rm -f "${BINARY_x86_64}_tmp" `;
`rm -f "${BINARY_FULL}" `;

print "\n==================== External strip phase complete\n";


#EOF
This statement is false.
User avatar
Franky47
JUCE Geek
 
Posts: 44
Joined: Tue Mar 29, 2011 5:15 pm
Location: France

Re: Symbol stripping on OSX. Any luck?

Postby valhallasound » Thu May 17, 2012 4:54 am

I do separate strips in Terminal, after I build in Xcode. None of the build-based strips I tried worked worth a darn.

Sean Costello
valhallasound
JUCE UberWeenie
 
Posts: 393
Joined: Wed Apr 09, 2008 1:30 am

Re: Symbol stripping on OSX. Any luck?

Postby Mikey » Thu May 17, 2012 11:55 am

I've found that the suggestion by jpo (second post on this thread), followed by a terminal-style 'strip' command has been effective. I placed the strip command into an existing Xcode build phase. So the whole thing is still a one-step operation from the human point of view.
Mikey
JUCE UberWeenie
 
Posts: 227
Joined: Fri Feb 20, 2009 7:36 pm
Location: The Rockies


Return to Audio Plugins

Who is online

Users browsing this forum: No registered users and 0 guests