[PATCH v2 0/2] Enable arch-specific CFI directives and DWARF instructions only when required by the target (part 1)

Matthieu Longo matthieu.longo@arm.com
Fri Apr 25 11:04:07 GMT 2025


This patch is related to a comment from another patch series (see [1]), and tries to propose a solution for the raised issue while changing the approach proposed in a previous RFC [2] based on the feedback.

## Context

DWARF 5 standard provides a space for vendor-specific DWARF directives. Binutils currently defines GNU-specific DWARF directives and vendor-specific ones for AArch64, SGI/MIPS, and Sparc architectures.
The architecture-specific code is not guarded. This has caused confusion in the past, and .cfi_window_save (a Sparc-specific directive) was used on AArch64 in place of .cfi_negate_ra_state, the defined directive by the "DWARF extensions on AArch64" document (see [3]).

In [1], Jan Beulich rightly pointed out the issue and proposed to introduce an `#ifdef TC_AARCH64` around the AArch64 directives in **gas (only)**. Gas only supports one target architecture (the one selected with --target), whereas others tools like readelf, objdump, etc. deduce the target architecture from the input object at runtime. Hence, using TC_<arch> definitions to enable/disable DWARF directives at compilation time outside of gas is excluded.

## Solution

In bfd, the architecture of the input object is detected at runtime using bfd_get_arch, and only the architecture-specific instructions matching the target of the object are considered during the processing.
In gas, the architecture-specific code is surrounded by TC_<arch> defines to enable/disable DWARF directives at compilation time.

This patch deliberately excluded from the scope binutils/dwarf.c that also requires a check of the architecture at runtime. This part will be addressed in a follow-up patch.

Tested on aarch64-none-linux-gnu and sparc-linux-gnu, and no regression found.

Regards,
Matthieu.
  
[1]: https://inbox.sourceware.org/binutils/eaedfc6c-5666-4a05-a676-d25bf52b76c1@suse.com/
[2]: https://inbox.sourceware.org/binutils/20241211120553.1391850-1-matthieu.longo@arm.com/
[3]: https://github.com/ARM-software/abi-aa/blob/main/aadwarf64/aadwarf64.rst#id1

Diff with revision 1 (https://inbox.sourceware.org/binutils/20250409103611.407140-1-matthieu.longo@arm.com/):
- Addressed code-style comments from Jan regarding switch-cases.
- Removed GAS_MODULE, and TC_<arch> from dwarf2.def.

Matthieu Longo (2):
  Remove annoying spaces at the end of lines in dwarf2.def
  Enable arch-specific CFI directives and DWARF instructions only when required by the target (part 1)

 bfd/elf-eh-frame.c | 93 ++++++++++++++++++++++++++++++++++++++++------
 gas/dw2gencfi.c    | 33 +++++++++++++---
 gas/gen-sframe.c   | 35 ++++-------------
 include/dwarf2.def | 31 ++++++++++------
 4 files changed, 135 insertions(+), 57 deletions(-)

-- 
2.49.0



More information about the Binutils mailing list