genodelabs/genode — Issue #49: Separate symbols from binaries using GNU debuglink (was sf id 3023943)
Author: nfeske
Created: 2011-12-20 10:02:20+00:00
State: open
Labels: feature

Modern binutils versions 2.18, 2.19, 2.20+ allow splitting of symbols from ELF files, leaving only symbol link in target ELF.
This allows keep symbols separate with release code and makes debugging considerably easier.
E.g. you reference the elf file in gdb/insight "symbol-file foo" -> gdb knows about .debuglink sections and loads the referenced external symbol file.

Example for symbol splitting step for base\mk\prg.mk:

```
TARGET_DBG = $(INSTALL_DIR)/.debug/$(TARGET).dbg

$(INSTALL_DIR)/$(TARGET): $(TARGET_DBG)
$(MSG_STRIP)$(TARGET)
$(VERBOSE)ln -sf `pwd`/$(TARGET) $@
$(VERBOSE)$(CUSTOM_OBJCOPY) --add-gnu-debuglink=$(TARGET_DBG) --strip-unneeded $(abspath $(TARGET)) $@
$(VERBOSE)chmod 755 $@

$(TARGET_DBG): $(TARGET)
$(MSG_SYMBOLS)$(TARGET)
$(VERBOSE)$(CUSTOM_OBJCOPY) --only-keep-debug $(abspath $<) $@
```

This would produce an ELF file as usual, stripped of all symbol information "foo" and a file "foo.dbg" containing all symbol info for debugging in ".debug" subfolder.

global.mk:

```
MSG_SYMBOLS = @$(ECHO) " SYMBOLS "
MSG_STRIP = @$(ECHO) " STRIP+INST "
```