0

I need to get the symbols defined in .so file. I use latest Mac OS and I do this:

 /usr/bin/nm  -gC libs/armeabi/libhello.so 

error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm: invalid argument -C Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm [-agnopruUmxjlfAP[s segname sectname] [-] [-t format] [[-arch ] ...] [file ...]

As I understand this is another nm utility? It is connected with XCode? How to fix this issue?

EDIT: Adding code from which the .so file is created.

#include <android/log.h>
#include <stdio.h>
#include <jni.h>

       jint NativeAddition(JNIEnv *pEnv, jobject pObj, jint pa, jint pb)
       {
         return pa+pb;
       }

       jint NativeMultiplication(JNIEnv *pEnv, jobject pObj, jint pa,
       jint pb) {
         return pa*pb;
       }

       JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* pVm, void* reserved)
       {
           JNIEnv* env;
           if ((*pVm)->GetEnv(pVm, (void **)&env, JNI_VERSION_1_6)) {
return -1; }
           JNINativeMethod nm[2];
           nm[0].name = "NativeAddition";
           nm[0].signature = "(II)I";
           nm[0].fnPtr = NativeAddition;
           nm[1].name = "NativeMultiplication";
           nm[1].signature = "(II)I";
           nm[1].fnPtr = NativeMultiplication;
           jclass cls = (*env)->FindClass(env, "com/example/hellondk/HelloNDKActivity");
           // Register methods with env->RegisterNatives.
           (*env)->RegisterNatives(env, cls, nm, 2);
           return JNI_VERSION_1_6;
}

This example is from Android Native Development Kit Cookbook.

And also here is the usage message of my nm

Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm [-agnopruUmxjlfAP[s segname sectname] [-] [-t format] [[-arch ] ...] [file ...]

Narek
  • 38,779
  • 79
  • 233
  • 389

2 Answers2

1

In OS X the -C option for demangling symbols is absent.

# nm libs/armeabi/libhello.so | c++filt -p -i

You can instead use c++filt as a wrapper or invoke it as shown above.

l'L'l
  • 44,951
  • 10
  • 95
  • 146
  • I have an .so file that contains just two functions. And when I write §nm -g libhello.so§ it prints nothing. Consequently it does not print anything after piping. – Narek Jun 01 '14 at 03:26
  • Remove the `-g` option :) – l'L'l Jun 01 '14 at 03:27
  • Again prints nothing. What is -g option? Does it matter that .so file is for JNI? – Narek Jun 01 '14 at 03:53
  • @Narek, The `-g`option will display only global (external) symbols (mostly for use with dylibs, etc.). You might need to install `c++filt`, although it's usually included with the XCode command line tools - what is the output of `which c++filt`? – l'L'l Jun 01 '14 at 03:56
  • I have that tool here: `/usr/bin/c++filt`. The problem is that `nm libs/armeabi/libhello.so` prints nothing. In this case it should be true that I pase nothing with pipe to `c++filt` which in its turn, obviously, should print nothing. – Narek Jun 01 '14 at 04:00
  • Hmmm. If you can post the file I'll take a look. – l'L'l Jun 01 '14 at 04:04
  • Sure, it is a C code. Does it matter? And please see my edit for the code. – Narek Jun 01 '14 at 04:07
  • I have added the usage message of my `nm`, please check it with yours. Maybe mine is not what I need. – Narek Jun 01 '14 at 04:24
  • The synopsis on my `nm` is this: `nm [ -agnoprumxjlfPA [ s segname sectname ]] [ - ] [ -t format ] [[ -arch arch_flag ]...] [ file ... ]`. I don't have those libs installed (`android` and `jni`), so if you could upload the compiled `.so` then i could look. – l'L'l Jun 01 '14 at 04:37
  • Thank you very much for your help. Never mind, I have asked you too much questions :). Sorry about that. – Narek Jun 01 '14 at 05:09
0

Install macports and then, using macports run port install binutils.

Finally, run gobjdump -p app

ichramm
  • 6,437
  • 19
  • 30