binutils-gdb/include/elf/riscv.h
Jim Wilson 2dc8dd17cd RISC-V: Support ELF attribute for gas and readelf.
2019-01-16  Kito Cheng  <kito@andestech.com>
		    Nelson Chu  <nelson@andestech.com>

	bfd/
	* elfnn-riscv.c (riscv_elf_obj_attrs_arg_type): New.
	(elf_backend_obj_attrs_vendor): Define.
	(elf_backend_obj_attrs_section_type): Likewise.
	(elf_backend_obj_attrs_section): Likewise.
	(elf_backend_obj_attrs_arg_type): Define as
	riscv_elf_obj_attrs_arg_type.
	* elfxx-riscv.c (riscv_estimate_digit): New.
	(riscv_estimate_arch_strlen1): Likewise.
	(riscv_estimate_arch_strlen): Likewise.
	(riscv_arch_str1): Likewise.
	(riscv_arch_str): Likewise.
	* elfxx-riscv.h (riscv_arch_str): Declare.
	binutils/
	* readelf.c (get_riscv_section_type_name): New function.
	(get_section_type_name): Add handler for RISC-V.
	(riscv_attr_tag_t): Declare.
	(riscv_attr_tag): New.
	(display_riscv_attribute): New function.
	(process_attributes): Add handler for RISC-V.
	* testsuite/binutils-all/strip-3.d: Remove .riscv.attribute
	section.
	gas/
	* config/tc-riscv.c (DEFAULT_RISCV_ATTR): Define to 0 if not defined.
	(riscv_set_options): Add `arch_attr` field.
	(riscv_opts): Set default value for arch_attr.
	(riscv_write_out_arch_attr): New.
	(riscv_set_public_attributes): Likewise.
	(riscv_md_end): Likewise.
	(riscv_convert_symbolic_attribute): Likewise.
	(s_riscv_attribute): Likewise.
	(explicit_arch_attr): Likewise.
	(riscv_pseudo_table): Add .attribute to the table.
	(options): Add OPTION_ARCH_ATTR and OPTION_NO_ARCH_ATTR
	enumeration constants.
	(md_longopts): Add `march-attr' and `mno-arch-attr' options.
	(md_parse_option): Handle the new options.
	(md_show_usage): Document the `march-attr' option.
	* config/tc-riscv.h (md_end): Define as riscv_md_end
	(riscv_md_end): Declare.
	(CONVERT_SYMBOLIC_ATTRIBUTE): Define as
	riscv_convert_symbolic_attribute.
	(riscv_convert_symbolic_attribute): Declare.
	(start_assemble): Declare.
	* testsuite/gas/elf/elf.exp: Adjust test case for section2.e.
	* testsuite/gas/elf/section2.e-riscv: New.
	* testsuite/gas/riscv/attribute-01.d: New test
	* testsuite/gas/riscv/attribute-02.d: Likewise.
	* testsuite/gas/riscv/attribute-03.d: Likewise.
	* testsuite/gas/riscv/attribute-04.d: Likewise.
	* testsuite/gas/riscv/attribute-04.s: Likewise.
	* testsuite/gas/riscv/attribute-05.d: Likewise.
	* testsuite/gas/riscv/attribute-05.s: Likewise.
	* testsuite/gas/riscv/attribute-06.d: Likewise.
	* testsuite/gas/riscv/attribute-06.s: Likewise.
	* testsuite/gas/riscv/attribute-07.d: Likewise.
	* testsuite/gas/riscv/attribute-07.s: Likewise.
	* testsuite/gas/riscv/attribute-08.d: Likewise.
	* testsuite/gas/riscv/attribute-08.s: Likewise.
	* testsuite/gas/riscv/attribute-unknown.d: Likewise.
	* testsuite/gas/riscv/attribute-unknown.s: Likewise.
	* testsuite/gas/riscv/empty.l: Likewise.
	* doc/c-riscv.texi (.attribute): Add documentation.
	* configure.ac (--enable-default-riscv-attribute): New options.
	* configure: Re-generate.
	* config.in: Re-generate.
	include/
	* elf/riscv.h (SHT_RISCV_ATTRIBUTES): Define.
	(Tag_RISCV_arch): Likewise.
	(Tag_RISCV_priv_spec): Likewise.
	(Tag_RISCV_priv_spec_minor): Likewise.
	(Tag_RISCV_priv_spec_revision): Likewise.
	(Tag_RISCV_unaligned_access): Likewise.
	(Tag_RISCV_stack_align): Likewise.
2019-01-16 13:14:59 -08:00

136 lines
4.4 KiB
C

/* RISC-V ELF support for BFD.
Copyright (C) 2011-2019 Free Software Foundation, Inc.
Contributed by Andrew Waterman (andrew@sifive.com).
Based on MIPS ELF support for BFD, by Ian Lance Taylor.
This file is part of BFD, the Binary File Descriptor library.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program 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 a copy of the GNU General Public License
along with this program; see the file COPYING3. If not,
see <http://www.gnu.org/licenses/>. */
/* This file holds definitions specific to the RISCV ELF ABI. Note
that most of this is not actually implemented by BFD. */
#ifndef _ELF_RISCV_H
#define _ELF_RISCV_H
#include "elf/reloc-macros.h"
#include "libiberty.h"
/* Relocation types. */
START_RELOC_NUMBERS (elf_riscv_reloc_type)
/* Relocation types used by the dynamic linker. */
RELOC_NUMBER (R_RISCV_NONE, 0)
RELOC_NUMBER (R_RISCV_32, 1)
RELOC_NUMBER (R_RISCV_64, 2)
RELOC_NUMBER (R_RISCV_RELATIVE, 3)
RELOC_NUMBER (R_RISCV_COPY, 4)
RELOC_NUMBER (R_RISCV_JUMP_SLOT, 5)
RELOC_NUMBER (R_RISCV_TLS_DTPMOD32, 6)
RELOC_NUMBER (R_RISCV_TLS_DTPMOD64, 7)
RELOC_NUMBER (R_RISCV_TLS_DTPREL32, 8)
RELOC_NUMBER (R_RISCV_TLS_DTPREL64, 9)
RELOC_NUMBER (R_RISCV_TLS_TPREL32, 10)
RELOC_NUMBER (R_RISCV_TLS_TPREL64, 11)
/* Relocation types not used by the dynamic linker. */
RELOC_NUMBER (R_RISCV_BRANCH, 16)
RELOC_NUMBER (R_RISCV_JAL, 17)
RELOC_NUMBER (R_RISCV_CALL, 18)
RELOC_NUMBER (R_RISCV_CALL_PLT, 19)
RELOC_NUMBER (R_RISCV_GOT_HI20, 20)
RELOC_NUMBER (R_RISCV_TLS_GOT_HI20, 21)
RELOC_NUMBER (R_RISCV_TLS_GD_HI20, 22)
RELOC_NUMBER (R_RISCV_PCREL_HI20, 23)
RELOC_NUMBER (R_RISCV_PCREL_LO12_I, 24)
RELOC_NUMBER (R_RISCV_PCREL_LO12_S, 25)
RELOC_NUMBER (R_RISCV_HI20, 26)
RELOC_NUMBER (R_RISCV_LO12_I, 27)
RELOC_NUMBER (R_RISCV_LO12_S, 28)
RELOC_NUMBER (R_RISCV_TPREL_HI20, 29)
RELOC_NUMBER (R_RISCV_TPREL_LO12_I, 30)
RELOC_NUMBER (R_RISCV_TPREL_LO12_S, 31)
RELOC_NUMBER (R_RISCV_TPREL_ADD, 32)
RELOC_NUMBER (R_RISCV_ADD8, 33)
RELOC_NUMBER (R_RISCV_ADD16, 34)
RELOC_NUMBER (R_RISCV_ADD32, 35)
RELOC_NUMBER (R_RISCV_ADD64, 36)
RELOC_NUMBER (R_RISCV_SUB8, 37)
RELOC_NUMBER (R_RISCV_SUB16, 38)
RELOC_NUMBER (R_RISCV_SUB32, 39)
RELOC_NUMBER (R_RISCV_SUB64, 40)
RELOC_NUMBER (R_RISCV_GNU_VTINHERIT, 41)
RELOC_NUMBER (R_RISCV_GNU_VTENTRY, 42)
RELOC_NUMBER (R_RISCV_ALIGN, 43)
RELOC_NUMBER (R_RISCV_RVC_BRANCH, 44)
RELOC_NUMBER (R_RISCV_RVC_JUMP, 45)
RELOC_NUMBER (R_RISCV_RVC_LUI, 46)
RELOC_NUMBER (R_RISCV_GPREL_I, 47)
RELOC_NUMBER (R_RISCV_GPREL_S, 48)
RELOC_NUMBER (R_RISCV_TPREL_I, 49)
RELOC_NUMBER (R_RISCV_TPREL_S, 50)
RELOC_NUMBER (R_RISCV_RELAX, 51)
RELOC_NUMBER (R_RISCV_SUB6, 52)
RELOC_NUMBER (R_RISCV_SET6, 53)
RELOC_NUMBER (R_RISCV_SET8, 54)
RELOC_NUMBER (R_RISCV_SET16, 55)
RELOC_NUMBER (R_RISCV_SET32, 56)
RELOC_NUMBER (R_RISCV_32_PCREL, 57)
END_RELOC_NUMBERS (R_RISCV_max)
/* Processor specific flags for the ELF header e_flags field. */
/* File may contain compressed instructions. */
#define EF_RISCV_RVC 0x0001
/* Which floating-point ABI a file uses. */
#define EF_RISCV_FLOAT_ABI 0x0006
/* File uses the soft-float ABI. */
#define EF_RISCV_FLOAT_ABI_SOFT 0x0000
/* File uses the single-float ABI. */
#define EF_RISCV_FLOAT_ABI_SINGLE 0x0002
/* File uses the double-float ABI. */
#define EF_RISCV_FLOAT_ABI_DOUBLE 0x0004
/* File uses the quad-float ABI. */
#define EF_RISCV_FLOAT_ABI_QUAD 0x0006
/* File uses the 32E base integer instruction. */
#define EF_RISCV_RVE 0x0008
/* The name of the global pointer symbol. */
#define RISCV_GP_SYMBOL "__global_pointer$"
/* Additional section types. */
#define SHT_RISCV_ATTRIBUTES 0x70000003 /* Section holds attributes. */
/* Object attributes. */
enum
{
/* 0-3 are generic. */
Tag_RISCV_stack_align = 4,
Tag_RISCV_arch = 5,
Tag_RISCV_unaligned_access = 6,
Tag_RISCV_priv_spec = 8,
Tag_RISCV_priv_spec_minor = 10,
Tag_RISCV_priv_spec_revision = 12
};
#endif /* _ELF_RISCV_H */