From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 08D0B3870895 for ; Tue, 30 Jan 2024 12:32:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 08D0B3870895 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 08D0B3870895 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706617957; cv=none; b=Fv4Ki4xu8CcnwNgiXRKLqHHoZ6mW26tmY5SmDrOiA3CUf2YgF7SVxbf8Efr5xNL81Afx4VLA585rGnq8PBU6k+AV89wnezf665eJ3agqpOT25llXk0T2mQhL5082NLra0WFPe+6RiwEbLUUdcDS07rr511yFZuJg7vUB5+OD1JI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706617957; c=relaxed/simple; bh=hoZ33F7kdVZavB8x+FQ9pwEu5jb0P4HNpWFvzyC5Zus=; h=DKIM-Signature:From:Message-Id:Mime-Version:Subject:Date:To; b=POc124s54TAp5WaOcSMM3HGEsQIxOfx1iaZ6Lx0kaMUDVCHhqwpa24HRPdBIYwKBhMG3Y0BcEYk+N3yclh74ZJ+EifQU8JHkeDsjZH7TSUng/zG4fHvifdnSciODEBFpI9k46BNnOGPOWnOk7712pBbkgmHnvzqbwo/b/FtZvqw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-5d8df34835aso818936a12.0 for ; Tue, 30 Jan 2024 04:32:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1706617951; x=1707222751; darn=sourceware.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=4QFqAV7mRFfBT0cc8+XReDXOJ/6TzmD8TTlSFnui6HY=; b=iTyaxGPb2qRx8QsgNjSvsBfoF+3a8RWFtxiskFHos8o7P/S3WxcmWJ6gq1mdn8nlDc QqGayRB9mpySgrXTy5qTEuVlGDgTFa+j1XvLIbIyO5eN/hc0DAqPdMZOA7dXL4zRVnYV Qoy05MBkd3hyVTWD7QhtCBy9e2W9IoROH6ihA38XJ9K/8YhvzJFH95OKOSHe1klQ1vM2 G/PQ7zk2MMo+syfOH9BknPh6aHzDuarB7qNiq3BRc64oN6ApGxdiDq9KsJykeHRwsb0a 1XRMyeWiTMbqUyolCWw2Rxf383Vd2xECzW4NwXxobM5G/ELwi89+u8Vtd/fVAbZQroXu cF5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706617951; x=1707222751; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4QFqAV7mRFfBT0cc8+XReDXOJ/6TzmD8TTlSFnui6HY=; b=vLEwNk4v5ZvQqV6hioluGj3yRO34i8AAtQdQVeJJ893sLbZB7fhiLH13tz+cM1UpK1 bu+2Sx6LrdixyTjP0mTPzPQaF2uGGRpHhWn+zVPZeCVSzY0jCWP1AvzX8K5l4UrHWUFD Ud0gAYVwD/GfvlzgoixUIupVRqpB4We7ysPbiMv10suRpXw0E7/rkSmT8oF2gQGqKRhp 73PcWnfdkkWjjoeK7fH/gZfhDtINYZHpVPNtrW9nDcDtkiEPXzLUwqnT/DLf6zE/9Y8M 6GByjzs+66o0jeIYsl7pMQIT0G3VKBXVD7FIFnLUX9Nggiv07mhm6OE4ztxWZWvVJI3v mdgw== X-Gm-Message-State: AOJu0YxomrpQS1/UMUQckM0Uj4o+bVs4yDjbeKhWkvzF8gwAUegV1qis RFpr3z1i+G0NnpuTic3h+0o6a0faUpWIUKs70Tg4cqSc279ibjx7EV9Ry9V5kCREoSuga4kACzn TrXU= X-Google-Smtp-Source: AGHT+IHUzGWAMJEI9Tf3Ryevyoe0blNOKmr1PA0X9GsI/Pe7Zr+vap4PBSGYw/rjVdoBJeTYaSHu6Q== X-Received: by 2002:a05:6a20:3d01:b0:19c:ad53:2aff with SMTP id y1-20020a056a203d0100b0019cad532affmr1747880pzi.37.1706617950898; Tue, 30 Jan 2024 04:32:30 -0800 (PST) Received: from smtpclient.apple (36-238-34-212.dynamic-ip.hinet.net. [36.238.34.212]) by smtp.gmail.com with ESMTPSA id c26-20020a056a00009a00b006ddc75edd55sm7609290pfj.152.2024.01.30.04.32.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jan 2024 04:32:30 -0800 (PST) From: Hau Hsu Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_5A616118-60FC-4F89-B56F-D3B182EEE0F5" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) Subject: Re: [PATCH v2] RISC-V: Add --march=help Date: Tue, 30 Jan 2024 20:32:17 +0800 In-Reply-To: Cc: Binutils To: Tsukasa OI References: <20240130063630.2931301-1-hau.hsu@sifive.com> X-Mailer: Apple Mail (2.3731.700.6) X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,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 List-Id: --Apple-Mail=_5A616118-60FC-4F89-B56F-D3B182EEE0F5 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi Tsukasa, Indeed this idea is from Clang. Let me see if I can have another implementation based on your suggestions. Thanks for your quick reply :). Best, Hau Hsu Software Engineer hau.hsu@sifive.com > Tsukasa OI =E6=96=BC 2024=E5=B9=B41=E6=9C= =8830=E6=97=A5 =E4=B8=8B=E5=8D=884:43 =E5=AF=AB=E9=81=93=EF=BC=9A >=20 > Hi Hau, >=20 > I'm not yet ready to come back to Binutils development (because I > haven't finished writing my research paper) but I'd like to comment. >=20 > While your idea seems great at first glance, I would never like to see > "help" handling in the riscv_parse_subset function because many other > functions call it (some calls this function with an argument retrieved > from an assembly / object file and your design seems vulnerable from > adversarial files e.g. when disassembling files with unknown origin). >=20 > Besides that, I think that's not a bad idea (quite rare to see in the > GNU toolchain, though). >=20 > IMHO, the right place to put "help" handling (at least, its entry point) > is the md_parse_option function in gas/config/tc-riscv.c. Exiting > successfully from here is rare but at least cris and kvx does so for > help-like options. >=20 > Thanks, > Tsukasa >=20 > On 2024/01/30 15:36, Hau Hsu wrote: >> Use --march=3Dhelp to print all supported extensions and versions. >>=20 >> This patch assumes that the supported extensions with the same versions >> are listed together. >>=20 >> For example >> static struct riscv_supported_ext riscv_supported_std_ext[] =3D >> { >> ... >> {"i", ISA_SPEC_CLASS_20191213, 2, 1, 0 }, >> {"i", ISA_SPEC_CLASS_20190608, 2, 1, 0 }, >> {"i", ISA_SPEC_CLASS_2P2, 2, 0, 0 }, >> ... >> }; >>=20 >> For "i" extension, 2.1.0 with different spec class are listed together. >> This patch records the previous printed extension and version. If the >> current extension and version are the same as the previous one, skip >> printing. >>=20 >> Here is part of the output of `as -march=3Dhelp`: >>=20 >> All available -march extensions for RISC-V: >> e 1.9 >> i 2.1, 2.0 >> m 2.0 >> a 2.1, 2.0 >> f 2.2, 2.0 >> d 2.2, 2.0 >> q 2.2, 2.0 >> c 2.0 >> v 1.0 >> h 1.0 >> zicbom 1.0 >> zicbop 1.0 >>=20 >> Signed-off-by: Hau Hsu >> --- >> bfd/ChangeLog | 9 ++++++ >> bfd/elfxx-riscv.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++ >> 2 files changed, 81 insertions(+) >>=20 >> diff --git a/bfd/ChangeLog b/bfd/ChangeLog >> index 97d0c585a56..0807a2e0bcb 100644 >> --- a/bfd/ChangeLog >> +++ b/bfd/ChangeLog >> @@ -1,3 +1,12 @@ >> +2024-01-17 Hau Hsu >> + >> + * elfxx-riscv.c (riscv_parse_subset): Parse 'help' keyword to print >> + available extension and versions. >> + (riscv_print_extensions): New function. >> + (riscv_same_extension_version): New function. >> + (riscv_same_extension_diff_version): New function. >> + (riscv_valid_ext): New function. >> + >> 2024-01-15 Nick Clifton >>=20 >> * 2.42 branch point. >> diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c >> index 9a121b47121..bb394a589b1 100644 >> --- a/bfd/elfxx-riscv.c >> +++ b/bfd/elfxx-riscv.c >> @@ -2051,6 +2051,71 @@ riscv_set_default_arch (riscv_parse_subset_t *rps) >> } >> } >>=20 >> +static >> +bool riscv_same_extension_version( >> + const struct riscv_supported_ext* ext1, >> + const struct riscv_supported_ext* ext2) >> +{ >> + return (strcmp(ext1->name, ext2->name) =3D=3D 0 >> + && ext1->major_version =3D=3D ext2->major_version >> + && ext1->minor_version =3D=3D ext2->minor_version); >> +} >> + >> +static >> +bool riscv_same_extension_diff_version( >> + const struct riscv_supported_ext* ext1, >> + const struct riscv_supported_ext* ext2) >> +{ >> + return (strcmp(ext1->name, ext2->name) =3D=3D 0 >> + && !(ext1->major_version =3D=3D ext2->major_version >> + && ext1->minor_version =3D=3D ext2->minor_version)); >> +} >> + >> +static >> +bool riscv_valid_ext(const struct riscv_supported_ext *ext) >> +{ >> + return (ext->isa_spec_class !=3D ISA_SPEC_CLASS_NONE >> + && ext->major_version !=3D RISCV_UNKNOWN_VERSION >> + && ext->minor_version !=3D RISCV_UNKNOWN_VERSION); >> +} >> + >> +static >> +void riscv_print_extensions(void) >> +{ >> + /* Record the previous pritned extension. >> + Print the current one if they are not the same. */ >> + const struct riscv_supported_ext *cur =3D NULL, *prev =3D NULL; >> + >> + int i, j; >> + printf ("All available -march extensions for RISC-V:"); >> + for (i =3D 0; riscv_all_supported_ext[i] !=3D NULL; i++) >> + { >> + const struct riscv_supported_ext *exts =3D riscv_all_supported_ex= t[i]; >> + prev =3D NULL; >> + for (j =3D 0; exts[j].name !=3D NULL; j++) >> + { >> + cur =3D &exts[j]; >> + if (!riscv_valid_ext (cur)) >> + continue; >> + >> + if (prev && riscv_same_extension_version (prev, cur)) >> + continue; >> + >> + if (!prev || !riscv_same_extension_diff_version (prev, cur)) >> + { >> + printf("\n\t%-40s%d.%d", cur->name, cur->major_version, c= ur->minor_version); >> + prev =3D &exts[j]; >> + } >> + else >> + { >> + printf(", %d.%d", cur->major_version, cur->minor_version); >> + prev =3D &exts[j]; >> + } >> + } >> + } >> + printf ("\n"); >> +} >> + >> /* Function for parsing ISA string. >>=20 >> Return Value: >> @@ -2089,6 +2154,13 @@ riscv_parse_subset (riscv_parse_subset_t *rps, >> } >>=20 >> p =3D arch; >> + /* List all avaiable archs. */ >> + if (strcmp (p, "help") =3D=3D 0) >> + { >> + riscv_print_extensions(); >> + exit (EXIT_SUCCESS); >> + } >> + >> if (startswith (p, "rv32")) >> { >> *rps->xlen =3D 32; --Apple-Mail=_5A616118-60FC-4F89-B56F-D3B182EEE0F5--