From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 14591 invoked from network); 15 Mar 2021 23:50:15 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 15 Mar 2021 23:50:15 -0000 Received: (qmail 3248 invoked by uid 550); 15 Mar 2021 23:50:10 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 3230 invoked from network); 15 Mar 2021 23:50:10 -0000 Date: Tue, 16 Mar 2021 02:49:59 +0300 (MSK) From: Alexander Monakov To: musl@lists.openwall.com cc: Markus Wichmann In-Reply-To: <20210309180434.GV32655@brightrain.aerifal.cx> Message-ID: References: <20210309035652.32453-1-ericonr@disroot.org> <20210309134242.GS32655@brightrain.aerifal.cx> <20210309150320.GU32655@brightrain.aerifal.cx> <20210309165404.GB2766@voyager> <20210309180434.GV32655@brightrain.aerifal.cx> User-Agent: Alpine 2.20.13 (LNX 116 2015-12-14) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Subject: Re: [musl] [PATCH v2] add qsort_r. On Tue, 9 Mar 2021, Rich Felker wrote: > I tested sh4, sh2/fdpic, rv64, s390x, or1k, m68k, and mips (32-bit) > and they all do the tail call properly. But mips64 (n64 and n32) both > fail to. According to the GCC source, it's some thing to allow lazy > binding. MIPS64 does not use a real PLT, but actually has GOT entries > that might go through a lazy resolver and that expect %gp (call-saved) > to be valid on entry. I think you botched something in your MIPS64 testing, probably making a direct call instead of an indirect call. An indirect call should not go to a lazy resolver (because then if you take the address once and reuse it many times, you risk entering the resolver multiple times). Here's a Compiler Explorer link demonstrating that indirect call compiles to a simple jump on MIPS64: https://godbolt.org/z/vroTs9 > musl does not, and will never, do lazy binding, so this is purely > counterproductive for musl and we should probably teach GCC not to do > it. The current logic is: > > /* Sibling calls should not prevent lazy binding. Lazy-binding stubs > require $gp to be valid on entry, so sibcalls can only use stubs > if $gp is call-clobbered. */ > if (decl decl will be NULL for an indirect call > && TARGET_CALL_SAVED_GP > && !TARGET_ABICALLS_PIC0 > && !targetm.binds_local_p (decl)) > return false; > > TARGET_CALL_SAVED_GP is rightly true (it's the ABI). > > TARGET_ABICALLS_PIC0 is rightly false (I'm pretty sure that's a bogus > alt ABI, and defined as TARGET_ABSOLUTE_ABICALLS && TARGET_PLT). > > It probably needs an addition condition && TARGET_LAZY_BINDING that we > can define as false. Alternatively the issue could just be fixed not > to go through lazy resolver anywhere. > > I opened a bug for it here: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99491 > > > Rich >