From patchwork Mon May 22 01:34:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mengqinggang X-Patchwork-Id: 9644 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1144280vqo; Sun, 21 May 2023 18:35:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6N6BY/KJrD+HX5kl5b4PrscLd9AMOQekYCRP17kW1lwWNAKqHS2FiQW51ZjUoB+eYlsWKZ X-Received: by 2002:aa7:d153:0:b0:510:f673:ee12 with SMTP id r19-20020aa7d153000000b00510f673ee12mr7667436edo.2.1684719304427; Sun, 21 May 2023 18:35:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684719304; cv=none; d=google.com; s=arc-20160816; b=g9F5wNFOAIG+wcRpaHpu1Qlh4dIHugwhtsDK8k/uTHl0Qxzyeev4dAbFmUu/WwC2ko v0oAV5l7dt6Gf0tcDOzImKBNt2OWc32yPV0X5pFDAnTtYzXYPZWWv3OLAEXDiHOwLERo gSsD7+wTi96mqWyS/V2tttDEce4TyqlavMewbgh5Lw9FofVxgomcAvoQZ4ZOTjpKdQzu tpzVmMYfDFzi2gOjp/vuF/5vATaiNZkDIP8VzaTwDfQ4TCv4BEDpbUn3U75FHWwqgNvM /FTiwG88XyNcZL8sIIpig8MTdhQLdg4FXVzBFaiWRag368TStVpEnBLBF3GUTSa6HN2A TAJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender: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:dmarc-filter :delivered-to; bh=/LP1Dz2Q+9LquWdKZngYaEYmzLsoPPqFOpgv1OnAVYI=; b=aemg5aAsAwYuf07MZToZ1UPdQVU6v12BL4zr4H7IgA99Y7uYuBJcupH0eTn3OJq39x NQfdCOht8Ko4x+DVoj8HUSV4I5zaen7a+EYgb/RVd049BmjSk5iJiGtrVxnsY8UCUIzR NPGDtMbvlCrQEqp7EOuNYe8nchLe9Ez4pAHjhcF9upu8/a7QdCuw7utHc4Naq+fuIouL 5pUFgYpBirjJzmMIN/Q8dppc3VtxHGAgbX4Ukbvu6o4fW06eKYGdHgm6VIGlsF/iT9aa zcjxts6qdMYDtUSmYg3G09fJAWYA+tY2HfjokDPaJLQX/UQ/YHcve970To3l51pUmlxy Arow== ARC-Authentication-Results: i=1; mx.google.com; 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 sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l6-20020aa7d946000000b0050bf6548840si3002917eds.590.2023.05.21.18.35.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 May 2023 18:35:04 -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; 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 C2D5D385771D for ; Mon, 22 May 2023 01:35:01 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 05BC43858D20 for ; Mon, 22 May 2023 01:34:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 05BC43858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.5]) by gateway (Coremail) with SMTP id _____8AxNPC7xmpkYMYKAA--.18502S3; Mon, 22 May 2023 09:34:52 +0800 (CST) Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxMMi0xmpkzF5uAA--.53821S2; Mon, 22 May 2023 09:34:50 +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, mengqinggang Subject: [PATCH v4 0/6] LoongArch linker relaxation support. Date: Mon, 22 May 2023 09:34:35 +0800 Message-Id: <20230522013441.3074776-1-mengqinggang@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxMMi0xmpkzF5uAA--.53821S2 X-CM-SenderInfo: 5phqw15lqjwttqj6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjvJXoWxCw1xWw4DXFy7CrWrKry3Arb_yoWrKry3pa 4UZr1FyF4kCFnrGr1DG3y5u3Z5Jan7Krya9a4ftF12kr4Sqry0vw10yw43XFs8J3yjg34f Zw10vw1ruFn8trJanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b7xYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26F4j6r4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UM2AI xVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx1l5I8CrVACY4xI64 kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVWUJVW8JwAm 72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I 0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWU GVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI 0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0 rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r 4UYxBIdaVFxhVjvjDU0xZFpf9x07UNvtZUUUUU= X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no 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.29 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 Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766556229350189216?= X-GMAIL-MSGID: =?utf-8?q?1766556229350189216?= This is the v4 version of patches to support loongarch linker relax. This version mainly rebase to the master branch. The binutils, gcc, glibc and Spec2006 testcases is ok. Now, only the instrunctions expand from macro (la.local, la.global, etc.) at assembly time can be relaxed, because gcc instruction scheduling causes relax unable to handle some special cases. Gcc can add -mno-explicit-relocs option to generate macro instrunction. There are two code sequence can be relaxed in LoongArch. The first one is "pcala12i + addi.d", which can be relaxed to pcaddi. Another one is "pcalau12i + ld.d", which can be relaxed to "pcalau12i + addi.d". And it can be relaxed to pcaddi one more time. Pcaddi instrunction can address a signed 22 bits 4-byte alinged offset relative to pc. In the future, the TLS LE code sequence and function call in medium code mode would be relaxed too. For .align directive, some small problems cannot be perfectly solved (see http://maskray.me/blog/2021-03-14-the-dark-side-of-riscv-linker-relaxation). The new relocs document at here: https://github.com/loongson/LoongArch-Documentation/pull/77 mengqinggang (6): LoongArch: include: Add support for linker relaxation. LoongArch: bfd: Add support for linker relaxation. LoongArch: opcodes: Add support for linker relaxation. LoongArch: binutils: Add support for linker relaxation. LoongArch: gas: Add support for linker relaxation. LoongArch: ld: Add support for linker relaxation. bfd/bfd-in2.h | 8 + bfd/elfnn-loongarch.c | 582 +++++++++++++-- bfd/elfxx-loongarch.c | 676 +++++++++++++----- bfd/elfxx-loongarch.h | 10 +- bfd/libbfd.h | 8 + bfd/reloc.c | 22 + binutils/readelf.c | 84 ++- binutils/testsuite/binutils-all/readelf.exp | 13 +- gas/config/tc-loongarch.c | 427 +++++++++-- gas/config/tc-loongarch.h | 48 +- gas/testsuite/gas/all/align.d | 5 +- gas/testsuite/gas/all/gas.exp | 10 +- gas/testsuite/gas/all/relax.d | 4 + gas/testsuite/gas/elf/dwarf-5-irp.d | 3 +- gas/testsuite/gas/elf/dwarf-5-loc0.d | 3 +- gas/testsuite/gas/elf/dwarf-5-macro-include.d | 2 +- gas/testsuite/gas/elf/dwarf-5-macro.d | 2 +- gas/testsuite/gas/elf/dwarf2-11.d | 3 +- gas/testsuite/gas/elf/dwarf2-15.d | 3 +- gas/testsuite/gas/elf/dwarf2-16.d | 3 +- gas/testsuite/gas/elf/dwarf2-17.d | 3 +- gas/testsuite/gas/elf/dwarf2-18.d | 3 +- gas/testsuite/gas/elf/dwarf2-19.d | 3 +- gas/testsuite/gas/elf/dwarf2-5.d | 3 +- gas/testsuite/gas/elf/ehopt0.d | 3 + gas/testsuite/gas/elf/elf.exp | 3 + gas/testsuite/gas/elf/section11.d | 4 +- gas/testsuite/gas/lns/lns.exp | 1 + gas/testsuite/gas/loongarch/jmp_op.d | 65 +- gas/testsuite/gas/loongarch/li.d | 8 +- gas/testsuite/gas/loongarch/macro_op.d | 68 +- gas/testsuite/gas/loongarch/macro_op_32.d | 24 +- .../gas/loongarch/macro_op_large_abs.d | 32 +- .../gas/loongarch/macro_op_large_pc.d | 134 ++-- gas/testsuite/gas/loongarch/relax_align.d | 26 + gas/testsuite/gas/loongarch/relax_align.s | 5 + gas/testsuite/gas/loongarch/uleb128.d | 36 + gas/testsuite/gas/loongarch/uleb128.s | 20 + include/elf/loongarch.h | 20 + include/opcode/loongarch.h | 3 + ld/emultempl/loongarchelf.em | 3 + ld/testsuite/ld-elf/compressed1d.d | 3 + ld/testsuite/ld-elf/pr26936.d | 4 +- ld/testsuite/ld-loongarch-elf/disas-jirl-32.d | 2 + ld/testsuite/ld-loongarch-elf/disas-jirl.d | 4 +- ld/testsuite/ld-loongarch-elf/jmp_op.d | 65 +- ld/testsuite/ld-loongarch-elf/macro_op.d | 84 ++- ld/testsuite/ld-loongarch-elf/macro_op_32.d | 24 +- ld/testsuite/ld-loongarch-elf/relax-align.dd | 7 + ld/testsuite/ld-loongarch-elf/relax-align.s | 9 + ld/testsuite/ld-loongarch-elf/relax.exp | 73 ++ ld/testsuite/ld-loongarch-elf/relax.s | 16 + ld/testsuite/ld-loongarch-elf/uleb128.dd | 10 + ld/testsuite/ld-loongarch-elf/uleb128.s | 21 + opcodes/loongarch-opc.c | 5 +- 55 files changed, 2189 insertions(+), 521 deletions(-) create mode 100644 gas/testsuite/gas/loongarch/relax_align.d create mode 100644 gas/testsuite/gas/loongarch/relax_align.s create mode 100644 gas/testsuite/gas/loongarch/uleb128.d create mode 100644 gas/testsuite/gas/loongarch/uleb128.s create mode 100644 ld/testsuite/ld-loongarch-elf/relax-align.dd create mode 100644 ld/testsuite/ld-loongarch-elf/relax-align.s create mode 100644 ld/testsuite/ld-loongarch-elf/relax.exp create mode 100644 ld/testsuite/ld-loongarch-elf/relax.s create mode 100644 ld/testsuite/ld-loongarch-elf/uleb128.dd create mode 100644 ld/testsuite/ld-loongarch-elf/uleb128.s