binutils Newspaper
OCTOBER 6, 2026
gdb — Proposed

Fix `add-symbol-file -o ... -s ...` address mapping bug

Fixes a bug in GDB's `add-symbol-file` command where section addresses are incorrectly mapped when using both `-o` and `-s` options.

Dragorn421 reports a bug in GDB’s add-symbol-file command where the -o (offset) option interferes with specific section mappings provided by the -s option. The issue arises because set_objfile_default_section_offset incorrectly passes 0 to objfile_relocate for sections that should not be modified by the global offset. The proposed fix modifies this function to pass the current offset instead.

In the Thread 1 participant
  1. Dragorn421 <dragorn421@gmail.com> proposer

    Identifies and explains a bug in GDB's `add-symbol-file` command concerning address mapping with `-o` and `-s` options, and proposes a fix.

    “This behavior boils down to the `set_objfile_default_section_offset` function assuming it can pass 0 as `objfile_relocate`'s `offsets` entries to not modify the `-s` mappings previously set by the `symbol_file_add` call in `add_symbol_file_command`.”

In Details

This patch addresses a bug in GDB's add-symbol-file command, which is used to load symbol tables from ELF files at specific memory addresses. The problem occurs when the -o option (to set a default offset for unspecified sections) is used in conjunction with the -s option (to specify an address for a particular section). The set_objfile_default_section_offset function incorrectly handles the case where a section's address is explicitly set by -s, leading to incorrect address mappings in the info files output.

For Context
add-symbol-file
A GDB command used to load symbol table information from an executable or shared library file, allowing it to be mapped to arbitrary memory addresses.
ELF file
Executable and Linkable Format. A common standard file format for executables, object code, shared libraries, and core dumps, used on many Unix-like systems.
section mapping
The process of associating a section within an ELF file (e.g., .text, .data) with a specific memory address when loading it for debugging or execution.
-o option
In add-symbol-file, this option sets a default offset for all sections not explicitly mapped by other options.
-s option
In add-symbol-file, this option allows specifying a base address for a particular section.
Filed Under: gdbbinutilsdebuggingelfaddress mapping