From patchwork Wed Sep 20 08:31:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rui Ueyama X-Patchwork-Id: 142284 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3972039vqi; Wed, 20 Sep 2023 01:34:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHnwuaaYVCGoRpQ7yRXT09pRxeiuVBefAUNpwakGK7nImKN2943k4M2UF6FY2CZUTQX2Bre X-Received: by 2002:a17:906:30c6:b0:9a2:2635:dab6 with SMTP id b6-20020a17090630c600b009a22635dab6mr1476688ejb.47.1695198858457; Wed, 20 Sep 2023 01:34:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695198858; cv=none; d=google.com; s=arc-20160816; b=lRmyn5Hy817zP5iEdFh0J7jcuEfZAKNFCnwWbeGrIY7WCbz4t/6FDSo+XNWrsQyjwn 6rWb8/wDd/1l/go/oEu3ziM3c/IZj5vRgH0dgKJk7USFO+TthNSEyilx3ityO+Bx/22T KMJfR3GAz14G8HqOCfqpPsjDx45pv9478QTo8gKMZrLVufZiItJsWmlagBZJLZRfbLcJ /ux6pT815XbUkD/rppdbZK0EyvQYR/bUu9+DzWGMcKbaddXIQnh4XstkqdJ8frAONLkH QwW5BUMHlGzySHn4u2O/gGWTHyEFPKq5zmBGi6v3MH+bkmw/tyHu+PqLldCbXpN+5zjy jHlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=aFvZRF6qBGlV+u2y9TV/y2vyJmd9qPT9jMYNLxApxV4=; fh=bp9mo9iCXv6C7RhrBIO+KljoEd+5s3FX9oLfVrowl5g=; b=bcNa9gWRF/mvZ9xlEjrFo85GbTI4LlvR36HGsBn5hbbpC0iNP2vNIHTiP5FExuOcWm QrB3zk5w9Zw6JKtodOzPNrErhSFuXQLxHgLmqscnSQm4Y8NqOeNs9CXfcLqu1m0I+5nh 86RXb9T4uOHtjwyO2rkpTWl/oxrgBgbotbutAX6g5EfKZQznsmuL7RlqHC4IH9bFjIL+ 3zJrO0OLK2458mwGU4HeKpMpCUZ5etDNA3UKSgtaj1A6g8yZGCS4eZK83LPAwqMm79AC 34RP47mNwsj7OLeeEjIKNp+nbctpoLrkjLS+NqddBqvI+LweHU/v1p8g7kpekHQYy76W Ou+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=qqX14zah; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g18-20020a1709063b1200b0099b53d41849si10836303ejf.506.2023.09.20.01.34.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 01:34:18 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=qqX14zah; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1844B38582B7 for ; Wed, 20 Sep 2023 08:34:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1844B38582B7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695198857; bh=aFvZRF6qBGlV+u2y9TV/y2vyJmd9qPT9jMYNLxApxV4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=qqX14zahjPocVzJxg5E9YoGGoThRAFfkRGsFzbJFIcn3aP1mSdFfzA+UDKeFqY7iq iB7La+MuGygIPpzrXT7h5JHe5MfvALDrWvtp+TsBNt6C0VkId4h3YVCTz72SxLAxZx qFgvrZkW4Usjp/1kdTssoKJPTb56FDyUhs+7ELj0= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id B9E213858D39 for ; Wed, 20 Sep 2023 08:34:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9E213858D39 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1c4194f7635so4793115ad.0 for ; Wed, 20 Sep 2023 01:34:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695198840; x=1695803640; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aFvZRF6qBGlV+u2y9TV/y2vyJmd9qPT9jMYNLxApxV4=; b=Y+pR0Sci7BBJB4YD13F2wH+CSZ/QsvjuAX77tBSjqcLGoU1wCqnavweAisw/wUgyaR cgmIcK+DrN8y0MohEc4QMadsGxthEA8xlJApxpJpsvn19imlzbG+czT0pTE5nRJzrriQ bpGkPgJUnHofc9iK4mWGYqglveT3/TOYwvvdIQgbEYi+ZnZv0X1HeuPRP+E4S9i6kvGR 3MHEKLBLpPnQhwA/WJPdubrovxBFCuCMVa/UmdubGy8xSs55AnhlOAzOtESNEYivqgxK PlabfUvGw6Fx81HfvyQ+L0JiAY2/3vzaz2iQ7uy9bTbcSltawPIzFyycozHwB9ng+EJM nSEQ== X-Gm-Message-State: AOJu0Yyv5rXKomF4VA04++smHAPC83ZewMDr/5CCZRqKO6sgKinEnDcL KO9RFf5W4odQkERn4Vpz16/G/JaxuFM= X-Received: by 2002:a17:903:1c1:b0:1c3:e2eb:f79d with SMTP id e1-20020a17090301c100b001c3e2ebf79dmr6813429plh.8.1695198840051; Wed, 20 Sep 2023 01:34:00 -0700 (PDT) Received: from blue.flets-east.jp ([2405:6580:8dc0:3c00:bf3f:9318:f978:c133]) by smtp.gmail.com with ESMTPSA id n6-20020a170902e54600b001b694140d96sm11312573plf.170.2023.09.20.01.33.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 01:33:59 -0700 (PDT) X-Google-Original-From: Rui Ueyama To: Nelson Chu Cc: binutils@sourceware.org, Rui Ueyama Subject: [PATCH v2] RISC-V: emit R_RISCV_RELAX for the la pseudo instruction Date: Wed, 20 Sep 2023 17:31:26 +0900 Message-Id: <20230920083124.2072273-1-ruiu@bluewhale.systems> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Rui Ueyama via Binutils From: Rui Ueyama Reply-To: Rui Ueyama Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777448467770640568 X-GMAIL-MSGID: 1777544838439369762 Now the macro identifier is stored to tc_fix_data if a relocation is created as a result of assembler macro expansion. --- gas/config/tc-riscv.c | 15 +++++++++++++++ gas/config/tc-riscv.h | 8 ++++++++ gas/testsuite/gas/riscv/la-variants.d | 3 +++ 3 files changed, 26 insertions(+) diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c index 3b520ad208b..c761b793afc 100644 --- a/gas/config/tc-riscv.c +++ b/gas/config/tc-riscv.c @@ -59,6 +59,9 @@ struct riscv_cl_insn fixS *fixp; }; +/* The identifier of the assembler macro we are expanding, if any. */ +static int source_macro = -1; + /* All RISC-V CSR belong to one of these classes. */ enum riscv_csr_class { @@ -1659,6 +1662,7 @@ append_insn (struct riscv_cl_insn *ip, expressionS *address_expr, address_expr, false, reloc_type); ip->fixp->fx_tcbit = riscv_opts.relax; + ip->fixp->tc_fix_data.source_macro = source_macro; } } @@ -2020,6 +2024,8 @@ macro (struct riscv_cl_insn *ip, expressionS *imm_expr, int rs2 = (ip->insn_opcode >> OP_SH_RS2) & OP_MASK_RS2; int mask = ip->insn_mo->mask; + source_macro = mask; + switch (mask) { case M_LI: @@ -2168,6 +2174,8 @@ macro (struct riscv_cl_insn *ip, expressionS *imm_expr, as_bad (_("internal: macro %s not implemented"), ip->insn_mo->name); break; } + + source_macro = -1; } static const struct percent_op_match percent_op_utype[] = @@ -4049,6 +4057,13 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) break; case BFD_RELOC_RISCV_GOT_HI20: + /* R_RISCV_GOT_HI20 and the following R_RISCV_LO12_I are relaxable + only if it is created as a result of la or lga assembler macros. */ + if (fixP->tc_fix_data.source_macro == M_LA || + fixP->tc_fix_data.source_macro == M_LGA) + relaxable = true; + break; + case BFD_RELOC_RISCV_ADD8: case BFD_RELOC_RISCV_ADD16: case BFD_RELOC_RISCV_ADD32: diff --git a/gas/config/tc-riscv.h b/gas/config/tc-riscv.h index 0c70c7d4739..4fba3a07829 100644 --- a/gas/config/tc-riscv.h +++ b/gas/config/tc-riscv.h @@ -101,6 +101,14 @@ extern void riscv_pre_output_hook (void); #define TC_FORCE_RELOCATION_LOCAL(FIX) 1 #define DIFF_EXPR_OK 1 +struct riscv_fix +{ + int source_macro; +}; + +#define TC_FIX_TYPE struct riscv_fix +#define TC_INIT_FIX_DATA(FIX) (FIX)->tc_fix_data.source_macro = -1 + extern void riscv_pop_insert (void); #define md_pop_insert() riscv_pop_insert () diff --git a/gas/testsuite/gas/riscv/la-variants.d b/gas/testsuite/gas/riscv/la-variants.d index b1d316983b7..e8ac09c2af2 100644 --- a/gas/testsuite/gas/riscv/la-variants.d +++ b/gas/testsuite/gas/riscv/la-variants.d @@ -21,11 +21,13 @@ Disassembly of section .text: [ ]+[0-9a-f]+:[ ]+R_RISCV_RELAX[ ]+\*ABS\* [ ]+[0-9a-f]+:[ ]+00000617[ ]+auipc[ ]+a2,0x0 [ ]+[0-9a-f]+:[ ]+R_RISCV_GOT_HI20[ ]+a +[ ]+[0-9a-f]+:[ ]+R_RISCV_RELAX[ ]+\*ABS\* [ ]+[0-9a-f]+:[ ]+(00062603|00063603)[ ]+(lw|ld)[ ]+a2,0\(a2\).* [ ]+[0-9a-f]+:[ ]+R_RISCV_PCREL_LO12_I[ ]+\.L0[ ]+ [ ]+[0-9a-f]+:[ ]+R_RISCV_RELAX[ ]+\*ABS\* [ ]+[0-9a-f]+:[ ]+00000697[ ]+auipc[ ]+a3,0x0 [ ]+[0-9a-f]+:[ ]+R_RISCV_GOT_HI20[ ]+a +[ ]+[0-9a-f]+:[ ]+R_RISCV_RELAX[ ]+\*ABS\* [ ]+[0-9a-f]+:[ ]+(0006a683|0006b683)[ ]+(lw|ld)[ ]+a3,0\(a3\).* [ ]+[0-9a-f]+:[ ]+R_RISCV_PCREL_LO12_I[ ]+\.L0[ ]+ [ ]+[0-9a-f]+:[ ]+R_RISCV_RELAX[ ]+\*ABS\* @@ -37,6 +39,7 @@ Disassembly of section .text: [ ]+[0-9a-f]+:[ ]+R_RISCV_RELAX[ ]+\*ABS\* [ ]+[0-9a-f]+:[ ]+00000797[ ]+auipc[ ]+a5,0x0 [ ]+[0-9a-f]+:[ ]+R_RISCV_GOT_HI20[ ]+a +[ ]+[0-9a-f]+:[ ]+R_RISCV_RELAX[ ]+\*ABS\* [ ]+[0-9a-f]+:[ ]+(0007a783|0007b783)[ ]+(lw|ld)[ ]+a5,0\(a5\).* [ ]+[0-9a-f]+:[ ]+R_RISCV_PCREL_LO12_I[ ]+\.L0[ ]+ [ ]+[0-9a-f]+:[ ]+R_RISCV_RELAX[ ]+\*ABS\*