public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Joseph Myers <jsm28@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-1346] nios2: Fix PIC function call slowness Date: Wed, 29 Jun 2022 15:56:46 +0000 (GMT) [thread overview] Message-ID: <20220629155646.C77C5385AE6C@sourceware.org> (raw) https://gcc.gnu.org/g:b01c075e7e6d84da846c2ff9087433a30ebeb0d2 commit r13-1346-gb01c075e7e6d84da846c2ff9087433a30ebeb0d2 Author: Joseph Myers <joseph@codesourcery.com> Date: Wed Jun 29 15:55:41 2022 +0000 nios2: Fix PIC function call slowness 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. Diff: --- gcc/config/nios2/nios2.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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
reply other threads:[~2022-06-29 15:56 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220629155646.C77C5385AE6C@sourceware.org \ --to=jsm28@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).