[PATCH 1/2 v2] RISC-V: Support ELF attribute for gas and readelf

11 views
Skip to first unread message

Kito Cheng

unread,
Jan 9, 2019, 8:47:39 AM1/9/19
to binu...@sourceware.org, Jim Wilson, pat...@groups.riscv.org, Palmer Dabbelt
This patch implement RISC-V ELF attribute[1] support for assembler and readelf.

Patch tested with 4 different configuration: (rv32gc, rv64gc) x (newlib, glibc)

Change list:
- Fix several typo.
- Fix test failed case on linux target.
- New testcase for testing handling unknown attribute: attribute-unknown.
- New option -march-attr and -mno-arch-attr to control emit arch
attribute by default or not.
- New configure option --enable-default-riscv-attribute to control
the default behavior of -m[no-]arch-attr.
- Note: disable by default in non-bare-mental target
- Change the prefix of attribute to Tag_RISCV_.
- Adjust Tag value to following even/odd rule.
- Remove NO_DEFAULT for y priv_spec, priv_spec_minor, priv_spec_revision,
unsigned_access and stack_align
- .attribute arch must appear before any instruction.
- Note: .attribute arch got higher priority than -march.
- Add document for .attribute.

ChangeLog:
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.

[1] https://github.com/riscv/riscv-elf-psabi-doc/pulls/71
0001-RISC-V-Support-ELF-attribute-for-gas-and-readelf.patch

Jim Wilson

unread,
Jan 13, 2019, 5:34:36 PM1/13/19
to Kito Cheng, Binutils, RISC-V Patches, Palmer Dabbelt
On Wed, Jan 9, 2019 at 5:47 AM Kito Cheng <kito....@gmail.com> wrote:
> This patch implement RISC-V ELF attribute[1] support for assembler and readelf.

The plan is to make the binutils-2.32 branch in a week, and then the
release a week later. That doesn't give much time to deal with large
patches. Is this something that can wait for the next release?

Jim

Kito Cheng

unread,
Jan 14, 2019, 10:21:41 AM1/14/19
to pat...@groups.riscv.org, Binutils, Palmer Dabbelt
> The plan is to make the binutils-2.32 branch in a week, and then the
> release a week later. That doesn't give much time to deal with large
> patches. Is this something that can wait for the next release?

It seems like hard to meet the schedule of binutils, it would be
better if it included in 2.32 since GCC 9 could to use that,
but I think let wait next release cycle is better, we don't
upstream different merge policy yet.

Jim Wilson

unread,
Jan 14, 2019, 7:42:01 PM1/14/19
to Kito Cheng, Binutils, RISC-V Patches, Palmer Dabbelt
On Wed, Jan 9, 2019 at 5:47 AM Kito Cheng <kito....@gmail.com> wrote:
&gt; This patch implement RISC-V ELF attribute[1] support for
assembler and readelf.

It looks nice. Adding the gas command line option and configure
option makes it safer to add the feature this close to a release. If
there is a problem, people can disable it.

In the old code, there is one place that has "p = " which has one too
many spaces after the equal sign, but that is a minor ignorable
problem.

In the new code, I see uses of "RISC-V used arch attribute" that I
think should just be "RISC-V arch attribute". This appears in gas
configure and config/tc-riscv.c patches, including strings printed in
messages.

In the new docs, there are lines over 80 characters in length.

In the .attribute docs, there is a comma missing after
Tag_RISCV_unaligned_access, and a missing period at the end of the
line.

In the Tag_RISCV_arch docs, there are references to "-march" that
should be @option{-march) instead. And I think stuff like "RV32I"
should be @code{RV32I} instead. Basically, anyplace in the docs where
you use double quotes should be @option or @code instead.

In the Tag_RISCV_unaligned_access docs, it uses bullets instead of a
paragraph which is an odd style change in the middle of the
documentation. I think it should be a paragraph like the rest.

There is some stuff in the docs that doesn't look quite right to a
native English speaker, but it is probably easier if I fix that
myself. I could perhaps just fix the other stuff too.

Without the other patch to elf-attrs.c, I get some unresolved
testcases because of readelf errors. WIth that elf-attrs.c patch, I
get some linker failures, but maybe there is a fix for that in the
second part of this patch set. I'll look at the second part next, and
deal with the elf-attrs.c patch separately.

Jim

Kito Cheng

unread,
Jan 15, 2019, 4:09:31 AM1/15/19
to Jim Wilson, Binutils, RISC-V Patches, Palmer Dabbelt
> There is some stuff in the docs that doesn't look quite right to a
> native English speaker, but it is probably easier if I fix that
> myself. I could perhaps just fix the other stuff too.

Really appreciate for format fixing and correct my wired word/sentence,

So I will start to prepare patches for GCC part :)

Jim Wilson

unread,
Jan 15, 2019, 12:41:49 PM1/15/19
to Kito Cheng, Binutils, RISC-V Patches, Palmer Dabbelt
On Tue, Jan 15, 2019 at 1:09 AM Kito Cheng <kito....@gmail.com> wrote:
>
> > There is some stuff in the docs that doesn't look quite right to a
> > native English speaker, but it is probably easier if I fix that
> > myself. I could perhaps just fix the other stuff too.
>
> Really appreciate for format fixing and correct my wired word/sentence,

So just to clarify, is the plan here that I do the minor fixups and
commit the patches?

Jim

Kito Cheng

unread,
Jan 15, 2019, 10:16:19 PM1/15/19
to RISC-V Patches, Binutils, Palmer Dabbelt
> > Really appreciate for format fixing and correct my wired word/sentence,
>
> So just to clarify, is the plan here that I do the minor fixups and
> commit the patches?

I guess you might not in office when I reply, so I'll update a
patch for fix format, and then you fix rest wired English part,
and then you commit the patches for save time.

Thank :)

Kito Cheng

unread,
Jan 16, 2019, 12:01:19 AM1/16/19
to RISC-V Patches, Jim Wilson, Binutils, Palmer Dabbelt
Hi Jim:

There is two patch, one is updated patch[1], and another one[2] is just the
diff of the fixes for easier review/merge.

Thanks!

[1] 0001-RISC-V-Support-ELF-attribute-for-gas-and-readelf.patch
[2] 0001-Fix-format-error-and-sentence.patch
0001-Fix-format-error-and-sentence.patch
0001-RISC-V-Support-ELF-attribute-for-gas-and-readelf.patch

Jim Wilson

unread,
Jan 16, 2019, 4:45:20 PM1/16/19
to Kito Cheng, RISC-V Patches, Binutils, Palmer Dabbelt
On Tue, Jan 15, 2019 at 9:01 PM Kito Cheng <kito....@gmail.com> wrote:
> There is two patch, one is updated patch[1], and another one[2] is just the
> diff of the fixes for easier review/merge.

I committed the 3 patches. I did basic cross testing. I will do some
more testing as the release is coming soon. I plan to do a
riscv-gnu-toolchain regression test, freedom-u-sdk build, and native
testing on my HiFive Unleashed board.

Jim
Reply all
Reply to author
Forward
0 new messages