From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2081.outbound.protection.outlook.com [40.107.20.81]) by sourceware.org (Postfix) with ESMTPS id AC8F63850877 for ; Fri, 10 Mar 2023 09:28:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AC8F63850877 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KfjlUXsXUxJ2YydmIRWI6nAm4hFZpD19br7tjTd7HuEjcq1u5tVse7r8UE3YAhwzmRN2k591TufxsMuRxrh3XGpz4ZmaWVxXV1DJbustZMK9R9UjBAILdlOmuEXR2tp9Hfqrj7NvbyUjen5KRTCxK1S9XuDOpaxZG0QcSYJPs3OLn1eja68WhxZhO/xgf8WodTwJzQZw/cI65EMF1k5HwjMchchOqwzXTVZLLTuvBEZqRh8vzjHf28duO1WpcBG//nDeebk3LRXSPJ+ZPlBligtHDRWhvaMAWBDt5Pv13ekR4KfeqfH94vBkTYwBruAPq1Cd9TgOEGDelw0VBy8+xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VdvIqSTnpWhvXaHKo3jOzIbXnq5M8GEwk/8xtdGCxCw=; b=BpDVPtrbEG9lEbGiftzyhfWVxJfo16At48tCPJhkpvCymV9LqG3kiK9+GkXEH4k5aCvbjMqT3wSKDTUuUNLeJ0Jtd5cFE0PdRBQiRALDssjyJLBR0Ya47qZJUNW4+wBz3cbxG/hMBe2rj2TYGOXlmGcdDCbA/GvtRl4sIdlStcFA8kxTwPsupj9VnpKMah3E+TiepiPYvSJ/oGCV5lIOBCYCpLzEb08yotjqc0PtaKwWk1zZQud6pncK0RozwF0Bka/TAQSxTkj24AP72tojrXKs6bJSV8TPUVAxJC2F2tFW6RG+Q4zkk8rZOU5ibTx5SgVG1eUN4GJAeLXdYhaOtg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VdvIqSTnpWhvXaHKo3jOzIbXnq5M8GEwk/8xtdGCxCw=; b=FvZSplZupdmVUVTGiVikeVOe/mVY9jJJRdrpXcHmqfS38kihaNmplopeFDQ2V7JNPF06oqp6id1yvs/isMLCc14XvxoO8LALayiWSvdQ5uLam7fJ1TH9Vz2Hn/+Xyc2v4MRKZQ/nGx6VefVrrlf6kfyPUciP8oyVspUaWP4KMVSg0vD6GogUq+MPXoaULECLOVckLlUqDYnVgGAe7AYKqhnp46g51vXaMkjigatFfIJ8wAjX24s9OtPcBb/J6l2/gfkLnwBXDV/fJamIAZAnQSbFNMJT14YSyzlUAqJNbSsyg/B5B5VZXHvH16hKfm/nn0pwHHp5QtoJ9vgYKr3FqA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by PA4PR04MB9464.eurprd04.prod.outlook.com (2603:10a6:102:2ac::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.19; Fri, 10 Mar 2023 09:28:25 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::154e:166d:ec25:531b]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::154e:166d:ec25:531b%5]) with mapi id 15.20.6178.019; Fri, 10 Mar 2023 09:28:25 +0000 Message-ID: <54b0d4cc-855a-78c7-5233-22f7d454c0c4@suse.com> Date: Fri, 10 Mar 2023 10:28:23 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: [PATCH v2 7/7] RISC-V: adjust logic to avoid register name symbols Content-Language: en-US To: Binutils Cc: Palmer Dabbelt , Andrew Waterman , Jim Wilson , Nelson Chu References: From: Jan Beulich In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: FR3P281CA0142.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:95::16) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR04MB6560:EE_|PA4PR04MB9464:EE_ X-MS-Office365-Filtering-Correlation-Id: ca9b3d81-739e-408c-89fe-08db2149cc5b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: w5p8VYoBItuz/4GkWm2mdHsJ9guGI+6dz4beAfIS9Jca5t3RfioVYiTDlcelsd2eLvkpyamy2mWt8hnTVFZzfp4OMC8TRgggo/EG3gI6g4hDRcYTTaiVBNK9YMAT60SXr+rmL22ZkSjY/LRoLRUjX33pgsAJJV1PwEllrNGc02/IdE7AwhpfunH9eir8pkJy58b1AYptbxmYg8ECnPJcNFHZYX04jXPOKRg2rC/psph4TUzaS0rhViHFao9jQOYVzI9NwhaVGCjc7h2i1PG5ZPBfQDsnpHKkHH/psJZxoESKGjXCcVL6YmsexIvzqsAAkNRGGewz3dbUpdOQpOAEC39uKXKQPDo7mgCsv3WYBEC0XkNojgoyU/wCQytEt7IwicpGVkuyeJcVPLFEqzCx0A7nLQw8wDLEMIt1in8Db+PwSmteHLEAoxpT6K0JOwUHHN+ijqIxYs+vhy8XeX4Wxp9k603WVEAQKpoFDXDyXvDYwUn4RK13Vl2FNroLGHNADZ1GmdZqOoKIBR/pWdwIGPk0rAVG9I3qhBViuerQN1NUoSbVpD6VXp4L9/qziVCRWS5XFTD7JuV2eGcBhVbgkmyA/N4LPfjbWCCL0oOQFaqIxPc519wqasabBUDH71Ov4YgRb7JDmK5yJbjBQcYl1YXN3odybJMjJOex+PgPhqiL9NfadeodgZr22gCMeuWNZ6O9XWgcWOgNYEAawe8lThmfGWkg3c1qZYwks4Buecc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6560.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(346002)(366004)(39860400002)(396003)(136003)(376002)(451199018)(36756003)(54906003)(478600001)(6486002)(316002)(5660300002)(2906002)(8936002)(66946007)(66476007)(8676002)(66556008)(4326008)(41300700001)(6916009)(31696002)(86362001)(38100700002)(186003)(2616005)(6506007)(26005)(6512007)(83380400001)(31686004)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?SXdCaW9aVEZpVUxXVjRMb1dOc3pkdHJGd2puYXY3ZFlCMktlUTNtc2ZoY0Nq?= =?utf-8?B?OWxQWHRuRFZ3WFhqcXU4aEZoSlV6VGVjUDQrb01aUlYvaEtZQ0xya3ltdm5B?= =?utf-8?B?S2N5djZVS1RqSFBBTjkreXBteW5vZE5ZK3J4WGVjeHphVisrWVJHZ3pNZ3hH?= =?utf-8?B?SGt6TTd2cFNkUzdBQllSYjlKRlNsOFF0NFV4T1YwK2d6d3NQbVVUVlZ2MGdy?= =?utf-8?B?bnQ0T1NlbzdTYWNnTm5QOHlmUTlBZVMwVmlNMlVrcVkzaW9JcUZvOEpXSW5F?= =?utf-8?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nNQNllmeHlnd2xaZFNlTnN1aXR6UHRS?= =?utf-8?Q?dZiYyQ+FJAoH7i3W97cBvLDSO?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: ca9b3d81-739e-408c-89fe-08db2149cc5b X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2023 09:28:25.3718 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: rC3z0zIBhugnG2sEo4k/eEeKJDqU+1qq8zTHaN8ELHG9rOHYrhj/wJnxaOcXcFztH8Wk0kC1f/9nprMw0MFIaA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB9464 X-Spam-Status: No, score=-3028.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,TXREP 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: Special casing GPR names in my_getSmallExpression() leads to a number of inconsistencies. Generalize this by utilizing the md_parse_name() hook, limited to when instruction operands are being parsed (really: probed). Then both the GPR lookup there and the yet more ad hoc workaround for PR/gas 29940 can be removed (including its extension needed for making the compressed form JAL work again). --- When a floating point extension (but not [hfdq]inx) is enabled, floating point registers would perhaps better be recognized by riscv_parse_name() as well. Same for vector registers and likely also CSRs. Otherwise inconsistent behavior may (continue to) result when equates come into play, afaict. Considering equates, the new behavior isn't the only sensible one: We could also omit the symbol_find() call, thus never honoring equates. Then, however, even with the "i" insn suffix (or sometimes infix) explicitly specified, equates with names matching a GPR name (or, see above, potentially also other register names) wouldn't be accepted anymore. I guess the primary question here is what the intended (and consistent) behavior is to be. Overall the uses of my_getSmallExpression() vs my_getExpression() look pretty random to me: Is there any underlying principle when which of the two is expected to be used? --- v2: Re-work to not break things like %hi(). --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -171,6 +171,8 @@ static enum float_abi float_abi = FLOAT_ static unsigned elf_flags = 0; +static bool probing_insn_operands; + /* Set the default_isa_spec. Return 0 if the spec isn't supported. Otherwise, return 1. */ @@ -2228,21 +2230,10 @@ my_getSmallExpression (expressionS *ep, char *str, const struct percent_op_match *percent_op) { size_t reloc_index; - unsigned crux_depth, str_depth, regno; + unsigned crux_depth, str_depth; + bool orig_probing = probing_insn_operands; char *crux; - /* First, check for integer registers. No callers can accept a reg, but - we need to avoid accidentally creating a useless undefined symbol below, - if this is an instruction pattern that can't match. A glibc build fails - if this is removed. */ - if (reg_lookup (&str, RCLASS_GPR, ®no)) - { - ep->X_op = O_register; - ep->X_add_number = regno; - expr_parse_end = str; - return 0; - } - /* Search for the start of the main expression. End the loop with CRUX pointing to the start of the main expression and @@ -2274,9 +2265,17 @@ my_getSmallExpression (expressionS *ep, return 0; } + /* Anything inside parentheses or subject to a relocation operator cannot + be a register and hence can be treated the same as operands to + directives (other than .insn). */ + if (str_depth || reloc_index) + probing_insn_operands = false; + my_getExpression (ep, crux); str = expr_parse_end; + probing_insn_operands = orig_probing; + /* Match every open bracket. */ while (crux_depth > 0 && (*str == ')' || *str == ' ' || *str == '\t')) if (*str++ == ')') @@ -2462,6 +2461,13 @@ riscv_is_priv_insn (insn_t insn) || ((insn ^ MATCH_SFENCE_VM) & MASK_SFENCE_VM) == 0); } +static symbolS *deferred_sym_rootP; +static symbolS *deferred_sym_lastP; +/* Since symbols can't easily be freed, try to recycle ones which weren't + committed. */ +static symbolS *orphan_sym_rootP; +static symbolS *orphan_sym_lastP; + /* This routine assembles an instruction into its binary format. As a side effect, it sets the global variable imm_reloc to the type of relocation to do if one of the operands is an address expression. */ @@ -2497,6 +2503,8 @@ riscv_ip (char *str, struct riscv_cl_ins insn = (struct riscv_opcode *) str_hash_find (hash, str); + probing_insn_operands = true; + asargStart = asarg; for ( ; insn && insn->name && strcmp (insn->name, str) == 0; insn++) { @@ -2513,6 +2521,17 @@ riscv_ip (char *str, struct riscv_cl_ins /* Reset error message of the previous round. */ error.msg = _("illegal operands"); error.missing_ext = NULL; + + /* Purge deferred symbols from the previous round, if any. */ + while (deferred_sym_rootP) + { + symbolS *sym = deferred_sym_rootP; + + symbol_remove (sym, &deferred_sym_rootP, &deferred_sym_lastP); + symbol_append (sym, orphan_sym_lastP, &orphan_sym_rootP, + &orphan_sym_lastP); + } + create_insn (ip, insn); imm_expr->X_op = O_absent; @@ -2567,9 +2586,22 @@ riscv_ip (char *str, struct riscv_cl_ins } if (*asarg != '\0') break; + /* Successful assembly. */ error.msg = NULL; insn_with_csr = false; + + /* Commit deferred symbols, if any. */ + while (deferred_sym_rootP) + { + symbolS *sym = deferred_sym_rootP; + + symbol_remove (sym, &deferred_sym_rootP, + &deferred_sym_lastP); + symbol_append (sym, symbol_lastP, &symbol_rootP, + &symbol_lastP); + symbol_table_insert (sym); + } goto out; case 'C': /* RVC */ @@ -2773,8 +2805,6 @@ riscv_ip (char *str, struct riscv_cl_ins case 'p': goto branch; case 'a': - if (oparg == insn->args + 1) - goto jump_check_gpr; goto jump; case 'S': /* Floating-point RS1 x8-x15. */ if (!reg_lookup (&asarg, RCLASS_FPR, ®no) @@ -3278,18 +3308,6 @@ riscv_ip (char *str, struct riscv_cl_ins continue; case 'a': /* 20-bit PC-relative offset. */ - /* Like in my_getSmallExpression() we need to avoid emitting - a stray undefined symbol if the 1st JAL entry doesn't match, - but the 2nd (with 2 operands) might. */ - if (oparg == insn->args) - { - jump_check_gpr: - asargStart = asarg; - if (reg_lookup (&asarg, RCLASS_GPR, NULL) - && (*asarg == ',' || (ISSPACE (*asarg) && asarg[1] == ','))) - break; - asarg = asargStart; - } jump: my_getExpression (imm_expr, asarg); asarg = expr_parse_end; @@ -3512,6 +3530,8 @@ riscv_ip (char *str, struct riscv_cl_ins if (save_c) *(asargStart - 1) = save_c; + probing_insn_operands = false; + return error; } @@ -3808,6 +3828,53 @@ riscv_after_parse_args (void) flag_dwarf_cie_version = 3; } +bool riscv_parse_name (const char *name, struct expressionS *ep, + enum expr_mode mode) +{ + unsigned int regno; + symbolS *sym; + + if (!probing_insn_operands) + return false; + + gas_assert (mode == expr_normal); + + regno = reg_lookup_internal (name, RCLASS_GPR); + if (regno == (unsigned int)-1) + return false; + + if (symbol_find (name) != NULL) + return false; + + /* Create a symbol without adding it to the symbol table yet. + Insertion will happen only once we commit to using the insn + we're probing operands for. */ + for (sym = deferred_sym_rootP; sym; sym = symbol_next (sym)) + if (strcmp (name, S_GET_NAME (sym)) == 0) + break; + if (!sym) + { + for (sym = orphan_sym_rootP; sym; sym = symbol_next (sym)) + if (strcmp (name, S_GET_NAME (sym)) == 0) + { + symbol_remove (sym, &orphan_sym_rootP, &orphan_sym_lastP); + break; + } + if (!sym) + sym = symbol_create (name, undefined_section, + &zero_address_frag, 0); + + symbol_append (sym, deferred_sym_lastP, &deferred_sym_rootP, + &deferred_sym_lastP); + } + + ep->X_op = O_symbol; + ep->X_add_symbol = sym; + ep->X_add_number = 0; + + return true; +} + long md_pcrel_from (fixS *fixP) { --- a/gas/config/tc-riscv.h +++ b/gas/config/tc-riscv.h @@ -123,6 +123,10 @@ extern void riscv_elf_final_processing ( /* Adjust debug_line after relaxation. */ #define DWARF2_USE_FIXED_ADVANCE_PC 1 +#define md_parse_name(name, exp, mode, c) \ + riscv_parse_name (name, exp, mode) +bool riscv_parse_name (const char *, struct expressionS *, enum expr_mode); + #define md_finish riscv_md_finish #define CONVERT_SYMBOLIC_ATTRIBUTE riscv_convert_symbolic_attribute