nm

list symbols from object files

llvm-nm [-agnoprumxjlPA] [-] [-t format ] [[-arch arch_flag ]] [ file] [ -s segname sectname ]

nm-classic [-agnoprumxjlfPA] [-s segname sectname]] [-] [-t format] [[-arch arch_flag ]] [ file …]

As of Xcode 8.0 the default nm is llvm-nm.

For the most part nm and llvm-nm have the same options; exceptions include -f, -s, and L.

nm displays the name list (symbol table of nlist structures) of each object file.
With an object that has had strip -T applied, that can be different than the dyld information. For that information use dyldinfo.

For an archive, a listing for each object file is produced.
For filenames of the form libx.a\(x.o\) only symbols from that member of the object file are listed.

The output is sorted alphabetically by default.

-g only global (external) symbols.
-p Preserve original order i.e. Don't sort; display in symbol-table order.
-n Sort numerically rather than alphabetically.
-r Sort in reverse order.
-o Prepend file or archive element name to each output line, rather than only once.
-u only undefined symbols.
-U Don't display undefined symbols.
-m Display the N_SECT type symbols (Mach-O symbols) as (segment_name, section_name) followed by either external or non-external and then the symbol name.
Undefined, common, absolute and indirect symbols get displayed as (undefined), (common), (absolute), and (indirect),
Other symbol details are displayed in a human-friendly manner, such as "[no dead strip]".
The referenced symbol for indirect symbols and will display the name of the library expected to provide an undefined symbol. See nlist(3) and mach-o/nlist.h
-x symbol table entry's fields in hexadecimal with the name
-j symbol names (no value or type).
-s segname sectname only those symbols in the section segname,sectname. Must be last on the command line after the files.
-l With -s, list a pseudo symbol .section_start if no symbol has as its value the starting address of the section.
-arch arch_type When the file is a universal file (see arch for the arch_types).
arch_type can be all
The default is to display the symbols from only the host architecture.
-f bsd | sysv| posix | darwin
-A pathname or library name of an object on each line.
-P portable
-a all symbol table entries, i.e. include for use by debuggers.
-t x|d|o With -P output, write the numeric value d decimal (default), o octal or x hexadecimal.
--version as of 11/22/22
Apple LLVM version 12.0.0 (clang-1200.0.32.29)
  Optimized build.
  Default target: x86_64-apple-darwin21.6.0
  Host CPU: broadwell

    GNU nm (GNU Binutils for Raspbian) 2.31.1

    GNU nm version 2.27-44.base.el7_9.1 
--help
nm --help
OVERVIEW: llvm symbol table dumper

USAGE: nm [options] 

OPTIONS:

Generic Options:

  --help             - Display available options (--help-hidden for more)
  --help-list        - Display list of available options (--help-list-hidden for more)
  --version          - Display the version of this program

llvm-nm Options:

  -B                 - Alias for --format=bsd
  -P                 - Alias for --format=posix
  --add-dyldinfo     - Add symbols from the dyldinfo not already in the symbol table, Mach-O only
  --arch=    - architecture(s) from a Mach-O file to dump
  --debug-syms       - Show all symbols, even debugger only
  --defined-only     - Show only defined symbols
  --demangle         - Demangle C++ symbol names
  --dyldinfo-only    - Show only symbols from the dyldinfo, Mach-O only
  --dynamic          - Display the dynamic symbols instead of normal symbols.
  --extern-only      - Show only external symbols
  --format=   - Specify output format
    =bsd             -   BSD format
    =sysv            -   System V format
    =posix           -   POSIX.2 format
    =darwin          -   Darwin -m format
  --just-symbol-name - Print just the symbol's name
  -m                 - Alias for --format=darwin
  --no-demangle      - Don't demangle symbol names
  --no-dyldinfo      - Don't add any symbols from the dyldinfo, Mach-O only
  --no-llvm-bc       - Disable LLVM bitcode reader
  --no-sort          - Show symbols in order encountered
  --no-weak          - Show only non-weak symbols
  --numeric-sort     - Sort symbols by address
  --portability      - Alias for --format=posix
  --print-armap      - Print the archive map
  --print-file-name  - Precede each symbol with the object file it came from
  --print-size       - Show symbol size as well as address
  --radix=    - Radix (o/d/x) for printing symbol Values
    =d               -   decimal
    =o               -   octal
    =x               -   hexadecimal
  --reverse-sort     - Sort in reverse order
  --size-sort        - Sort symbols by size
  --undefined-only   - Show only undefined symbols
  -x                 - Print symbol entry in hex, Mach-O only

Pass @FILE as argument to read options from FILE.  

Each symbol name is preceded by its value
With -m the value is followed by a type code:

Uundefined. Expected to be provided by another module.
Aabsolute
Ttext section
Ddata section
Bbss section
Ccommon
-for debugger table entries; see -a ,
Ssymbol in a section other than those above, or
Iindirect symbol.
u in a dynamic shared library indicates a undefined reference to a private external in another module in the same library.

Local symbols (non-external), have the type in lowercase.
For Objective-C methods the symbol name is
  +−Class_namecategory_name method:name: where
  + is for class methods,
  − is for instance methods.


nm -U main.c.o
00000000 t app_on_error           local text
00000000 d m_app_motion_threshold local data
00000000 T main                   global text 
00000000 t on_wdto
00000000 T setup
00000000 n wm4.0.f12d64df14e574c70a921dc676ec558e
00000000 n wm4._ansi.h.31.de524f58584151836e90d8620a16f8e8
…

> nm main.c.o
         U app_button_init  Undefined
         U app_comms_init
         U app_dc_dc_init
         U app_heartbeat_init
         U app_heartbeat_start
         U app_led_activity_signal
         U app_led_error_signal
         U app_led_init
         U app_log_init
00000000 t app_on_error
         U app_sensor_acc_thr_set
         U app_sensor_init
         U app_sensor_vdd_sample
00000000 d m_app_motion_threshold
00000000 T main
00000000 t on_wdto
         U rd_error_cb_set
         U rd_error_check
         U ri_delay_ms
         U ri_log_init
         U ri_power_reset
         U ri_scheduler_execute
         U ri_scheduler_init
         U ri_timer_init
         U ri_watchdog_init
         U ri_yield
         U ri_yield_init
         U ri_yield_low_power_enable
         U rt_flash_init
         U rt_gpio_init
00000000 T setup
00000000 n wm4.0.f12d64df14e574c70a921dc676ec558e
00000000 n wm4._ansi.h 31.de524f58584151836e90d8620a16f8e8
00000000 n wm4._default_types.h 6.959254cf5f09734ea7516c89e8bb21bd
00000000 n wm4._intsup.h 10.cce27fed8484c08a33f522034c30d2b5
00000000 n wm4._newlib_version.h 4.875b979a44719054cd750d0952ad3fd6
00000000 n wm4._stdint.h 10.c24fa3af3bc1706662bb5593a907e841
00000000 n wm4._types.h 125.5cf8a495f1f7ef36777ad868a1e32068
00000000 n wm4._types.h 184.03611d4f6b5bec9997bcf4279eceba07

00000000 n wm4.app_comms.h 33.71447fe52ea632374ded51d1443d5c7f
00000000 n wm4.app_config.h 35.b651bba672c235f5aeb141fd770cf5e1
00000000 n wm4.app_log.h 2.86c0025fb5cf53becfe3e2e75117e74f
00000000 n wm4.app_sensor.h 37.d3325dd4059e89c56ad9306d72a1771e
00000000 n wm4.application_mode_debug.h 2.01ddc4cf2a98edb7e1baa4cc33f8f60d
00000000 n wm4.application_mode_default.h 2.2295c99aacd4087307c5dc52769c7bbe

00000000 n wm4.cdefs.h 47.14fad0b327eb9dcf106599b738d85132
00000000 n wm4.config.h 220.6cac6a9685cfce5e83c17784171638d9
00000000 n wm4.features.h 22.0ca0b2e469d5b0fcf64dfa21c188c8f3
00000000 n wm4.float.h 29.cae0b78251c51e3ff449cb238a29ed5b
00000000 n wm4.ieeefp.h 77.220d9cccac42cd58761758bee2df4ce6
00000000 n wm4.lock.h 2.1461d1fff82dffe8bfddc23307f6484f
00000000 n wm4.main.h 43.eda67af644d2b91c5ea043083d9b7b16
00000000 n wm4.math.h 13.f32faf077997dea5179da7aa46377238
00000000 n wm4.newlib.h 18.5e5ca3429233af402d406a202f1fc1ac
00000000 n wm4.nrf5_sdk15_app_config.h 2.6339e5799526f0c778e6c0cfae09fced
00000000 n wm4.reent.h 17.90c2574d4acdcfce933db5cb09ff35fe
00000000 n wm4.ruuvi_board_defaults.h 45.94fcf79915b397cb8ad800f4f8502d1a
00000000 n wm4.ruuvi_board_ruuvitag_b.h 43.8f0266e2674fc9c35821653294a15321
00000000 n wm4.ruuvi_boards.h 11.0b95fd9fdbad4b07e98e5b3f6c0dbcb5
00000000 n wm4.ruuvi_driver_enabled_modules.h 18.3baaf871687ea33b2462742b5c58d570
00000000 n wm4.ruuvi_driver_enabled_modules.h 46.2ab59d576a1e8ed3b0f7ba90d9098d24
00000000 n wm4.ruuvi_driver_error.h 23.884daf6f6f6d8af7af3ab0db85589852
00000000 n wm4.ruuvi_driver_sensor.h 63.a8776dde6477ee456a916a8b6d8faf12
00000000 n wm4.ruuvi_interface_communication.h 2.24cfaaf0a86d7063a988ab2141207bf7
00000000 n wm4.ruuvi_interface_communication.h 25.ec2e0ad20c90f2888ba543f05a407666
00000000 n wm4.ruuvi_interface_communication_radio.h 2.e1471bdc8bc7bc6605de9c8f718a41f9
00000000 n wm4.ruuvi_interface_flash.h 31.ad4e26abce3a742a7ea8c43e13f2a3fd
00000000 n wm4.ruuvi_interface_gpio.h 26.c8a96d46ee6972e8f64ff8a4d4b9cb6b
00000000 n wm4.ruuvi_interface_log.h 31.3ca06e02b5ead4aeffa8bc7690196104
00000000 n wm4.ruuvi_interface_power.h 2.b33760264a96923cd63cd888e3a37d12
00000000 n wm4.ruuvi_interface_timer.h 2.e999227e57b4ec8661afad7d4d86b56e
00000000 n wm4.ruuvi_interface_tmp117.h 2.4f66435e19279cc62f8734eea5ca0966
00000000 n wm4.ruuvi_interface_watchdog.h 2.ee5d6d072e3167f0e38a812c73b5dccd
00000000 n wm4.ruuvi_interface_yield.h 2.330d4f75d2bd0e040dce6ac7daa16220
00000000 n wm4.ruuvi_task_led.h 2.3d2e96260a07e6182e167dd52da9faa5
00000000 n wm4.stdarg.h 34.3a23a216c0c293b3d2ea2e89281481e6
00000000 n wm4.stdbool.h 29.07dce69c3b78884144b7f7bd19483461
00000000 n wm4.stddef.h 161.19e15733342b50ead2919490b095303e
00000000 n wm4.stddef.h 161.5349cb105733e8777bfb0cf53c4e3f34
00000000 n wm4.stddef.h 39.99b5021e28f91cdb161c889e07266673
00000000 n wm4.stdint.h 23.d53047a68f4a85177f80b422d52785ed
00000000 n wm4.stdio.h 2.4aa87247282eca6c8f36f9de33d8df1a
00000000 n wm4.stdio.h 27.3fc80220048df77954e38daec3bb9670
00000000 n wm4.stdio.h 81.2a55589bfa3ee24eeb84e3c79458e4a9
00000000 n wm4.stdlib.h 13.4ed386f5c1a80d71e72172885d946ef2
00000000 n wm4.stdlib.h 56.b4ddaf162082f284ba35b4444af99a9a
00000000 n wm4.types.h 114.fb65732f4f5f288a036a25898de2c91f
00000000 n wm4.types.h 40.e8c16e7ec36ba55f133d0616070e25fc
+++
With -a these are included:
$d, $t, .ARM.attributes, .bss, .comment, .data,
.debug_abbrev, .debug_aranges, .debug_frame, .debug_info, .debug_line, .debug_loc, .debug_macro, .debug_ranges, .debug_str,
.group, .rodata.ffff.str1.n, .text

sort on -k to create xref

SEE ALSO ar(1), ar(5), Mach-O(5), stab(5), nlist(3), dyldinfo(1)

BUGS Displaying Mach-O symbols with -m is too verbose. Without the -m, symbols in the Objective-C sections get displayed as an `s'.