N7SD logo

HOME      INDEX

Debug Information Removal in Ada/OpenAL Projects


In my testing, removing the -g option alone was insufficient to eliminate debug information from the executable.

I recommend the following approach:

  1. Build the executable with default settings
  2. Use the strip command to remove debug information:

$ strip executable_name


Example Results

  • Before stripping: 2.5 MB (with debug_info, not stripped)
  • After stripping: 564 KB (stripped)
  • Size reduction: 77.7% smaller


Strip Command Availability by Operating System

Linux (Ubuntu/Debian/CentOS/Fedora)

  • Included by default (binutils package)

macOS

  • Included in Xcode Command Line Tools

Windows

  • Not included by default
  • Available through MinGW-w64 or MSYS2


Very simple sample (Hello world)

file” command that displays basic information about the file type, format, architecture, etc.
Also shows whether the executable is “stripped” or “not stripped”.

~/ada/test/test_debug_off$ file bin/test_debug_off

bin/test_debug_off: ELF 64-bit LSB executable, x86-64, version 1 (SYSV),
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2,
for GNU/Linux 3.2.0, with debug info, not stripped    *** See "with debug info, not stripped" ***

readelf” command that displays ELF section headers and extracts only sections related to debug or symtab (symbol table).
Used to check if debug information or symbol information is present.

~/ada/test/test_debug_off$ readelf -S bin/test_debug_off | grep -E “(debug|symtab)”

[28] .debug_aranges PROGBITS 0000000000000000 00045d72
[29] .debug_info PROGBITS 0000000000000000 00046e32
[30] .debug_abbrev PROGBITS 0000000000000000 000a272c
[31] .debug_line PROGBITS 0000000000000000 000afb2b
[32] .debug_str PROGBITS 0000000000000000 000d1f14
[33] .debug_line_str PROGBITS 0000000000000000 000f459e
[34] .debug_loclists PROGBITS 0000000000000000 000f525f
[35] .debug_rnglists PROGBITS 0000000000000000 00127d28
[36] .symtab SYMTAB 0000000000000000 0012da88

~/ada/test/test_debug_off$ ls -al bin/test_debug_off

-rwxrwxr-x 1 mm mm 1381280 Aug 16 11:21 bin/test_debug_off            1.38MByte with Debug

Debug Information Removal
strip” command that removes debug information and symbol tables from the executable file.
Reduces the file size by stripping out debugging symbols and other non-essential information.
After execution, the file becomes “stripped” and debugging becomes more difficult

~/ada/test/test_debug_off$ strip bin/test_debug_off

~/ada/test/test_debug_off$ file bin/test_debug_off

bin/test_debug_off: ELF 64-bit LSB executable, x86-64, version 1 (SYSV),
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2,
for GNU/Linux 3.2.0, stripped                                  *** See "stripped" ***

The following command will finish without displaying anything if the executable file contains no debug information:

~/ada/test/test_debug_off$ readelf -S bin/test_debug_off | grep -E “(debug|symtab)”

~/ada/test/test_debug_off$

~/ada/test/test_debug_off$ ls -al  bin/test_debug_off

-rwxrwxr-x 1 mm mm 288184 Aug 16 11:24 bin/test_debug_off           288kByte without Debug