From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id 36F5A385022D for ; Wed, 29 Jun 2022 15:57:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 36F5A385022D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.92,231,1650960000"; d="scan'208";a="80719568" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 29 Jun 2022 07:57:19 -0800 IronPort-SDR: S0WeUobFHjacArDUe2iQkz/lRdyuXihEtFlEIJ6ibkTgvIEXfCfcC9yK0F5XVhBncrhkXIGQ4u s4MlNn5dsRH+J/J3HnS5957r2fdtRDJN10bUmlNmfBLaVCHOUbqT67R95MNFNPFV675uxW9SWL t2TpDq+aKAjgqjy6Cd2TD5SBK7m+o334E/u2KHDeWLiYcAviVGB9Jd0YBFK0H0XNF/AhClJPuK /iJvg/1A4Rc8UIqHXekl77y8OktJ20FY/qLN74BIgRdaV5Jtimv6/MBespXHjNlq7RNof2obfY Hzk= Date: Wed, 29 Jun 2022 15:57:15 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: Subject: [committed] nios2: Fix PIC function call slowness Message-ID: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-09.mgc.mentorg.com (139.181.222.9) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-3118.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, 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: 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: , X-List-Received-Date: Wed, 29 Jun 2022 15:57:22 -0000 On Nios II, PIC function calls use R_NIOS2_CALL* relocations, which may refer to a GOT entry that initially points to a PLT entry to resolve the function on first call and that is then changed by the dynamic linker to point directly to the function to be called so subsequent calls do not go through the dynamic linker. To quote the ABI, "A global offset table (GOT) entry referenced using R_NIOS2_GOT16, R_NIOS2_GOT_LO as well as R_NIOS2_GOT_HA must be resolved at load time. A GOT entry referenced only using R_NIOS2_CALL16, R_NIOS2_CALL_LO as well as R_NIOS2_CALL_HA can initially refer to a procedure linkage table (PLT) entry and then be resolved lazily.". However, GCC wrongly treats function addresses loaded from the GOT with such relocations as constant. If the address load is pulled out of a loop, then every call in the loop looks up the function by name. This shows up as very slow execution of many glibc testcases in glibc 2.35 and later (tests that call functions from shared libc many times in a loop), where tests are now built as PIE by default. Fix this problem by using gen_rtx_MEM instead of gen_const_mem when loading addresses for PIC function calls. Tested with no regressions for cross to nios2-linux-gnu, where many glibc tests pass that previously timed out. * config/nios2/nios2.cc (nios2_load_pic_address): Use gen_rtx_MEM not gen_const_mem for UNSPEC_PIC_CALL_SYM. --- Approved off-list by Sandra and committed. diff --git a/gcc/config/nios2/nios2.cc b/gcc/config/nios2/nios2.cc index f193cde5a34..1a33c88f19f 100644 --- a/gcc/config/nios2/nios2.cc +++ b/gcc/config/nios2/nios2.cc @@ -2552,7 +2552,10 @@ nios2_load_pic_address (rtx sym, int unspec, rtx tmp) return nios2_large_got_address (offset, tmp); } - return gen_const_mem (Pmode, nios2_got_address (sym, unspec)); + if (unspec == UNSPEC_PIC_CALL_SYM) + return gen_rtx_MEM (Pmode, nios2_got_address (sym, unspec)); + else + return gen_const_mem (Pmode, nios2_got_address (sym, unspec)); } /* Nonzero if the constant value X is a legitimate general operand -- Joseph S. Myers joseph@codesourcery.com