GitXplorerGitXplorer
n

lssym

public
38 stars
6 forks
0 issues

Commits

List of commits on branch main.
Verified
e0360f05ffaa33e75e2c91d5fcb52c7e7e48b5d0

mention dyld_info

nnico committed 2 years ago
Unverified
ed71d5247659dd27235a8ddffe8e3002f3557436

add LC_DYLD_INFO_ONLY

nnico committed 5 years ago
Unverified
26cf80ca927c324cab481347302c7fb25da5b3b1

align

nnico committed 5 years ago
Unverified
e90e41dd385644d86499050a5d5d8f1a9cb82b00

more compact section flags

nnico committed 5 years ago
Unverified
392a6d6b24a09339b3cdafce1bdd2a103b94b46b

dump segment details

nnico committed 5 years ago
Unverified
e71abf574d3dafe00faaca9cfb5d1b731310cc4b

correctly dump LC_BUILD_VERSION and LC_MAIN

nnico committed 5 years ago

README

The README file for this repository.

A toy program to teach myself more about the mach-o file format. Right now, it roughly does what dsymutil -s does (which is a bit more than nm), but worse.

Demo

But one can already see interesting things with this tool.

See symbols in lssym (like with nm, but with some otool -l thrown in):

clang -o lssym lssym.c -Wall 
./lssym lssym

See what's left after stripping:

strip lssym
./lssym lssym

(Compare with the output of nm lssym and dsymutil -s lssym in both cases. Note that strip adds a symbol that looks like

radr://5614542    N_STAB 3c    n_sect 000 n_desc 0x0000    n_value 0x5614542

I wonder what that bug is. nm doesn't list it because nm only lists symbols, and this is a stabs debug info entry which nm only shows if you pass -a.)

Now build with debug info:

clang -o lssym lssym.c -Wall -gdwarf-2
./lssym lssym

Note that the file now includes stabs debug info, even though we asked for dwarf. dsymutil lssym complains about a temporary .o file. Let's break up compile and link step:

clang -c lssym.c -Wall -gdwarf-2
clang -o lssym lssym.o
dsymutil lssym
./lssym lssym         # Still contains stabs entries.
dwarfdump lssym.dSYM  # But this finds dwarf info now, too.
dwarfdump lssym.o     # So does this.
dwarfdump lssym       # This doesn't.

If you don't want ld to write stabs info (since you have a dSYM, it's pointless, and might slow down the ld step), link like this:

clang -o lssym lssym.o -Wl,-S

If you pass -Wl,-s instead, ld will claim that -s is obsolete and ignored, but still still strip all symbols that can be stripped (after first writing them as far as I understand -- so that probably doesn't help with linker performance).

Related tools

  • dyldinfo can show relocation info (man dyldinfo works, but dyldinfo isn't in my path for some reason -- xcrun dyldinfo finds it though)
    • e.g. -exports, -opcodes, ...
  • dyld_info is apparently different from dyldinfo, and can print chained relocs, dependent librarys, opcodes, ... (and it doesn't need xcrun)
  • dwarfdump shows dwarf debug data
  • dsymutil can show symbol tables (-s) and link dwarf debug info from .o files into a single .dSYM file.
  • nm shows references symbols; a subset of dsymutil -s output.
  • otool -l all load commands in a mach-o file.
  • dwarfdump --file-stats lssym
  • atos
  • dwarfdump --lookup
  • run programs with DYLD_PRINT_STATISTICS=1 set (see man dyld for more flags)

http://wiki.dwarfstd.org/index.php?title=Apple's_%22Lazy%22_DWARF_Scheme