From owner-freebsd-toolchain@freebsd.org Mon Jun 5 11:57:16 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 439F1BFD380 for ; Mon, 5 Jun 2017 11:57:16 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id 2AAFD7B810 for ; Mon, 5 Jun 2017 11:57:16 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: by mailman.ysv.freebsd.org (Postfix) id 29F02BFD37E; Mon, 5 Jun 2017 11:57:16 +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 29521BFD37D; Mon, 5 Jun 2017 11:57:16 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from tensor.andric.com (tensor.andric.com [IPv6:2001:470:7a58:1::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "tensor.andric.com", Issuer "COMODO RSA Domain Validation Secure Server CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D34DA7B80F; Mon, 5 Jun 2017 11:57:15 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from [IPv6:2001:470:7a58::4075:b535:a8d3:d26] (unknown [IPv6:2001:470:7a58:0:4075:b535:a8d3:d26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id 8933919516; Mon, 5 Jun 2017 13:57:13 +0200 (CEST) From: Dimitry Andric Message-Id: Content-Type: multipart/signed; boundary="Apple-Mail=_C7C66C48-20D1-407B-AAF3-250460E3AE05"; protocol="application/pgp-signature"; micalg=pgp-sha1 Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: Function attribute for optimization level Date: Mon, 5 Jun 2017 13:57:01 +0200 In-Reply-To: <20170605110911.GZ82323@kib.kiev.ua> Cc: Eric van Gyzen , FreeBSD Hackers , toolchain@freebsd.org To: Konstantin Belousov References: <85c47390-dd27-aa74-24fe-25a9a5352527@FreeBSD.org> <20170605100324.GV82323@kib.kiev.ua> <20170605110911.GZ82323@kib.kiev.ua> X-Mailer: Apple Mail (2.3273) 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:57:16 -0000 --Apple-Mail=_C7C66C48-20D1-407B-AAF3-250460E3AE05 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii On 5 Jun 2017, at 13:09, Konstantin Belousov wrote: > > 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. Like that, or use -fno-builtin: $ cat test-memcpy.c #include void foo(void) { long dummy = -1; memcpy(&dummy, &dummy, sizeof(dummy)); } $ cc -O2 -fno-builtin -fomit-frame-pointer -S test-memcpy.c -o - .text .file "test-memcpy.c" .globl foo # -- Begin function foo .p2align 4, 0x90 .type foo,@function foo: # @foo .cfi_startproc # BB#0: # %entry pushq %rax .Lcfi0: .cfi_def_cfa_offset 16 movq $-1, (%rsp) movq %rsp, %rdi movl $8, %edx movq %rdi, %rsi callq memcpy popq %rax retq .Lfunc_end0: .size foo, .Lfunc_end0-foo .cfi_endproc # -- End function .ident "FreeBSD clang version 5.0.0 (trunk 304659) (based on LLVM 5.0.0svn)" .section ".note.GNU-stack","",@progbits -Dimitry --Apple-Mail=_C7C66C48-20D1-407B-AAF3-250460E3AE05 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.30 iEYEARECAAYFAlk1RxkACgkQsF6jCi4glqMDUwCguMJgKivulhOfFPbolf5dyp4S xXwAoPqPmdS4cIYScjgzYk5BcaONt0X3 =Z2N/ -----END PGP SIGNATURE----- --Apple-Mail=_C7C66C48-20D1-407B-AAF3-250460E3AE05--