MIPS: Fix line info in compressed MIPS function
Discussion on a patch that improves DWARF line number information for MIPS compressed functions.
This discussion concerns a patch for MIPS ELF handling in the BFD library that aims to improve the accuracy of DWARF line number information for compressed MIPS functions. The patch proposes a strategy where, if the standard line number lookup fails, it retries by setting the Instruction Set Architecture (ISA) bit in the program counter offset. This is based on an observation that line number entries for compressed functions might have the ISA bit set, causing the initial lookup to fail if the PC does not also have this bit set. A reviewer notes that this approach is analogous to a GDB commit that preserves the ISA bit.
- contributor
Provides the patch which retries line info lookup for MIPS compressed functions by setting the ISA bit in the offset.
“The bfd_find_nearest_line_discriminator may not be able to find filename and line if pc points to start of a MIPS compressed function. This is because ISA bit is set in the line number entries. For example, if start of a function is 0x80200750 then line number entries start from 0x80200751 (31st bit is set). Set ISA bit of the pc and search again.”
- reviewer
Comments that the patch retries after other handlers fail by setting the ISA bit, which aligns with a similar GDB commit.
“So this sets the ISA bit and retries once all the handlers have failed. This would be conceptually analogous to GDB commit 3e29f34a4eef ("MIPS: Keep the ISA bit in compressed code addresses"), which makes sense to me.”
Technical Tradeoffs
- Introduces a second lookup attempt for line information, which could slightly increase debugging lookup time in specific MIPS compressed function scenarios.
In Details
This patch for bfd's MIPS ELF backend addresses an issue with DWARF line number information for MIPS compressed instructions (MIPS16/microMIPS). The problem is that when the program counter (pc) points to the start of a compressed function, the DWARF line number entries might have the ISA bit (indicating compressed mode) set in their address, while the pc itself might not. The _bfd_elf_find_nearest_line function, when called with such a pc, fails to find the correct line. The patch adds a retry mechanism: if the initial lookup fails and the pc is not already marked as compressed,…
- MIPS
- A family of reduced instruction set computing (RISC) architectures developed by MIPS Computer Systems.
- ELF
- Executable and Linkable Format, a common standard file format for object files, executables, and shared libraries on Unix-like systems.
- BFD
- Binary File Descriptor library, a GNU library used for accessing and manipulating various executable binary file formats.
- DWARF
- Debugging With Attributed Record Formats, a standardized debugging data format used by many compilers and debuggers.
- compressed MIPS function
- Refers to MIPS code generated using compression techniques (like MIPS16 or microMIPS) to reduce instruction size, which can affect address interpretation.
- line info
- Debugging information that maps machine code addresses back to source code lines.
- ISA bit
- Instruction Set Architecture bit. In the context of MIPS compressed code, this bit in an address might indicate whether the instruction at that address is compressed.