From owner-freebsd-current@freebsd.org Mon Jan 1 21:09:21 2018 Return-Path: Delivered-To: freebsd-current@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 11472E81392 for ; Mon, 1 Jan 2018 21:09:21 +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 8398E7E8B1 for ; Mon, 1 Jan 2018 21:09:20 +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 w01L97LF087888 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 1 Jan 2018 23:09:10 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua w01L97LF087888 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id w01L97tl087887; Mon, 1 Jan 2018 23:09:07 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 1 Jan 2018 23:09:07 +0200 From: Konstantin Belousov To: Pierre DAVID Cc: freebsd-current@freebsd.org Subject: Re: Problem with C11 _Atomic Message-ID: <20180101210907.GG1684@kib.kiev.ua> References: <20180101204740.GA15590@vagabond> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180101204740.GA15590@vagabond> User-Agent: Mutt/1.9.2 (2017-12-15) 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-current@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Jan 2018 21:09:21 -0000 On Mon, Jan 01, 2018 at 09:47:40PM +0100, Pierre DAVID wrote: > Hi, > > I'm on a recent current: > FreeBSD biceps.ma.maison 12.0-CURRENT FreeBSD 12.0-CURRENT #2 r327239: Wed Dec 27 18:25:46 CET 2017 pda@biceps.ma.maison:/usr/obj/usr/src/amd64.amd64/sys/BICEPS amd64 > > with clang 5.0.1: > FreeBSD clang version 5.0.1 (tags/RELEASE_501/final 320880) (based on LLVM 5.0.1) > Target: x86_64-unknown-freebsd12.0 > Thread model: posix > InstalledDir: /usr/bin > > I'm having a problem with the following source file: > > ------------------------------------------------------------------------------ > #include > > struct foo > { > int f1 ; > char f2 ; > int f3 ; > } ; > > _Atomic struct foo a ; > struct foo b ; > > int main (int argc, char *argv []) > { > b = (struct foo) {.f1 = 5, .f2 = 7, .f3 = 9 } ; > // atomic_store (&a, b) ; > a = b ; > } > ------------------------------------------------------------------------------ > > This code does not compile/link with: > % cc foo.c -lstdthreads > /tmp/foo-a0ef26.o: In function `main': > foo.c:(.text+0x63): undefined reference to `__sync_lock_test_and_set_16' > cc: error: linker command failed with exit code 1 (use -v to see invocation) > > The gcc internal seems to be linked as "cc -v" told me: > % cc -v foo.c -lstdthreads > ... > "/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags -o a.out /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib /tmp/foo-d7a21b.o -lstdthreads -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o > > The problem occurs with "atomic_store(&a, b)" as well as with "a = b". > > If I remove the f3 member, the struct foo is only 8 bytes and the code > compiles/links. > > Did I missed something? clang issues a calls to libatomic, which we do not provide. As a workaround, use the following command to compile. The resulting binary works on all practically usable machines. $ cc -march=core2 source.c You might want to turn off sse3/4.1 if you are concerned about older pentium4.