From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12035 Path: news.gmane.org!.POSTED!not-for-mail From: Andre McCurdy Newsgroups: gmane.linux.lib.musl.general Subject: Re: How to handle attempts to combine ARM Thumb with frame pointers? Date: Thu, 26 Oct 2017 10:48:41 -0700 Message-ID: References: <20171008032153.GH1627@brightrain.aerifal.cx> <20171025211623.GU15263@port70.net> <20171026170054.GA1627@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1509040160 20987 195.159.176.226 (26 Oct 2017 17:49:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 26 Oct 2017 17:49:20 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-12048-gllmg-musl=m.gmane.org@lists.openwall.com Thu Oct 26 19:49:15 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1e7mGv-0002FA-Lo for gllmg-musl@m.gmane.org; Thu, 26 Oct 2017 19:48:49 +0200 Original-Received: (qmail 20148 invoked by uid 550); 26 Oct 2017 17:48:54 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 20124 invoked from network); 26 Oct 2017 17:48:54 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=x4a2VrPZiUrZQtji0g1PxHix8gBiqmYlcBiepoBXKPA=; b=FlQc1IZGDed8gPPEj3mj827JdN0GnZfdq5GHthHFODT+5XgGuVzzFwdKiVzYUvXT8b RoHsMSZplPAD4b68NdKZEbpOT36LjXN5R4qttGUdDmpUEKDZIbRd7ss7ncBTF7qDxQHQ pBhBTpq+P8eJ8cYqkvYfwBLZm67q7Wb6u0sEauLUqtlYfOYLGX0hQ0PfZQHAPZCaVc6y ORlu2+Csx437VgdaCky8b2JJQszESlZTUTmhfIHIS2WXDVlvx1GAAzYOGoGyWcrCoxii wTqdjNDzINf7PSMyHICGKq/kL1t9+fEvAok2ueGrvbqH3Ao4g6tIoWAcrmE44aUx6Z/f tFWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=x4a2VrPZiUrZQtji0g1PxHix8gBiqmYlcBiepoBXKPA=; b=f/P7/f+lPNPgh7mXJV0rX9M6RLO/KVqAWyKT7KzhLg/J7oM+haHuwxkSTc/Q5K1P1x cYhF0bnowAJ9GtafUtAxvsGlA/VG2krh4tNuwdTyMoX8j6loRpkql1bOPRLQ5LgS3f4r W8R+tHww9GAC1T8JEesQw9itdY70pFOIoTyOGSKfaSfHe7dB2Qb4/O4IoH098b1efAjZ Hws+CUAK3OoYqsGDH8xJt6BOg73rxkuqowA4eI6e4v07KY/RO2h8YL/o34fhmF2qwQx4 E+UVgEbagGekWkxyWXfEwaRQibKQE1l2Es9Z2Kty6Vr+f527fHFa39nWpZNLzF1YJ97q Rzmw== X-Gm-Message-State: AMCzsaW9u1t3AJoe/hVWALHy8/k49FbljTxbAnY+lFy30asRySElO7Hj zlIe4sIv0M7JxbdZlBu7wp5smcabUgPmrxC4eajUFg== X-Google-Smtp-Source: ABhQp+QUj/iXIqHfI/Fn1itEtjgQJzTf2CePfVmtIcaIUTmLSshDEGh1pa1+5EZ3bTQY4vU7cSqZ0dtTQmPuWP+9esY= X-Received: by 10.223.186.140 with SMTP id p12mr5815551wrg.235.1509040122087; Thu, 26 Oct 2017 10:48:42 -0700 (PDT) In-Reply-To: <20171026170054.GA1627@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:12035 Archived-At: On Thu, Oct 26, 2017 at 10:00 AM, Rich Felker wrote: > On Thu, Oct 26, 2017 at 02:48:11PM -0200, Adhemerval Zanella wrote: >> On 25/10/2017 19:16, Szabolcs Nagy wrote: >> > * Andre McCurdy [2017-10-09 09:48:29 -0700]: >> >> On Sat, Oct 7, 2017 at 8:21 PM, Rich Felker wrote: >> >>> On Fri, Oct 06, 2017 at 05:53:38PM -0700, Andre McCurdy wrote: >> >>> If you do want to test for broken configurations, rather than >> >>> hard-coding an assumption that some configuration is broken, you >> >>> should test for it. This would look something like, if ARCH is arm, >> >>> try compiling a trivial function with inline asm using r7 and see if >> >>> it fails. >> >> >> >> Yes, I came to the same conclusion after seeing the clang bug, which >> >> seems to suggest that clang uses a frame pointer even with >> >> optimisation enabled. >> >> >> >>> If so, exit with an error or perhaps try adding >> >>> -fomit-frame-pointer and retrying. >> >> >> >> If we over-ride the user supplied CFLAGS then there's probably no need >> >> to test the behaviour of the compiler - we can just force >> >> -fomit-frame-pointer unconditionally when compiling for Thumb/Thumb2. >> >> >> >> There's a slight complication though that if -fno-omit-frame-pointer >> >> is present in the user supplied CFLAGS then adding >> >> -fomit-frame-pointer to CFLAGS_AUTO won't over-ride it (since CFLAGS >> >> appears on the final compiler command line after CFLAGS_AUTO). >> >> >> >> Would it be OK for the configure script to append to CFLAGS? Or should >> >> the configure script perhaps setup a new variable (CFLAGS_FORCE?) >> >> which the Makefile would then add to CFLAGS_ALL after CFLAGS? >> > >> > glibc works this around in thumb mode by extern syscall asm >> > (of course it cannot guarantee that r7 is a frame pointer at >> > all times, an interrupt can observe r7 with syscall num in it, >> > i'm not sure if that's acceptable for users who compile with >> > frame-pointers, in musl there is some asm code which wont >> > have fp setup anyway). >> > >> > http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/arm/sysdep.h;h=6a64351cdd87c2041d639a17efc9f681262d5e3f;hb=HEAD#l335 >> >> Why do you mean by glibc strategy might not be acceptable? What >> kind of issue are you referring on interrupt case? > > If you're compiling with frame pointers because you want them to be > present (and always valid) for debugging purposes or similar, there's > no way to achieve that while making syscalls -- and the most likely > place for a process to get stopped debugging is usually at a syscall. > Maybe this doesn't matter. It's not something we can change, just an > observation about a problem with the ABI, I think. > > I think what we could do to ensure that compiling with frame pointers > otherwise works is add a configure test for use of r7 in inline asm, > and if it fails Using r7 in inline asm together with frame pointers fails at build time with gcc, but not with clang. But perhaps an alternative way to detect whether the current combination of compiler + cflags is going to try to use frame pointers is to compile a trivial function to assembler and parse the output. I haven't tested clang, but gcc adds a helpful "frame_needed" comment which is easy to grep for. $ arm-linux-gnueabi-gcc -S tst.c -o - -O0 | grep frame_needed @ frame_needed = 1, uses_anonymous_args = 0 $ arm-linux-gnueabi-gcc -S tst.c -o - -O0 -fomit-frame-pointer | grep frame_needed @ frame_needed = 0, uses_anonymous_args = 0 $ arm-linux-gnueabi-gcc -S tst.c -o - -O2 | grep frame_needed @ frame_needed = 0, uses_anonymous_args = 0 $ arm-linux-gnueabi-gcc -S tst.c -o - -O2 -fno-omit-frame-pointer | grep frame_needed @ frame_needed = 1, uses_anonymous_args = 0 >, -D something that would cause arch/arm/syscall_arch.h > not to define any syscall inlines but instead #define > SYSCALL_NO_INLINE which results in src/internal/syscall.h just using > the external __syscall function (which will of course clobber r7 for > the duration of the syscall). > > Rich