[PATCH 0/2] gas: Anchor DWARF subprograms to the definitions

Longjun Luo luolongjuna@gmail.com
Tue Nov 24 11:51:34 GMT 2026


I am working on a tool to check DWARF correctness. When checking
debuginfo output from GAS, I found that addr2line may fail to find
the function name for a weak function and fail to find the source
line for the strong one. The problem is caused by using the function
symbol for DWARF address reference. For mechanisms like weak/strong
and COMDAT, a function may lose its original symbol after link, so
the DIE refers to the wrong address.

At first, I try to anchor the subprogram DIE to its definition by
generating a local start symbol. After organizing test cases, I
found two exceptions - ARM Thumb and MIPS. Both of them use the
lowest bit of the address to indicate the ISA mode, and the
difference is that MIPS uses this encoded address directly in
debuginfo. When using a local symbol, microMIPS may lose the ISA
mode in st_other if the relocation is reduced to a section symbol.
So I have to fix the existing microMIPS alias issue first in patch 1,
and save the ISA mode in patch 2. For ARM Thumb, using a local
symbol avoids setting the Thumb bit in .debug_info, which also fixes
its address mismatch with .debug_line.

For my other work about the weak mechanism, check the GDB report [1]
and LLDB fix [2]. This series aligns GAS with compilers (like GCC and
Clang) on weak functions, and more fixes for the weak issues are being
organized.

I ran the full GAS testsuite and selected ld tests on x86-64, ARM,
MIPS and RV64 with no unexpected failures.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=34741
[2] https://github.com/llvm/llvm-project/pull/233545

Longjun Luo (2):
  gas: Keep the ISA bit for a local alias of a weak microMIPS function
  gas: Anchor DWARF subprograms to the definitions

 gas/config/tc-mips.c                          | 18 ++++++++-
 gas/config/tc-mips.h                          |  3 ++
 gas/doc/internals.texi                        |  5 +++
 gas/dwarf2dbg.c                               | 16 +++++++-
 .../gas/elf/dwarf-3-func-weak-reloc.d         | 10 +++++
 gas/testsuite/gas/elf/elf.exp                 |  1 +
 ld/testsuite/ld-arm/arm-elf.exp               |  1 +
 ld/testsuite/ld-arm/dwarf-func-strong.s       |  7 ++++
 ld/testsuite/ld-arm/dwarf-func-thumb-range.d  | 38 +++++++++++++++++++
 ld/testsuite/ld-arm/dwarf-func-thumb.s        | 16 ++++++++
 ld/testsuite/ld-elf/dwarf-func-comdat-range.d | 26 +++++++++++++
 ld/testsuite/ld-elf/dwarf-func-comdat.s       |  8 ++++
 ld/testsuite/ld-elf/dwarf-func-strong.s       |  7 ++++
 ld/testsuite/ld-elf/dwarf-func-weak-range.d   | 24 ++++++++++++
 ld/testsuite/ld-elf/dwarf-func-weak.s         | 17 +++++++++
 ld/testsuite/ld-mips-elf/dwarf-func-strong.s  | 10 +++++
 .../ld-mips-elf/dwarf-func-weak-range.d       | 28 ++++++++++++++
 ld/testsuite/ld-mips-elf/dwarf-func-weak.s    | 22 +++++++++++
 .../ld-mips-elf/micromips-local-alias-call.d  | 13 +++++++
 .../ld-mips-elf/micromips-local-alias.d       |  8 ++++
 .../ld-mips-elf/micromips-local-alias.s       | 23 +++++++++++
 ld/testsuite/ld-mips-elf/mips-elf.exp         |  7 +++-
 22 files changed, 304 insertions(+), 4 deletions(-)
 create mode 100644 gas/testsuite/gas/elf/dwarf-3-func-weak-reloc.d
 create mode 100644 ld/testsuite/ld-arm/dwarf-func-strong.s
 create mode 100644 ld/testsuite/ld-arm/dwarf-func-thumb-range.d
 create mode 100644 ld/testsuite/ld-arm/dwarf-func-thumb.s
 create mode 100644 ld/testsuite/ld-elf/dwarf-func-comdat-range.d
 create mode 100644 ld/testsuite/ld-elf/dwarf-func-comdat.s
 create mode 100644 ld/testsuite/ld-elf/dwarf-func-strong.s
 create mode 100644 ld/testsuite/ld-elf/dwarf-func-weak-range.d
 create mode 100644 ld/testsuite/ld-elf/dwarf-func-weak.s
 create mode 100644 ld/testsuite/ld-mips-elf/dwarf-func-strong.s
 create mode 100644 ld/testsuite/ld-mips-elf/dwarf-func-weak-range.d
 create mode 100644 ld/testsuite/ld-mips-elf/dwarf-func-weak.s
 create mode 100644 ld/testsuite/ld-mips-elf/micromips-local-alias-call.d
 create mode 100644 ld/testsuite/ld-mips-elf/micromips-local-alias.d
 create mode 100644 ld/testsuite/ld-mips-elf/micromips-local-alias.s

-- 
2.55.0



More information about the Binutils mailing list