3

Is there an ld(1) option that provides the equivalent of --exclude-libs ALL on ARM platforms?

I'm trying to reduce the size of a shared object on Android, but --exclude-libs ALL is only available on x86.


EDIT: here's the reason I ask. Sorry about this extra detail. I was trying to keep the question short. My shared object does not export any Crypto++ symbols, yet 88 are showing up with and without --exclude-libs ALL.

Here are the envars of interest:

$ echo $CXX
arm-linux-androideabi-g++
$ echo $ANDROID_STL_INC
/opt/android-ndk-r9/sources/cxx-stl/stlport/stlport/
$ echo $ANDROID_SYSROOT
/opt/android-ndk-r9/platforms/android-9/arch-arm

First, build my shared object without --exclude-libs ALL:

$ $CXX -fPIC -Os -I/usr/local/cryptopp-android-9/include -I$ANDROID_STL_INC
    --sysroot=$ANDROID_SYSROOT com_deltoid_androidprng_PRNG.cpp
    -o libprng.so -shared

And then count the number of Crypto++ exports:

$ arm-linux-androideabi-nm --defined-only libprng.so | grep -i cryptopp | wc -l
      88

Second, same experiment with --exclude-libs ALL:

$ $CXX -fPIC -Os -I/usr/local/cryptopp-android-9/include -I$ANDROID_STL_INC
    --sysroot=$ANDROID_SYSROOT com_deltoid_androidprng_PRNG.cpp
    -o libprng.so -shared -Wl,--exclude-libs,ALL

And then count the number of Crypto++ exports:

$ arm-linux-androideabi-nm --defined-only libprng.so | grep -i cryptopp | wc -l
      88

In both cases, 88 Crypto++ symbols are being exported. The source file is below, an it does not export any Crypto++ symbols.


#include <string.h>
#include <jni.h>

#include <cryptopp/osrng.h>
using CryptoPP::AutoSeededRandomPool;

#include "com_deltoid_androidprng_PRNG.h"

static AutoSeededRandomPool& GetPRNG()
{
    static AutoSeededRandomPool prng;

    return prng;
}

static int IncorporateSensors()
{
    return 0;
}

/*
 * Class:     com_deltoid_androidprng_PRNG
 * Method:    CryptoPP_Reseed
 * Signature: ([B)I
 */
jint JNICALL Java_com_deltoid_androidprng_PRNG_CryptoPP_1Reseed
  (JNIEnv* env, jclass, jbyteArray seed)
{
    int ret, consumed = 0;

    try
    {
        AutoSeededRandomPool& prng = GetPRNG();

        if(env)
        {   
            jbyte* bytes = env->GetByteArrayElements(seed, 0);
            jint length = env->GetArrayLength(seed);

            if(bytes)
            {
                if(length >= 0)
                {
                    prng.IncorporateEntropy((const byte*)bytes, (size_t)length);
                    consumed += length;
                }

                env->ReleaseByteArrayElements(seed, bytes, JNI_ABORT);
            }                   
        }        
    }
    catch(const CryptoPP::Exception& ex)
    {
    }

    return consumed;
}

/*
 * Class:     com_deltoid_androidprng_PRNG
 * Method:    CryptoPP_GetBytes
 * Signature: ([B)I
 */
JNIEXPORT jint JNICALL Java_com_deltoid_androidprng_PRNG_CryptoPP_1GetBytes
  (JNIEnv *, jclass, jbyteArray)
{    
}
miken32
  • 42,008
  • 16
  • 111
  • 154
jww
  • 97,681
  • 90
  • 411
  • 885
  • Is it not recognized or not functioning? – auselen Aug 31 '14 at 06:31
  • @auselen - It does not appear to be functioning. – jww Aug 31 '14 at 13:08
  • @Notlikethat - yeah, I read that. But it does not seem to be working in practice (or it *only* applies to i386 in this case). – jww Aug 31 '14 at 13:09
  • 2
    `exclude-libs` has no effect on symbols defined in your own code. It looks like you have header-only libraries, those headers get compiled into your object and are indistinguishable from your code from the linker's perspective. – Ben Voigt Aug 31 '14 at 13:14
  • No need to apologise for making the question better ;) The context of "...gave this result instead of what I expected when I tried it" is _far_ more useful than the unqualified (and questionable) assumption "...is not available despite what the docs say". – Notlikethat Aug 31 '14 at 15:21
  • 1
    Note that symbols hidden from export by --exclude-libs [can still be shown by `nm`](http://stackoverflow.com/q/4994741/3156750). This [can be confusing](http://stackoverflow.com/a/3657200/3156750). – Notlikethat Aug 31 '14 at 15:57
  • Did you experiment with adding `-fvisibility=hidden` to GCC? – auselen Aug 31 '14 at 16:11

1 Answers1

2

I'm pretty sure --exclude-libs is supported by Android / ARM version of ld, since they use it themselves as well.

Did you try something like below in your Android.mk file?

LOCAL_LDFLAGS += -Wl,--exclude-libs,ALL
auselen
  • 27,577
  • 7
  • 73
  • 114
  • Thanks @auselen. I added additional details with source code and compiler/linker invocations. Sorry about the extra detail. I was trying to keep the question short. (I had to abandon Eclipse and Android.mk. I could not get either one to work. So I went back to the command line, which I know works all the time). – jww Aug 31 '14 at 13:21