From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id C6F373858401 for ; Wed, 10 Aug 2022 09:27:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C6F373858401 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id C203420355 for ; Wed, 10 Aug 2022 09:27:52 +0000 (UTC) Received: from hawking.suse.de (unknown [10.168.4.11]) by relay2.suse.de (Postfix) with ESMTP id BD3E32C2A9 for ; Wed, 10 Aug 2022 09:27:52 +0000 (UTC) Received: by hawking.suse.de (Postfix, from userid 17005) id 88AB3444B11; Wed, 10 Aug 2022 11:27:52 +0200 (CEST) From: Andreas Schwab To: elfutils-devel@sourceware.org Subject: [PATCH RFC] backends: Add RISC-V object attribute printing X-Yow: Is something VIOLENT going to happen to a GARBAGE CAN? Date: Wed, 10 Aug 2022 11:27:52 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1.91 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Aug 2022 09:27:55 -0000 This does not work yet. The RISC-V attribute tags use the same convention as the GNU attributes: odd numbered tags take a string value, even numbered ones an integer value, but print_attributes assumes the ARM numbering scheme by default for non-GNU attributes. --- backends/ChangeLog | 6 ++++ backends/Makefile.am | 3 +- backends/riscv_attrs.c | 80 ++++++++++++++++++++++++++++++++++++++++++ backends/riscv_init.c | 2 ++ 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 backends/riscv_attrs.c diff --git a/backends/ChangeLog b/backends/ChangeLog index 5b0daffe..a642fe9e 100644 --- a/backends/ChangeLog +++ b/backends/ChangeLog @@ -1,3 +1,9 @@ +2022-08-10 Andreas Schwab + + * Makefile.am (riscv_SRCS): Add riscv_attrs.c. + * riscv_init.c (riscv_init): Hook in riscv_check_object_attribute. + * riscv_attrs.c: New file. + 2022-08-09 Andreas Schwab * riscv_init.c (riscv_init): HOOK segment_type_name, diff --git a/backends/Makefile.am b/backends/Makefile.am index 9566377f..1863f66a 100644 --- a/backends/Makefile.am +++ b/backends/Makefile.am @@ -91,7 +91,8 @@ m68k_corenote_no_Wpacked_not_aligned = yes bpf_SRCS = bpf_init.c bpf_regs.c bpf_symbol.c riscv_SRCS = riscv_init.c riscv_symbol.c riscv_cfi.c riscv_regs.c \ - riscv_initreg.c riscv_corenote.c riscv64_corenote.c riscv_retval.c + riscv_initreg.c riscv_corenote.c riscv64_corenote.c \ + riscv_retval.c riscv_attrs.c csky_SRCS = csky_attrs.c csky_init.c csky_symbol.c csky_cfi.c \ csky_regs.c csky_initreg.c csky_corenote.c diff --git a/backends/riscv_attrs.c b/backends/riscv_attrs.c new file mode 100644 index 00000000..6947be6e --- /dev/null +++ b/backends/riscv_attrs.c @@ -0,0 +1,80 @@ +/* Object attribute tags for RISC-V. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of either + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at + your option) any later version + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at + your option) any later version + + or both in parallel, as here. + + elfutils is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#define BACKEND riscv_ +#include "libebl_CPU.h" + +#define KNOWN_VALUES(...) do \ + { \ + static const char *table[] = { __VA_ARGS__ }; \ + if (value < sizeof table / sizeof table[0]) \ + *value_name = table[value]; \ + } while (0) + +bool +riscv_check_object_attribute (Ebl *ebl __attribute__ ((unused)), + const char *vendor, int tag, uint64_t value, + const char **tag_name, const char **value_name) +{ + if (!strcmp (vendor, "riscv")) + switch (tag) + { + case 4: + *tag_name = "RISCV_stack_align"; + return true; + + case 5: + *tag_name = "RISCV_arch"; + return true; + + case 6: + *tag_name = "RISCV_unaligned_access"; + KNOWN_VALUES ("No unaligned access", "Unaligned access"); + return true; + + case 8: + *tag_name = "RISCV_priv_spec"; + return true; + + case 10: + *tag_name = "RISCV_priv_spec_minor"; + return true; + + case 12: + *tag_name = "RISCV_priv_spec_revision"; + return true; + } + + return false; +} diff --git a/backends/riscv_init.c b/backends/riscv_init.c index f2d46082..e5e9e33e 100644 --- a/backends/riscv_init.c +++ b/backends/riscv_init.c @@ -69,6 +69,8 @@ riscv_init (Elf *elf, HOOK (eh, section_type_name); HOOK (eh, dynamic_tag_name); HOOK (eh, dynamic_tag_check); + HOOK (eh, check_object_attribute); + HOOK (eh, set_initial_registers_tid); if (eh->class == ELFCLASS64) eh->core_note = riscv64_core_note; else -- 2.37.1 -- Andreas Schwab, SUSE Labs, schwab@suse.de GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different."