From patchwork Thu Aug 11 11:35:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenglulu X-Patchwork-Id: 471 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:38f:b0:2d5:3c95:9e21 with SMTP id 15csp156058pxh; Thu, 11 Aug 2022 04:43:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR44mzWiCky0wDg25giHPmIPjkXVIXK7p2K6O46fJQw2Drd8+lDSEAQbMj+yo+czc6dWxUTt X-Received: by 2002:a17:907:7355:b0:730:65bc:e761 with SMTP id dq21-20020a170907735500b0073065bce761mr23159323ejc.145.1660218214305; Thu, 11 Aug 2022 04:43:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660218214; cv=none; d=google.com; s=arc-20160816; b=iMPDYAe9fz9A2dqtO6JSZmoenZhOdkYHbyXGYpTSCI4+Qvt8kr7rL6TKShC6VtbiYN L629G0giQUOHbCKamD+U6rn+t8nxSyzCQ6L4sMkwfr0R2/e24Zk/AtNgeqjqK8fAGHyo E0T3fxlctcnGZuGaJhrETfuc9WBxqpIxRQMiVtuZ7qDAkI9tcfJpULhhcYUCwEDY4HdN Jx5E2sFgKp1+Ln6QHdo3H/EaU2bj0TW/dH1YyhxVVzPGJAy56lU4BfFNd0c2GzQbZz/k B3u9S1Gc6F159clrtzBzyzgtBHxp+7f2XkXYKSM9OtWSS0f2+4hogJHjBrqfNwAEwoZO gjzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dmarc-filter :delivered-to; bh=+om8B9S+KnQA3NB9CI7F82apgKmrdGu5dJnDVBpiM50=; b=Nxg3cr3FVU4/QdKn76yN8Hl4W9btkrp51shc4e3ZrbbdvN8AtdwZsnPi9w7SAOY8Ny k5phq83WDd9v5AYWB2/VfqZiEAJmUiMvs+v5/zcRmqf/hVQzVbRh+d8p+UqDCsoY6Zim 4wKQFCwZJSjuc9A9eZmTzX7DvVzw/EJ87WkBg8+9ATws1X8VJFuKlRrqOH4xy43wryit UGSAreMU4EmDdIDz7TBcwVvnqFsdi/63zv1JEgX97/o41t2LTVQMtoqnJlVKkdLR9agr +Zu6uHOwzA0mtFqiN/7P9eOO2oaxY8oW7c0+s+lyjgE6sjQOxkP2zfldRu782q2j0xoi jK9g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b15-20020a056402084f00b0043ce8b2c72dsi16877448edz.36.2022.08.11.04.43.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Aug 2022 04:43:34 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.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; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 814BE3856DEC for ; Thu, 11 Aug 2022 11:43:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 34EB73856DE5 for ; Thu, 11 Aug 2022 11:42:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 34EB73856DE5 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 5.5.5 (unknown [10.2.5.5]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxWswe6_RiNpgNAA--.9459S2; Thu, 11 Aug 2022 19:42:26 +0800 (CST) From: Lulu Cheng To: gcc-patches@gcc.gnu.org Subject: [PATCH] LoongArch: Get __tls_get_addr address through got table when disable plt. Date: Thu, 11 Aug 2022 19:35:28 +0800 Message-Id: <20220811113527.286471-1-chenglulu@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf9AxWswe6_RiNpgNAA--.9459S2 X-Coremail-Antispam: 1UD129KBjvJXoWxArW8Zw48uw43Gw1rKF13XFb_yoW5WFW3pF y3ur1akrW8AFZ3Grn7Ja45ZFn5CrZ2gry29as3trySkwsFyr9xZFy8tF9xXFyjya4jqrWI qr15Cw1jgF4jqwUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkI14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE-syl42xK 82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGw C20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48J MIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMI IF0xvE42xK8VAvwI8IcIk0rVWrZr1j6s0DMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvE x4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7VUbrMaUUUUUU== X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, WEIRD_PORT 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: xuchenghua@loongson.cn, Lulu Cheng , i@xen0n.name Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1740864974003997804?= X-GMAIL-MSGID: =?utf-8?q?1740864974003997804?= thread.c: __attribute__ ((tls_model ("global-dynamic"))) __thread int a; void test (void) { a = 10; } Compile the tests with -fno-plt, error message is as follows: thread.c: In function 'test': thread.c:7:1: error: unrecognizable insn: 7 | } | ^ (call_insn/u 7 6 8 2 (parallel [ (set (reg:DI 4 $r4) (call (mem:SI (symbol_ref:DI ("__tls_get_addr") [flags 0x41] ) [0 S4 A8]) (const_int 0 [0]))) (clobber (reg:SI 1 $r1)) ]) "thread.c":5:5 -1 (expr_list:REG_EH_REGION (const_int -2147483648 [0xffffffff80000000]) (nil)) (expr_list (use (reg:DI 4 $r4)) (nil))) during RTL pass: vregs thread.c:7:1: internal compiler error: in extract_insn, at recog.cc:2791 ------------------------- Fix bug, ICE with tls gd var with -fno-plt. gcc/ChangeLog: * config/loongarch/loongarch.cc (loongarch_call_tls_get_addr): Get __tls_get_addr address through got table when disable plt. gcc/testsuite/ChangeLog: * gcc.target/loongarch/tls-gd-noplt.c: New test. --- gcc/config/loongarch/loongarch.cc | 14 ++++++++++++-- gcc/testsuite/gcc.target/loongarch/tls-gd-noplt.c | 12 ++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/loongarch/tls-gd-noplt.c diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index 5c9a33c14f7..8d8232e5805 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -2297,8 +2297,18 @@ loongarch_call_tls_get_addr (rtx sym, enum loongarch_symbol_type type, rtx v0) else gcc_unreachable (); - insn = emit_call_insn (gen_call_value_internal (v0, loongarch_tls_symbol, - const0_rtx)); + if (flag_plt) + insn = emit_call_insn (gen_call_value_internal (v0, loongarch_tls_symbol, + const0_rtx)); + else + { + rtx dest = gen_reg_rtx (Pmode); + rtx high = gen_reg_rtx (Pmode); + loongarch_emit_move (high, gen_rtx_HIGH (Pmode, loongarch_tls_symbol)); + emit_insn (gen_ld_from_got (Pmode, dest, high, loongarch_tls_symbol)); + insn = emit_call_insn (gen_call_value_internal (v0, dest, const0_rtx)); + } + RTL_CONST_CALL_P (insn) = 1; use_reg (&CALL_INSN_FUNCTION_USAGE (insn), a0); insn = get_insns (); diff --git a/gcc/testsuite/gcc.target/loongarch/tls-gd-noplt.c b/gcc/testsuite/gcc.target/loongarch/tls-gd-noplt.c new file mode 100644 index 00000000000..a71bb48676d --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/tls-gd-noplt.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-plt" } */ +/* { dg-final { scan-assembler "pcalau12i\t.*%got_pc_hi20\\(__tls_get_addr\\)" } } */ + +__attribute__ ((tls_model ("global-dynamic"))) __thread int a; + +void +test (void) +{ + a = 10; +} +