From patchwork Tue Nov 28 03:56:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mengqinggang X-Patchwork-Id: 170525 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp3665671vqx; Mon, 27 Nov 2023 19:56:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IEo4GoGvrsHsW6oJMl1DMkWqNXN5/L7Tcr1lPVHuNYLkA8iVocVmVIHFUNdGC/DqsjeLAjo X-Received: by 2002:ac8:57d6:0:b0:423:708a:778e with SMTP id w22-20020ac857d6000000b00423708a778emr13252126qta.58.1701143791138; Mon, 27 Nov 2023 19:56:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701143791; cv=pass; d=google.com; s=arc-20160816; b=W0OGdwyida3q6dqJqA1C6JJbCImblxrHoD+evypH7a9KxQ0pb3LK+QhM8PLcZB0SDe 8zAJHIXrj9g1VbVhXL2OtwpbwFOXMlU0fM8hHugk21rt0+lbAOxI8/+zaGxtqCycqPqk TZVXNsAGzbonUrE7w3VDblSOy1PRBemyR1VqeBK80X+uVGlHPVgr1XTlhUv7JGRKJGWh r+DaHebeMJoYQ+etNFWIjTsE64RBVtoVUJ2p7JH+6npnyw2ctmYOnXECNOr5Lq1qp47i StNa0pnlXkFAtzkZv0PbJZU9ISwp3Xld3O3VgXYYIqYuuFtTVoPJoWXgXZwae0bLRO7r hh0g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:arc-filter :dmarc-filter:delivered-to; bh=+zAQ9uWa8RnpsOs702B2tP5VIMKA9+I3YTeu4IjcpNo=; fh=2A5WQKu3s0HSbOm+KO3Aq9miX1cvZu/zz3ANfE2bsGo=; b=JiN6HNGNnzq9Z+GUtHVnMKEv/5UFr1AK6rMHtyrtysf7KPKEXdEK/lBhwgDu/yXVWN bnTg0w85L7kvx6oq20Ryprg2OI8xO/HUFjtCb1bly+Lwxs+YBzpNuRK5fs8bAlUeL8FV Y1jw613+90i6Kay8y0ikenyzhKNhtPNNQb3BZ8KHyZunML//+VnmSHB2p2QOB2wgFRaH 7anWmWVAKUPjDklKUZLfIxAfyFdB2aVOsuJ2s8FLFaaqt8SPk6xylT7LD5RFKKLJQ3sW Oir924j7tMf5cUeoCp24DQZq4E977OTpOvmcfw99CcU6HZooAzKKcWNCnaEHQItNweZd paQw== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); 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" Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id o10-20020ac85a4a000000b0042370f990a5si10754456qta.266.2023.11.27.19.56.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 19:56:31 -0800 (PST) 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; arc=pass (i=1); 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 77E803857C62 for ; Tue, 28 Nov 2023 03:56:30 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id E4C22385842D for ; Tue, 28 Nov 2023 03:56:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E4C22385842D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E4C22385842D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701143784; cv=none; b=i+QNaP9ucgAmbxYKIZ6XboKJX0ssioJqTZnUzJePgwGwFxwF1QUWcMllj1OUdZ7kzFC9KcBFCyGykXp9Pk9X8bqkNveR/tZg10o8YfMhU1aNUFvacxT9wxl6kJ4DKKiWoG7Q4M57Pl48v+j9xEn0knIRjeonDIYMxbyYQc0+OWg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701143784; c=relaxed/simple; bh=G5m+0wiA/cKivLCfmpr/g92qzRVvAnFh/qgGH/jkpfc=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=oICiVpA4UE31t40tLb0l+jDNhVHLnCYvONG8gU5tCi9A6tL8aaA61/1RqlU9/bQgOGcDyQU0KfAgH1z0C3uAUI69qOudz0qSRy2qbch/6JLzvP7h1tJ+pyf+we2lE5KxK+FQbp0IVchq/8e5MVOVoKUMbso5beYr9KhyyelJ8Bg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [10.2.6.5]) by gateway (Coremail) with SMTP id _____8BxyeriZGVlSE89AA--.46748S3; Tue, 28 Nov 2023 11:56:19 +0800 (CST) Received: from 5.5.5 (unknown [10.2.6.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxjNziZGVlv2pOAA--.41918S2; Tue, 28 Nov 2023 11:56:18 +0800 (CST) From: mengqinggang To: binutils@sourceware.org Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn, liuzhensong@loongson.cn, xry111@xry111.site, i.swmail@xen0n.name, maskray@google.com, cailulu@loongson.cn, luweining@loongson.cn, wanglei@loongson.cn, hejinyang@loongson.cn, mengqinggang Subject: [PATCH] LoongArch: Add R_LARCH_ALIGN_MAX relocation Date: Tue, 28 Nov 2023 11:56:15 +0800 Message-Id: <20231128035615.1496147-1-mengqinggang@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxjNziZGVlv2pOAA--.41918S2 X-CM-SenderInfo: 5phqw15lqjwttqj6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj9fXoWfGFyrAF47KFyrZFW7Jw45CFX_yoW8JF43to W5ZFyFga1fGF42yrZrtwn8XFW8tryDCF43AasxuwnrCa18Kr15Gry7G3WrZrWfJrWkGa18 WFyUG393XFyagF1Dl-sFpf9Il3svdjkaLaAFLSUrUUUU1b8apTn2vfkv8UJUUUU8wcxFpf 9Il3svdxBIdaVrn0xqx4xG64xvF2IEw4CE5I8CrVC2j2Jv73VFW2AGmfu7bjvjm3AaLaJ3 UjIYCTnIWjp_UUUYD7kC6x804xWl14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI 8IcIk0rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xG Y2AK021l84ACjcxK6xIIjxv20xvE14v26r1I6r4UM28EF7xvwVC0I7IYx2IY6xkF7I0E14 v26r1j6r4UM28EF7xvwVC2z280aVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8JVW8Jr1ln4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12 xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y 6r17McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64 vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_ Jrv_JF1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1V AY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAI cVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42 IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVj vjDU0xZFpf9x07jjwZcUUUUU= X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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 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: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783778551963337185 X-GMAIL-MSGID: 1783778551963337185 The addend of R_LARCH_ALIGN_MAX is used to represent the first and the third expressions of the .align pseudo instruction. The lowest 8 bits are used to represent the first expression. Other bits are used to represent the third expression. The addend of R_LARCH_ALIGN_MAX for ".align 5, ,4" is 0x405. The addend of R_LARCH_ALIGN_MAX for ".balign 32, ,4" is 0x405. --- bfd/bfd-in2.h | 1 + bfd/elfnn-loongarch.c | 75 +++++++++++++++++++ bfd/elfxx-loongarch.c | 19 +++++ bfd/libbfd.h | 1 + bfd/reloc.c | 3 + gas/config/tc-loongarch.c | 6 +- gas/config/tc-loongarch.h | 4 +- gas/testsuite/gas/loongarch/relax_align.d | 34 ++++----- gas/testsuite/gas/loongarch/relax_align.s | 1 - include/elf/loongarch.h | 2 + .../ld-loongarch-elf/relax-align-max.dd | 4 + .../ld-loongarch-elf/relax-align-max.s | 6 ++ ld/testsuite/ld-loongarch-elf/relax.exp | 14 ++++ 13 files changed, 147 insertions(+), 23 deletions(-) create mode 100644 ld/testsuite/ld-loongarch-elf/relax-align-max.dd create mode 100644 ld/testsuite/ld-loongarch-elf/relax-align-max.s diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 040d5560cdf..e88e5966c22 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -7460,6 +7460,7 @@ enum bfd_reloc_code_real BFD_RELOC_LARCH_ADD_ULEB128, BFD_RELOC_LARCH_SUB_ULEB128, BFD_RELOC_LARCH_64_PCREL, + BFD_RELOC_LARCH_ALIGN_MAX, BFD_RELOC_UNUSED }; typedef enum bfd_reloc_code_real bfd_reloc_code_real_type; diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c index 024c5d4cd96..7a9b96018ec 100644 --- a/bfd/elfnn-loongarch.c +++ b/bfd/elfnn-loongarch.c @@ -3534,6 +3534,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, case R_LARCH_RELAX: case R_LARCH_ALIGN: + case R_LARCH_ALIGN_MAX: r = bfd_reloc_continue; unresolved_reloc = false; break; @@ -3891,6 +3892,63 @@ loongarch_relax_align (bfd *abfd, asection *sec, rel->r_addend - nop_bytes, link_info); } +static bool +loongarch_relax_align_max (bfd *abfd, asection *sec, + asection *sym_sec, + struct bfd_link_info *link_info, + Elf_Internal_Rela *rel, + bfd_vma symval) +{ + bfd_byte *contents = elf_section_data (sec)->this_hdr.contents; + + bfd_vma alignment = 1, pos, max; + + /* 2^n = 2<<(n-1). */ + alignment = 2 << ((rel->r_addend & 0xff) - 1); + max = (rel->r_addend >> 8); + + symval -= (alignment - 4); + bfd_vma aligned_addr = ((symval - 1) & ~(alignment - 1)) + alignment; + bfd_vma nop_bytes = aligned_addr - symval; + + /* Once we've handled an R_LARCH_ALIGN, we can't relax anything else. */ + sec->sec_flg0 = true; + + /* Make sure there are enough NOPs to actually achieve the alignment. */ + if ((alignment - 4) < nop_bytes) + { + _bfd_error_handler + (_("%pB(%pA+%#" PRIx64 "): %" PRId64 " bytes required for alignment " + "to %" PRId64 "-byte boundary, but only %" PRId64 " present"), + abfd, sym_sec, (uint64_t) rel->r_offset, + (int64_t) nop_bytes, (int64_t) alignment, (int64_t) rel->r_addend); + bfd_set_error (bfd_error_bad_value); + return false; + } + + /* Change R_LARCH_ALIGN_MAX to R_LARCH_NONE. */ + rel->r_info = ELFNN_R_INFO (0, R_LARCH_NONE); + + /* If doing the alignemnt would require skipping more bytes than the + specified maximum, then the alignment is not done at all (delete all NOPs). + If the maximum is 0, the alignment can skip any bytes. */ + if (max > 0 && nop_bytes > max) + return loongarch_relax_delete_bytes (abfd, sec, rel->r_offset, + alignment - 4, link_info); + + /* If the number of NOPs is already correct, there's nothing to do. */ + if (nop_bytes == (alignment - 4)) + return true; + + /* Write as many LOONGARCH NOPs as we need. */ + for (pos = 0; pos < (nop_bytes & -4); pos += 4) + bfd_putl32 (LARCH_NOP, contents + rel->r_offset + pos); + + /* Delete the excess NOPs. */ + return loongarch_relax_delete_bytes (abfd, sec, rel->r_offset + nop_bytes, + (alignment - 4) - nop_bytes, link_info); +} + static bool loongarch_elf_relax_section (bfd *abfd, asection *sec, struct bfd_link_info *info, @@ -4005,6 +4063,14 @@ loongarch_elf_relax_section (bfd *abfd, asection *sec, if (symtype != STT_SECTION) symval += rel->r_addend; } + /* For R_LARCH_ALIGN_MAX and R_LARCH_ALIGN, symval is sec_addr(sym_sec) + + rel->r_offset + (alingmeng - 4). + For R_LARCH_ALIGN, alignmeng-4 is r_addend. + For R_LARCH_ALIGN_MAX, alignment-4 is 2^(r_addend & 0xff)-4. */ + else if (R_LARCH_ALIGN_MAX == ELFNN_R_TYPE (rel->r_info)) + symval += ((2 << ((rel->r_addend & 0xff) - 1)) - 4); + else if (R_LARCH_ALIGN == ELFNN_R_TYPE (rel->r_info)) + symval += rel->r_addend; else symval += rel->r_addend; @@ -4016,6 +4082,12 @@ loongarch_elf_relax_section (bfd *abfd, asection *sec, if (1 == info->relax_pass) loongarch_relax_align (abfd, sec, sym_sec, info, rel, symval); break; + + case R_LARCH_ALIGN_MAX: + if (1 == info->relax_pass) + loongarch_relax_align_max (abfd, sec, sym_sec, info, rel, symval); + break; + case R_LARCH_DELETE: if (1 == info->relax_pass) { @@ -4023,11 +4095,13 @@ loongarch_elf_relax_section (bfd *abfd, asection *sec, rel->r_info = ELFNN_R_INFO (0, R_LARCH_NONE); } break; + case R_LARCH_PCALA_HI20: if (0 == info->relax_pass && (i + 4) <= sec->reloc_count) loongarch_relax_pcala_addi (abfd, sec, sym_sec, rel, symval, info, again); break; + case R_LARCH_GOT_PC_HI20: if (local_got && 0 == info->relax_pass && (i + 4) <= sec->reloc_count) @@ -4037,6 +4111,7 @@ loongarch_elf_relax_section (bfd *abfd, asection *sec, info, again); } break; + default: break; } diff --git a/bfd/elfxx-loongarch.c b/bfd/elfxx-loongarch.c index a970a257aa9..072dbc7494f 100644 --- a/bfd/elfxx-loongarch.c +++ b/bfd/elfxx-loongarch.c @@ -1547,6 +1547,25 @@ static loongarch_reloc_howto_type loongarch_howto_table[] = NULL, /* adjust_reloc_bits */ NULL), /* larch_reloc_type_name */ + /* The lowest 8 bits is the first expression of .align, + other bits is the third expression of .align. */ + LOONGARCH_HOWTO (R_LARCH_ALIGN_MAX, /* type (110). */ + 0, /* rightshift. */ + 0, /* size. */ + 0, /* bitsize. */ + false, /* pc_relative. */ + 0, /* bitpos. */ + complain_overflow_dont, /* complain_on_overflow. */ + bfd_elf_generic_reloc, /* special_function. */ + "R_LARCH_ALIGN_MAX", /* name. */ + false, /* partial_inplace. */ + 0, /* src_mask. */ + 0, /* dst_mask. */ + false, /* pcrel_offset. */ + BFD_RELOC_LARCH_ALIGN_MAX, /* bfd_reloc_code_real_type. */ + NULL, /* adjust_reloc_bits. */ + NULL), /* larch_reloc_type_name. */ + }; reloc_howto_type * diff --git a/bfd/libbfd.h b/bfd/libbfd.h index cc432677a81..79172590b19 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -3599,6 +3599,7 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@", "BFD_RELOC_LARCH_ADD_ULEB128", "BFD_RELOC_LARCH_SUB_ULEB128", "BFD_RELOC_LARCH_64_PCREL", + "BFD_RELOC_LARCH_ALIGN_MAX", "@@overflow: BFD_RELOC_UNUSED@@", }; #endif diff --git a/bfd/reloc.c b/bfd/reloc.c index 93ebad879e0..3353cbb2c2b 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -8292,6 +8292,9 @@ ENUMX ENUMX BFD_RELOC_LARCH_64_PCREL +ENUMX + BFD_RELOC_LARCH_ALIGN_MAX + ENUMDOC LARCH relocations. diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c index d1ce111c186..8c60dd555de 100644 --- a/gas/config/tc-loongarch.c +++ b/gas/config/tc-loongarch.c @@ -1646,7 +1646,7 @@ loongarch_make_nops (char *buf, bfd_vma bytes) the correct alignment now because of other linker relaxations. */ bool -loongarch_frag_align_code (int n) +loongarch_frag_align_code (int n, int max) { bfd_vma bytes = (bfd_vma) 1 << n; bfd_vma insn_alignment = 4; @@ -1666,12 +1666,12 @@ loongarch_frag_align_code (int n) nops = frag_more (worst_case_bytes); ex.X_op = O_constant; - ex.X_add_number = worst_case_bytes; + ex.X_add_number = ((max << 8) | n); loongarch_make_nops (nops, worst_case_bytes); fix_new_exp (frag_now, nops - frag_now->fr_literal, 0, - &ex, false, BFD_RELOC_LARCH_ALIGN); + &ex, false, BFD_RELOC_LARCH_ALIGN_MAX); /* We need to start a new frag after the alignment which may be removed by the linker, to prevent the assembler from computing static offsets. diff --git a/gas/config/tc-loongarch.h b/gas/config/tc-loongarch.h index 4afa38422d6..194ee107c0a 100644 --- a/gas/config/tc-loongarch.h +++ b/gas/config/tc-loongarch.h @@ -49,11 +49,11 @@ extern int loongarch_relax_frag (asection *, struct frag *, long); #define md_undefined_symbol(name) (0) #define md_operand(x) -extern bool loongarch_frag_align_code (int); +extern bool loongarch_frag_align_code (int, int); #define md_do_align(N, FILL, LEN, MAX, LABEL) \ if ((N) != 0 && !(FILL) && !need_pass_2 && subseg_text_p (now_seg)) \ { \ - if (loongarch_frag_align_code (N)) \ + if (loongarch_frag_align_code (N, MAX)) \ goto LABEL; \ } diff --git a/gas/testsuite/gas/loongarch/relax_align.d b/gas/testsuite/gas/loongarch/relax_align.d index 1810eb4cae7..cc2562fc25c 100644 --- a/gas/testsuite/gas/loongarch/relax_align.d +++ b/gas/testsuite/gas/loongarch/relax_align.d @@ -7,20 +7,20 @@ Disassembly of section .text: -00000000.* : -[ ]+0:[ ]+1a000004[ ]+pcalau12i[ ]+\$a0,[ ]+0 -[ ]+0:[ ]+R_LARCH_PCALA_HI20[ ]+L1 -[ ]+0:[ ]+R_LARCH_RELAX[ ]+\*ABS\* -[ ]+4:[ ]+02c00084[ ]+addi\.d[ ]+\$a0,[ ]+\$a0,[ ]+0 -[ ]+4:[ ]+R_LARCH_PCALA_LO12[ ]+L1 -[ ]+4:[ ]+R_LARCH_RELAX[ ]+\*ABS\* -[ ]+8:[ ]+03400000[ ]+nop[ ]+ -[ ]+8:[ ]+R_LARCH_ALIGN[ ]+\*ABS\*\+0xc -[ ]+c:[ ]+03400000[ ]+nop[ ]+ -[ ]+10:[ ]+03400000[ ]+nop[ ]+ -[ ]+14:[ ]+1a000004[ ]+pcalau12i[ ]+\$a0,[ ]+0 -[ ]+14:[ ]+R_LARCH_PCALA_HI20[ ]+L1 -[ ]+14:[ ]+R_LARCH_RELAX[ ]+\*ABS\* -[ ]+18:[ ]+02c00084[ ]+addi\.d[ ]+\$a0,[ ]+\$a0,[ ]+0 -[ ]+18:[ ]+R_LARCH_PCALA_LO12[ ]+L1 -[ ]+18:[ ]+R_LARCH_RELAX[ ]+\*ABS\* +.* <.text>: +[ ]+0:[ ]+1a000004[ ]+pcalau12i[ ]+\$a0, 0 +[ ]+0: R_LARCH_PCALA_HI20[ ]+L1 +[ ]+0: R_LARCH_RELAX[ ]+\*ABS\* +[ ]+4:[ ]+02c00084[ ]+addi.d[ ]+\$a0, \$a0, 0 +[ ]+4: R_LARCH_PCALA_LO12[ ]+L1 +[ ]+4: R_LARCH_RELAX[ ]+\*ABS\* +[ ]+8:[ ]+03400000[ ]+nop.* +[ ]+8: R_LARCH_ALIGN_MAX[ ]+\*ABS\*\+0x4 +[ ]+c:[ ]+03400000[ ]+nop.* +[ ]+10:[ ]+03400000[ ]+nop.* +[ ]+14:[ ]+1a000004[ ]+pcalau12i[ ]+\$a0, 0 +[ ]+14: R_LARCH_PCALA_HI20[ ]+L1 +[ ]+14: R_LARCH_RELAX[ ]+\*ABS\* +[ ]+18:[ ]+02c00084[ ]+addi.d[ ]+\$a0, \$a0, 0 +[ ]+18: R_LARCH_PCALA_LO12[ ]+L1 +[ ]+18: R_LARCH_RELAX[ ]+\*ABS\* diff --git a/gas/testsuite/gas/loongarch/relax_align.s b/gas/testsuite/gas/loongarch/relax_align.s index 3880d783e79..482600e43a5 100644 --- a/gas/testsuite/gas/loongarch/relax_align.s +++ b/gas/testsuite/gas/loongarch/relax_align.s @@ -1,5 +1,4 @@ .text -L1: la.local $a0, L1 .align 4 la.local $a0, L1 diff --git a/include/elf/loongarch.h b/include/elf/loongarch.h index e31395e13d5..cce43bb4a10 100644 --- a/include/elf/loongarch.h +++ b/include/elf/loongarch.h @@ -251,6 +251,8 @@ RELOC_NUMBER (R_LARCH_SUB_ULEB128, 108) RELOC_NUMBER (R_LARCH_64_PCREL, 109) +RELOC_NUMBER (R_LARCH_ALIGN_MAX, 110) + END_RELOC_NUMBERS (R_LARCH_count) /* Processor specific flags for the ELF header e_flags field. */ diff --git a/ld/testsuite/ld-loongarch-elf/relax-align-max.dd b/ld/testsuite/ld-loongarch-elf/relax-align-max.dd new file mode 100644 index 00000000000..0dd739ffc4a --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relax-align-max.dd @@ -0,0 +1,4 @@ +#... +.*pcaddi.* +.*pcaddi.* +#pass diff --git a/ld/testsuite/ld-loongarch-elf/relax-align-max.s b/ld/testsuite/ld-loongarch-elf/relax-align-max.s new file mode 100644 index 00000000000..2e829392fd6 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/relax-align-max.s @@ -0,0 +1,6 @@ + .text +.L1: + la.local $t0, .L1 + # If skipping more bytes than 4, then the alignment is not done at all. + .align 4, , 4 + la.local $t0, .L1 diff --git a/ld/testsuite/ld-loongarch-elf/relax.exp b/ld/testsuite/ld-loongarch-elf/relax.exp index 24d79ed5c20..a4bfd0fe0c7 100644 --- a/ld/testsuite/ld-loongarch-elf/relax.exp +++ b/ld/testsuite/ld-loongarch-elf/relax.exp @@ -130,6 +130,20 @@ if [istarget loongarch64-*-*] { ] \ ] + run_ld_link_tests \ + [list \ + [list \ + "loongarch relax-align-max" \ + "-e 0x0 -z relro" "" \ + "--no-warn" \ + {relax-align-max.s} \ + [list \ + [list objdump -d relax-align-max.dd] \ + ] \ + "relax-align-max" \ + ] \ + ] + set objdump_flags "-s -j .data" run_ld_link_tests \ [list \