From patchwork Fri Mar 1 06:17:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lulu Cai X-Patchwork-Id: 21188 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp889324dyb; Thu, 29 Feb 2024 22:18:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXx0GTKaJszkp+OB2KdHzfEYXKLyMXRmzBqq+wQEH9cC2XiV0VdBhabUB0y5oLWJfAjGXStZDX9B+qs2FkB1VfvIXSAGw== X-Google-Smtp-Source: AGHT+IGz80hnRGqWKUoPv5LA1PcadkraPeLO66xniJScX7lwyJQtRQtmIDOf4RlB4s/v5mXuVZYT X-Received: by 2002:a0c:c243:0:b0:690:2f5c:f0ce with SMTP id w3-20020a0cc243000000b006902f5cf0cemr885036qvh.24.1709273897824; Thu, 29 Feb 2024 22:18:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709273897; cv=pass; d=google.com; s=arc-20160816; b=hYno++zZRIf/KpnQkDI7enn+MkTVkZcdC282xuhHEhZQUroPt/r/95653qnLfQlAwh BpjDlMoY1kjsJPLwEYOJDVqsUiJOq8eloKRsdSxN1q3Ddxr7jOMF7EBRlC60Cx+BZKM7 0M0N7O/t2l8tY7dfYR3H+2ZRu7iXKkFST1H2n4EBXVyqPEzYBoiYpEg0zbDG2tn5ovsG f9d3AnbD7y1wHqn3GryZtdInJ4zgnboW5RJ9uVxaQ5SFHbdeUhrbJYACRAUhzvXHR1KU 2J7ybimvqjtM0l/onjDCl4Uf03XOARvn16/cPZpbj8m1wda2b+wWQk+V33sn8FU1ddFg 9/yg== 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=GKzKNSuk03xdh7ZQj8oVw1o7NNdnPpOLg6islWOg8KQ=; fh=FvlVQEmCpm5H8oBXQswexzCupeeQXnbssobXN+3R2Wg=; b=MHCwfvZmRWS5+RMet4qDDAmxsqofXmgcbHEaLJ3ObeHMJY/829dhr2gvPK7ggxh9fh zIV+A2m+88RjiinJRZuxNBkzAq3qFRb93rwSRsehGpxkCPcS4MLy1sKqBuP94uUw0Vl7 PsiBqKkQr55wQ7Y38DRjk2pkQJkyKKIvrImWjbWnqpPnGuxFi7t4QI9J9U6ECfBn9KvC tbbCTRNRRXEphBYWKyx3UI4cpu3XbgzhZyUbDjE7DktD/JFjlNwEy60mrn3zks4yck+w V70+jQ0itnsz/NgUSZUMP0q25ZfYTii+PiHX8ZmTmtBiin5OKfJIdzvKKUmx91vTLLAS 7Leg==; dara=google.com 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 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id i7-20020ad45c67000000b0068fd0486f10si3073577qvh.51.2024.02.29.22.18.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 22:18:17 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 7E7C9385841F for ; Fri, 1 Mar 2024 06:18:17 +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 603F33858C53 for ; Fri, 1 Mar 2024 06:17:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 603F33858C53 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 603F33858C53 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=1709273886; cv=none; b=m8+Ji/7tybHoKeI/fy+Ig9VwM6QLbGdEMOSjlL5hGkZYEa/d0LsGdWH1mQQkKqLu4Zg04hZOYFPCvFecYdxfoQh4DYyrAXg6yHkqzzrRCRZDfMx5PCU4RCwzPkWMcXSLKgm3USe1M7aFfO3nfHQ8CJPtPsJTRg/+FkutCdJ513M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709273886; c=relaxed/simple; bh=FCwYinV2I46N05MKbJoEGzYGdvm/U6rsat0fgD+pZzI=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=V0+/a7NRo7VXQBhNuDv+GHFybfjcX5T7Ra6+Ghk1DhB4uI8L4zztKJ59FofunRgEu9lT2Fd65Sp8C4L9H8k3FoubYOqG7CJ/16JTZhzKrQRr99Sl8rDMnVUH4YNY+zdOUki+IYcQHNG/CL7ahdGZ9Yp4lX4Lgkuy8JBwyPj19/M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [10.2.6.5]) by gateway (Coremail) with SMTP id _____8AxqvARc+FldTETAA--.48699S3; Fri, 01 Mar 2024 14:17:53 +0800 (CST) Received: from 5.5.5 (unknown [10.2.6.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxPBMQc+FlAHtLAA--.4520S4; Fri, 01 Mar 2024 14:17:53 +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 v3 0/3] LoongArch: TLS type transition instruction removal and old LE relax Date: Fri, 1 Mar 2024 14:17:48 +0800 Message-Id: <20240301061751.3061364-1-cailulu@loongson.cn> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxPBMQc+FlAHtLAA--.4520S4 X-CM-SenderInfo: xfdlz3tox6z05rqj20fqof0/1tbiAQACB2XgQGUEqAAlst X-Coremail-Antispam: 1Uk129KBj93XoW3WFyxCr1xuw1Dtry8Ar4xAFc_yoWxAF43pa 9rZr9Yy3W8AFsrGFyDC3y5Xr95WFZ7Gr43Wa4aqw1IkrsaqrW0qw1IyrW3Xa45A3yUJw1r Xw10qw1fuF1DJrXCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9Yb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07 AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWU AVWUtwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7V AKI48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v2 6r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIx AIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIev Ja73UjIFyTuYvjxU2NB_UUUUU 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 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: 1792303586462580937 X-GMAIL-MSGID: 1792303586462580937 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. ---- V2 -> V3: * Add dtpoff calculation function to prevent ld from crashing if tls_sec does not exist. * The gas test case and ld test case have been updated, and test cases for different code models have been added to the ld test case. Lulu Cai (3): LoongArch: Delete extra instructions when TLS type transition LoongArch: Add dtpoff calculation function LoongArch: Fix some test cases for TLS transition and relax bfd/elfnn-loongarch.c | 426 +++++++++++------- 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 | 27 -- gas/testsuite/gas/loongarch/tlsdesc_32.s | 12 - 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 | 11 +- ld/testsuite/ld-loongarch-elf/macro_op.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 | 86 ++-- ld/testsuite/ld-loongarch-elf/tlsdesc-dso.s | 9 + ld/testsuite/ld-loongarch-elf/tlsdesc_abs.d | 23 + ld/testsuite/ld-loongarch-elf/tlsdesc_abs.s | 7 + .../ld-loongarch-elf/tlsdesc_extreme.d | 25 + .../ld-loongarch-elf/tlsdesc_extreme.s | 7 + 39 files changed, 620 insertions(+), 338 deletions(-) delete mode 100644 gas/testsuite/gas/loongarch/tlsdesc_32.d delete mode 100644 gas/testsuite/gas/loongarch/tlsdesc_32.s 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 create mode 100644 ld/testsuite/ld-loongarch-elf/tlsdesc_abs.d create mode 100644 ld/testsuite/ld-loongarch-elf/tlsdesc_abs.s create mode 100644 ld/testsuite/ld-loongarch-elf/tlsdesc_extreme.d create mode 100644 ld/testsuite/ld-loongarch-elf/tlsdesc_extreme.s