From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 0FD8E3858C42 for ; Sun, 4 Feb 2024 03:11:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0FD8E3858C42 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 0FD8E3858C42 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=1707016308; cv=none; b=FSznsqyjIeenskK0DKbWJVwjLkY5j+ODcOg2BLpthd8zDzqZaYuXk74oFuuNVBu5+J0hpfSQS9ZwWvr6N6iV/49oclIV+tY2lOwEb/NBxAGhi8++6TrfqThslgfYxRDVC/Pga3ShYkYAumCNnOGUiEecpbxqfb2oyhLoalmAZ+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707016308; c=relaxed/simple; bh=aGsZJISTKvGZd9Lqpvo0Pup72REty9uwOliJGNInhY0=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=vKT2LyQaxfvexA/tQV+U+65JfMsv/BcaRAcjuiri/E59PmcfnN18oSIUv8dl2YUt6CAfxM9uQftNHHvcmwOvWXaaVyqykilUXl/Fa7uW8CbE48nCqnXf77cI/LLdT9lxBYpR6syTXF5slfP06BCzI3pcWl61FtMD5ZUZdu3fn8A= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [10.2.6.5]) by gateway (Coremail) with SMTP id _____8DxK+ltAL9lw4AKAA--.11326S3; Sun, 04 Feb 2024 11:11:42 +0800 (CST) Received: from 5.5.5 (unknown [10.2.6.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxX89rAL9lOiQvAA--.46986S4; Sun, 04 Feb 2024 11:11:39 +0800 (CST) From: Lulu Cai To: binutils@sourceware.org Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn, liuzhensong@loongson.cn, mengqinggang@loongson.cn, xry111@xry111.site, i.swmail@xen0n.name, maskray@google.com, luweining@loongson.cn, wanglei@loongson.cn, hejinyang@loongson.cn, Lulu Cai Subject: [PATCH v2 0/2] LoongArch: TLS type transition instruction removal and old LE rela Date: Sun, 4 Feb 2024 11:11:30 +0800 Message-Id: <20240204031132.3978170-1-cailulu@loongson.cn> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:AQAAf8AxX89rAL9lOiQvAA--.46986S4 X-CM-SenderInfo: xfdlz3tox6z05rqj20fqof0/1tbiAQAOB2W7VmEFAwAosP X-Coremail-Antispam: 1Uk129KBj93XoW3WFyxCr1xuw1Dtry8Ar4xAFc_yoW7ZF1fpa 9rZ3s0y3W8AFsrCF1DCw45Xr9xWFZ7Gr47Wa42qw1IkrsaqrW0qw1Iyr43Xa45A3yDAw1r Xw10qw1fuF1DJrXCm3ZEXasCq-sJn29KB7ZKAUJUUUUx529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUBFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1ln4kS14v26r126r1DM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12 xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r12 6r1DMcIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64 vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_ Jr0_Gr1l4IxYO2xFxVAFwI0_JF0_Jw1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8Gjc xK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0 cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8V AvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E 14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07jjQ6JUUUUU= X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,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 List-Id: This modification mainly changes the timing of type transition, adds relaxation to the old LE instruction sequence. We strictly distinguish between type transition and relaxation. Type transition is from one type to another, while relaxation is the removal of instructions under the same TLS type. Detailed instructions are as follows: 1. For type transition, only the normal code model of DESC/IE does type transition, and each relocation is accompanied by a R_LARCH_RELAX. Neither abs nor extreme will do type transition, and no R_LARCH_RELAX will be generated. The extra instructions when DESC transitions to other TLS types will be deleted during the type transition. Type Transition Delete Instructions: pcalau12i $a0,%desc_pc_hi20(sym) => pcalau12i $a0,%ie_pc_hi20(sym) addi.d $a0,$a0,%desc_pc_lo12(sym) => ld.d $a0,$a0,%ie_pc_lo12(sym) ld.d $ra,$a0,%desc_ld(sym) => (deleted) jirl $ra,$ra,%desc_call(sym) => (deleted) 2. Implemented relaxation for the old LE instruction sequence. The first two instructions of LE's 32-bit and 64-bit models use the same relocations and cannot be distinguished based on relocations. Therefore, for LE's instruction sequence, any code model will try to relaxation. LE of 32-bit relaxation: lu12i.w $a0,%le_hi20(sym) => (deleted) ori $a0,$a0,%le_lo12(sym) => ori $a0,$zero,%le_lo12(sym) LE of 64-bit relaxation: lu12i.w $a0,$le_hi20(sym) => (deleted) ori $a0,%le_lo12(sym) => ori $a0,$zero,%le_lo12(sym) lu32i.d $a0,%le64_lo20(sym) => (deleted) lu52i.d $a0,$a0,le64_hi12(sym) => (deleted) 3. Some function names have been adjusted to facilitate understanding, parameters have been adjusted, and unused macros have been deleted. ---- V1 -> V2: * Distinguished the different behavior of type transitions when using --relax/--no-relax. If --no-relax is used, the nop in DESC->IE/LE will not be deleted. such as DESC->LE: pcalau12i $a0,%desc_pc_hi20(sym) => lu12i.w $a0,%le_hi20(sym) addi.d $a0,$a0,%desc_pc_lo12(sym) => ori $a0,$a0,%le_lo12(sym) ld.d $ra,$a0,%desc_ld(sym) => nop jirl $ra,$ra,%desc_call(sym) => nop If --relax is used, the nop in DESC->IE/LE will be deleted. And it will try to relaxation the LE instruction sequence after the tls type transition. * Added a check to see if the current relocation is the last for the section to prevent excessive reads. * Added new test cases for testing --relax and --no-relax. Lulu Cai (2): LoongArch: Delete extra instructions when TLS type transition LoongArch: Fix some test cases for TLS transition and relax bfd/elfnn-loongarch.c | 420 +++++++++++------- gas/config/tc-loongarch.c | 31 +- gas/testsuite/gas/loongarch/macro_op.d | 4 + gas/testsuite/gas/loongarch/macro_op_32.d | 4 + .../gas/loongarch/macro_op_extreme_abs.d | 4 +- .../gas/loongarch/macro_op_extreme_pc.d | 2 + .../relax-cfi-fde-DW_CFA_advance_loc.d | 16 +- .../relax-cfi-fde-DW_CFA_advance_loc.s | 8 + gas/testsuite/gas/loongarch/reloc.d | 8 + gas/testsuite/gas/loongarch/tlsdesc_32.d | 2 + gas/testsuite/gas/loongarch/tlsdesc_64.d | 2 + ld/testsuite/ld-loongarch-elf/desc-ie.d | 14 +- ld/testsuite/ld-loongarch-elf/desc-ie.s | 13 +- .../ld-loongarch-elf/desc-le-norelax.d | 15 + .../ld-loongarch-elf/desc-le-norelax.s | 11 + ld/testsuite/ld-loongarch-elf/desc-le-relax.d | 13 + ld/testsuite/ld-loongarch-elf/desc-le-relax.s | 14 + ld/testsuite/ld-loongarch-elf/desc-le.d | 15 - ld/testsuite/ld-loongarch-elf/desc-le.s | 14 - ld/testsuite/ld-loongarch-elf/ie-le-norelax.d | 13 + .../{ie-le.s => ie-le-norelax.s} | 4 +- ld/testsuite/ld-loongarch-elf/ie-le-relax.d | 13 + ld/testsuite/ld-loongarch-elf/ie-le-relax.s | 13 + ld/testsuite/ld-loongarch-elf/ie-le.d | 13 - .../ld-loongarch-elf/ld-loongarch-elf.exp | 9 +- ld/testsuite/ld-loongarch-elf/macro_op.d | 4 + ld/testsuite/ld-loongarch-elf/macro_op_32.d | 4 + ld/testsuite/ld-loongarch-elf/relax.exp | 6 +- .../ld-loongarch-elf/tls-le-norelax.d | 18 + .../{tls-le.s => tls-le-norelax.s} | 4 + ld/testsuite/ld-loongarch-elf/tls-le-relax.d | 13 + ld/testsuite/ld-loongarch-elf/tls-le-relax.s | 22 + ld/testsuite/ld-loongarch-elf/tls-le.d | 14 - ld/testsuite/ld-loongarch-elf/tlsdesc-dso.d | 84 ++-- 34 files changed, 540 insertions(+), 304 deletions(-) create mode 100644 ld/testsuite/ld-loongarch-elf/desc-le-norelax.d create mode 100644 ld/testsuite/ld-loongarch-elf/desc-le-norelax.s create mode 100644 ld/testsuite/ld-loongarch-elf/desc-le-relax.d create mode 100644 ld/testsuite/ld-loongarch-elf/desc-le-relax.s delete mode 100644 ld/testsuite/ld-loongarch-elf/desc-le.d delete mode 100644 ld/testsuite/ld-loongarch-elf/desc-le.s create mode 100644 ld/testsuite/ld-loongarch-elf/ie-le-norelax.d rename ld/testsuite/ld-loongarch-elf/{ie-le.s => ie-le-norelax.s} (63%) create mode 100644 ld/testsuite/ld-loongarch-elf/ie-le-relax.d create mode 100644 ld/testsuite/ld-loongarch-elf/ie-le-relax.s delete mode 100644 ld/testsuite/ld-loongarch-elf/ie-le.d create mode 100644 ld/testsuite/ld-loongarch-elf/tls-le-norelax.d rename ld/testsuite/ld-loongarch-elf/{tls-le.s => tls-le-norelax.s} (70%) create mode 100644 ld/testsuite/ld-loongarch-elf/tls-le-relax.d create mode 100644 ld/testsuite/ld-loongarch-elf/tls-le-relax.s delete mode 100644 ld/testsuite/ld-loongarch-elf/tls-le.d -- 2.36.0