From owner-freebsd-toolchain@freebsd.org Mon Jun 5 11:09:17 2017 Return-Path: Delivered-To: freebsd-toolchain@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BA042BFC418 for ; Mon, 5 Jun 2017 11:09:17 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mailman.ysv.freebsd.org (unknown [127.0.1.3]) by mx1.freebsd.org (Postfix) with ESMTP id A0C8479CFB for ; Mon, 5 Jun 2017 11:09:17 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: by mailman.ysv.freebsd.org (Postfix) id A00BCBFC416; Mon, 5 Jun 2017 11:09:17 +0000 (UTC) Delivered-To: toolchain@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9D75FBFC415; Mon, 5 Jun 2017 11:09:17 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4251B79CF9; Mon, 5 Jun 2017 11:09:17 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id v55B9BYn084494 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 5 Jun 2017 14:09:11 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua v55B9BYn084494 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id v55B9BCN084493; Mon, 5 Jun 2017 14:09:11 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 5 Jun 2017 14:09:11 +0300 From: Konstantin Belousov To: Eric van Gyzen Cc: FreeBSD Hackers , toolchain@freebsd.org Subject: Re: Function attribute for optimization level Message-ID: <20170605110911.GZ82323@kib.kiev.ua> References: <85c47390-dd27-aa74-24fe-25a9a5352527@FreeBSD.org> <20170605100324.GV82323@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170605100324.GV82323@kib.kiev.ua> User-Agent: Mutt/1.8.2 (2017-04-18) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Jun 2017 11:09:17 -0000 On Mon, Jun 05, 2017 at 01:03:24PM +0300, Konstantin Belousov wrote: > I think that toolchain@ is more suitable list for the discussion. > > On Sun, Jun 04, 2017 at 05:44:31PM -0500, Eric van Gyzen wrote: > > _thr_rtld_init() calls memcpy() for the sole purpose of resolving its > > PLT entry. With clang 4.0 and the current code, compiler optimization > > defeats this attempt by completely eliding the call. Other compilers > > or code might emit inline instructions instead of the library call, > > also defeating the purpose. > After looking more closely at the whole situation, I have a question > that we probably must answer first. Is clang -ffreestanding mode > broken ? memcpy(3) is not included into the set of the environment > features required for a C11 freestanding implementation, and clang > pretending that it knows the semantic of the call sounds broken. Ok, I realized that I only added -ffreestanding to the rtld Makefile. So clang is optimizing correctly there. Should we compile both libc and libthr in the freestanding environment as well ? I am sure that there are a lot of similar assumptions that libc and libthr code calls into itself and not into the arbitrary re-implementation of the same code as generated by modern compilers. Then hopefully the __no_optimization hack is not needed. > > > > > I propose adding "__no_optimization" to sys/cdefs.h. The patch is > > below. Empirical testing shows that clang 3.7 and later support > > "optnone", and gcc 4.6 and later support "optimize()". Clang 3.4 does > > not support either, so it takes the define-to-empty case. I did not > > test clang 3.5 or 3.6. > Where this attribute should be applied ? To the _thr_rtld_init() function ? > > > > > Side note: GCC 4.6 with optimize(0) on amd64 emits two movq > > instructions for memset(x,0,16), but GCC 5 emits a call to memset(). > > > > I have done no research to see if other popular codebases have such a > > definition. If you know of one, please tell me; I would gladly adopt > > an already common name for this proposal, for the sake of portability. > > > > Thanks in advance for your feedback. > > > > Eric > > > > > > diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h index > > 9cdc03c861cb..e370f6d6459e 100644 --- a/sys/sys/cdefs.h +++ > > b/sys/sys/cdefs.h @@ -396,6 +396,14 @@ #define __unreachable() > > ((void)0) #endif > > > > +#if __has_attribute(optnone) +#define __no_optimization > > __attribute__((optnone)) +#elif __has_attribute(optimize) +#define > > __no_optimization __attribute__((optimize(0))) +#else +#define > > __no_optimization +#endif + /* XXX: should use `#if __STDC_VERSION__ < > > 199901'. */ #if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) > > #define __func__ NULL _______________________________________________ > > freebsd-hackers@freebsd.org mailing list > > https://lists.freebsd.org/mailman/listinfo/freebsd-hackers > > To unsubscribe, send any mail to > > "freebsd-hackers-unsubscribe@freebsd.org" > _______________________________________________ > freebsd-toolchain@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-toolchain > To unsubscribe, send any mail to "freebsd-toolchain-unsubscribe@freebsd.org"