Date: Mon, 5 Jun 2017 13:57:01 +0200 From: Dimitry Andric <dim@FreeBSD.org> To: Konstantin Belousov <kostikbel@gmail.com> Cc: Eric van Gyzen <vangyzen@FreeBSD.org>, FreeBSD Hackers <freebsd-hackers@freebsd.org>, toolchain@freebsd.org Subject: Re: Function attribute for optimization level Message-ID: <CE19E497-E069-48BF-924C-30097F346C8F@FreeBSD.org> In-Reply-To: <20170605110911.GZ82323@kib.kiev.ua> References: <85c47390-dd27-aa74-24fe-25a9a5352527@FreeBSD.org> <20170605100324.GV82323@kib.kiev.ua> <20170605110911.GZ82323@kib.kiev.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
--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 <kostikbel@gmail.com> 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 <string.h> 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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CE19E497-E069-48BF-924C-30097F346C8F>