This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH 4/9] binutils: Add a new function to initialise DWARF register name state
- From: "Palmer Dabbelt via binutils" <binutils at sourceware dot org>
- To: andrew dot burgess at embecosm dot com
- Cc: binutils at sourceware dot org, Jim Wilson <jimw at sifive dot com>, nelson dot chu at sifive dot com, andrew dot burgess at embecosm dot com
- Date: Fri, 22 Nov 2019 14:00:54 -0800 (PST)
- Subject: Re: [PATCH 4/9] binutils: Add a new function to initialise DWARF register name state
- Reply-to: Palmer Dabbelt <palmerdabbelt at google dot com>
On Fri, 22 Nov 2019 04:10:28 PST (-0800), andrew.burgess@embecosm.com wrote:
> Adds a new API function init_dwarf_regnames_by_bfd_arch_and_mach to
> initialise the register name state from a BFD architecture and machine
> type.
>
> There should be no user visible changes after this commit.
>
> binutils/ChangeLog:
>
> * dwarf.c (init_dwarf_regnames_by_bfd_arch_and_mach): New
> function.
> * dwarf.h (init_dwarf_regnames_by_bfd_arch_and_mach): Declare.
> * objdump.c (dump_dwarf): Call new function instead of calling
> specific initialization routines. Restrucure so that eh_addr_size
> is still calculated correctly.
>
> Change-Id: I346d665d2079a18ec4d04bd41893d0e9dc05e4b3
> ---
> binutils/ChangeLog | 9 +++++++++
> binutils/dwarf.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
> binutils/dwarf.h | 2 ++
> binutils/objdump.c | 40 ++++------------------------------------
> 4 files changed, 63 insertions(+), 36 deletions(-)
>
> diff --git a/binutils/dwarf.c b/binutils/dwarf.c
> index c888aad3988..e187d29b733 100644
> --- a/binutils/dwarf.c
> +++ b/binutils/dwarf.c
> @@ -7625,6 +7625,54 @@ init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine)
> }
> }
>
> +/* Initialize the DWARF register name lookup state based on the
> + architecture and specific machine type of a BFD. */
> +
> +void
> +init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch,
> + unsigned long mach)
> +{
> + switch (arch)
> + {
> + case bfd_arch_i386:
> + switch (mach)
> + {
> + case bfd_mach_x86_64:
> + case bfd_mach_x86_64_intel_syntax:
> + case bfd_mach_x86_64_nacl:
> + case bfd_mach_x64_32:
> + case bfd_mach_x64_32_intel_syntax:
> + case bfd_mach_x64_32_nacl:
> + init_dwarf_regnames_x86_64 ();
> + break;
> +
> + default:
> + init_dwarf_regnames_i386 ();
> + break;
> + }
> + break;
> +
> + case bfd_arch_iamcu:
> + init_dwarf_regnames_iamcu ();
> + break;
> +
> + case bfd_arch_aarch64:
> + init_dwarf_regnames_aarch64();
> + break;
> +
> + case bfd_arch_s390:
> + init_dwarf_regnames_s390 ();
> + break;
> +
> + case bfd_arch_riscv:
> + init_dwarf_regnames_riscv ();
> + break;
> +
> + default:
> + break;
> + }
> +}
> +
> static const char *
> regname (unsigned int regno, int row)
> {
> diff --git a/binutils/dwarf.h b/binutils/dwarf.h
> index 204f00ef53d..7a50d4e1b69 100644
> --- a/binutils/dwarf.h
> +++ b/binutils/dwarf.h
> @@ -226,6 +226,8 @@ extern unsigned long dwarf_start_die;
> extern int dwarf_check;
>
> extern void init_dwarf_regnames_by_elf_machine_code (unsigned int);
> +extern void init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch,
> + unsigned long mach);
> extern void init_dwarf_regnames_i386 (void);
> extern void init_dwarf_regnames_iamcu (void);
> extern void init_dwarf_regnames_x86_64 (void);
> diff --git a/binutils/objdump.c b/binutils/objdump.c
> index 1be3b232353..81c70e0b9ed 100644
> --- a/binutils/objdump.c
> +++ b/binutils/objdump.c
> @@ -2972,44 +2972,8 @@ dump_dwarf (bfd *abfd)
> return;
> }
>
> - eh_addr_size = bfd_arch_bits_per_address (abfd) / 8;
> -
> switch (bfd_get_arch (abfd))
> {
> - case bfd_arch_i386:
> - switch (bfd_get_mach (abfd))
> - {
> - case bfd_mach_x86_64:
> - case bfd_mach_x86_64_intel_syntax:
> - case bfd_mach_x86_64_nacl:
> - case bfd_mach_x64_32:
> - case bfd_mach_x64_32_intel_syntax:
> - case bfd_mach_x64_32_nacl:
> - init_dwarf_regnames_x86_64 ();
> - break;
> -
> - default:
> - init_dwarf_regnames_i386 ();
> - break;
> - }
> - break;
> -
> - case bfd_arch_iamcu:
> - init_dwarf_regnames_iamcu ();
> - break;
> -
> - case bfd_arch_aarch64:
> - init_dwarf_regnames_aarch64();
> - break;
> -
> - case bfd_arch_s390:
> - init_dwarf_regnames_s390 ();
> - break;
> -
> - case bfd_arch_riscv:
> - init_dwarf_regnames_riscv ();
> - break;
> -
> case bfd_arch_s12z:
> /* S12Z has a 24 bit address space. But the only known
> producer of dwarf_info encodes addresses into 32 bits. */
> @@ -3017,9 +2981,13 @@ dump_dwarf (bfd *abfd)
> break;
>
> default:
> + eh_addr_size = bfd_arch_bits_per_address (abfd) / 8;
> break;
> }
>
> + init_dwarf_regnames_by_bfd_arch_and_mach (bfd_get_arch (abfd),
> + bfd_get_mach (abfd));
> +
> bfd_map_over_sections (abfd, dump_dwarf_section, NULL);
> }
>
Reviewed-by: Palmer Dabbelt <palmerdabbelt@google.com>