3

I have an .SO file (note, not .a, not .dylib and not .o) and I need to get symbol information from it on OSX.

I have tried

nm -gU lib.so

However, nothing is printed out.

I can't use otool because it's not an object file, and readelf does not exists on OSX. How do I get the symbol information?

Please note, that I am using this .so file in another project, and there is symbol information. I am able to load the library, and reference functions from it. However, I have yet to find a tool on OSX to let me print the symbol information from it.

As asked,

file lib.so

ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked, stripped
stevebot
  • 23,275
  • 29
  • 119
  • 181
  • 2
    What is the actual type of the file (not its file extension, which is not determinative)? What does `file lib.so` output? By the way, there are various ELF-related packages supported by MacPorts. For example, it looks like the `elftoolchain` package includes a `readelf` tool. `i386-elf-binutils` or `x86_64-elf-binutils` may also have something useful. I'm sure the other package systems have similar packages. – Ken Thomases Mar 11 '15 at 22:50
  • That's an ARM binary. Will x86/x64 tools be able to make any sense of it? – tadman Mar 11 '15 at 23:30
  • 1
    Because OSX uses the Mach-O binary format, not ELF. As such, utilities like `nm`, etc., don't deal with ELF formats. Nor will they use the same command line syntax. I describe how to build and install the [`binutils`](http://stackoverflow.com/questions/8712352/linux-mach-o-disassembler/8714142#8714142) on Linux for Mach-O files. You might want to compile the `binutils` to run (hosted) on OSX/Darwin, but `--target` will need to be `arm-elf` or some variant. I can't remember specific ARM architectures, but there might be build option which handle everything from older ARM versions, to AArch64. – Brett Hale Dec 02 '16 at 08:42
  • 1
    Sure enough, if you have something like MacPorts installed, there are already packages built for this: `port list | grep -i binutils` lists several packages like: `arm-elf-binutils` – Brett Hale Dec 02 '16 at 08:47

2 Answers2

0

Try using c++filt piped from nm:

nm lib.so | c++filt -p -i

c++filt - Demangle C++ and Java symbols.

-p --no-params When demangling the name of a function, do not display the types of the function's parameters.

-i --no-verbose Do not include implementation details (if any) in the demangled output.

EDIT: Based upon the new (ARM) info provided in the question, try using symbols instead:

symbols lib.so -arch arm | awk '{print $4}'

I've used awk to simplify output; remove to output everything.

Manual page : Symbols

l'L'l
  • 44,951
  • 10
  • 95
  • 146
  • 2
    Thanks, unfortunately nm does not output anything for me. – stevebot Mar 11 '15 at 23:28
  • 1
    If this is a non-OS X library, the OS X tools may not know how to read it. Could you spin up a Linux VM to handle these? [Vagrant](https://www.vagrantup.com/) makes that super easy. If you're dealing with an ARM binary, you may need compiler tools dealing with that architecture. – tadman Mar 11 '15 at 23:29
  • Your first command with `c++filt` gave me no output. Your second command with `symbols` just prints: **file, do** – IgorGanapolsky May 10 '16 at 14:02
0

https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/nm.1.html Nm displays the name list (symbol table) of each object file in the argument list. If an argument is an archive, a listing for each object file in the archive will be produced. File can be of the form libx.a(x.o), in which case only symbols from that member of the object file are listed. (The paren- theses have to be quoted to get by the shell.) If no file is given, the symbols in a.out are listed.