Symbols in shared libraries

List all exported symbols of a dynamic library:

nm -gD path/to/libyourcode.so

To look at the largest objects/functions in libxul:

readelf -sW $NIGHTLY/libxul.so | sort -k 3 -g -r | head -n 100

To look at the disassembly:

objdump -dr $OBJ | c++filt

On macOS:

otool -tV $OBJ | c++filt

Size of symbols in dylib (mach-o)

This calculates the size of function based on its address and the address of the next symbol:

#!/bin/bash

func=$1
obj=obj/dist/bin/XUL
symline=$(nm -n $obj | rg $func -A1 | c++filt)
startaddr=$(echo "$symline" | head -1 | awk '{print $1}')
endaddr=$(echo "$symline" | tail -1 | awk '{print $1}')
name=$(echo "$symline" | head -1 | awk '{print $3}')
size=$(echo "(0x$endaddr - 0x$startaddr) bytes -> kilobytes" | numbat)

printf "%s\t%s\n" "$size" "$name"

Save as fnsize.sh and run it with:

./fnsize.sh your_function

(Note: only works correctly if $func matches a single symbol)

Last change: 2025-05-07, commit: efad844