From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10709 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: ub fix in magenta Date: Sat, 5 Nov 2016 17:14:52 -0400 Message-ID: <20161105211452.GB1555@brightrain.aerifal.cx> References: <20161105202558.GK5749@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1478380537 1387 195.159.176.226 (5 Nov 2016 21:15:37 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 5 Nov 2016 21:15:37 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: George Kulakowski , musl@lists.openwall.com Original-X-From: musl-return-10722-gllmg-musl=m.gmane.org@lists.openwall.com Sat Nov 05 22:15:29 2016 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 1c38Ir-0004tl-N0 for gllmg-musl@m.gmane.org; Sat, 05 Nov 2016 22:15:05 +0100 Original-Received: (qmail 22178 invoked by uid 550); 5 Nov 2016 21:15:07 -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 22154 invoked from network); 5 Nov 2016 21:15:06 -0000 Content-Disposition: inline In-Reply-To: <20161105202558.GK5749@port70.net> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:10709 Archived-At: On Sat, Nov 05, 2016 at 09:25:59PM +0100, Szabolcs Nagy wrote: > why do you think union based type punning is ub? > are you compiling musl as c++ code? > > commit 224516687417d5e9dcbb0ba300c3e34bb47bb12b > Author: George Kulakowski > Date: 2016-10-19 17:11:59 -0700 > > [musl][malloc] Remove undefined behavior in malloc > > This bit of code computes an approximation to log2(x) by extracting the > exponent from a float. Doing it via a union this way is bad, so memcpy > instead. > > https://fuchsia.googlesource.com/magenta/+/224516687417d5e9dcbb0ba300c3e34bb47bb12b It's definitely not UB (this usage is explicitly permitted by C), and the memcpy approach is much slower (requires store/call/load) because -ffreestanding implies -fno-builtin. I'd like to try overriding that with -fbuiltin-memcpy or a musl-internal header that defines memcpy to __builtin_memcpy, etc., for all files but src/string/*, but there are various subtle issues to be concerned about. > this makes implementation internals publicly visible, introduce > paddings and whenever you need to add new fields you will have > to break the abi again. > > note that the initializers are not valid c and thus non-conforming. > > commit c751172f029e96a3208b37da91fd9e020a792834 > Author: George Kulakowski > Date: 2016-10-13 21:31:24 -0700 > > [musl] Use a single proper struct definition for pthread types > > There is one slight change in layout here made for simplicity's > sake. Upstream's pthread_barrier_t overlays the _b_count and _b_inst > fields in the 32 bit case. Since this is so rarely used (in Fuchsia > outside of libc I pretty much only see tsan, gdb etc. test cases), > just do the simple thing. > > https://fuchsia.googlesource.com/magenta/+/c751172f029e96a3208b37da91fd9e020a792834 Yes, this change looks highly problematic to ABI stability. > (i don't plan to review all changes i just wanted to see if there > was anything useful in the magenta repo for musl, havent found much > yet, but some of the changes could have been discussed upstream) Thanks. Rich